// 校验规则(无 Vue 依赖) /** 手机号 */ export function isPhone(value: string): boolean { return /^1[3-9]\d{9}$/.test(value) } /** 邮箱 */ export function isEmail(value: string): boolean { return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value) } /** URL */ export function isUrl(value: string): boolean { return /^https?:\/\/[^\s]+$/.test(value) } export type PasswordLevel = 'weak' | 'medium' | 'strong' /** * 密码强度等级(6-20 位) * weak:仅字母或仅数字;medium:字母+数字;strong:字母+数字+特殊符号 */ export function getPasswordLevel(password: string): PasswordLevel { const hasLetter = /[a-zA-Z]/.test(password) const hasDigit = /\d/.test(password) const hasSymbol = /[^\w\s]/.test(password) if (hasLetter && hasDigit && hasSymbol) return 'strong' if (hasLetter && hasDigit) return 'medium' return 'weak' } /** 登录密码合法性(6-20 位) */ export function isValidPassword(password: string): boolean { return password.length >= 6 && password.length <= 20 }