This commit is contained in:
wangzzpeng
2026-09-24 10:10:43 +08:00
commit 7bc84bbe5e
194 changed files with 22571 additions and 0 deletions

36
src/utils/validate.ts Normal file
View File

@@ -0,0 +1,36 @@
// 校验规则(无 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
}