topfans/frontend/utils/validator.js
2026-04-07 23:08:49 +08:00

42 lines
735 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 验证手机号格式1开头的11位数字
export function validatePhone(phone) {
const phoneReg = /^1[3-9]\d{9}$/
if (!phone) {
return {
valid: false,
message: '请输入手机号'
}
}
if (!phoneReg.test(phone)) {
return {
valid: false,
message: '请输入正确的手机号格式'
}
}
return {
valid: true,
message: ''
}
}
// 验证密码长度至少6位
export function validatePassword(password) {
if (!password) {
return {
valid: false,
message: '请输入密码'
}
}
if (password.length < 6) {
return {
valid: false,
message: '密码至少为6位'
}
}
return {
valid: true,
message: ''
}
}