Files
czzj-app/src/utils/validate.ts
2026-10-13 16:23:43 +08:00

23 lines
723 B
TypeScript
Raw 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.
export function isValidPhone(phone: string): boolean {
return /^1\d{10}$/.test(phone.trim())
}
export function isValidSmsCode(code: string): boolean {
return /^\d{4,6}$/.test(code.trim())
}
export function isValidPassword(password: string): boolean {
return password.length >= 6 && password.length <= 32
}
/** 设置/修改登录密码:8-20 位,且字母、数字、符号至少包含 2 种 */
export function isValidStrongPassword(password: string): boolean {
const value = password.trim()
if (value.length < 8 || value.length > 20) return false
let types = 0
if (/[a-zA-Z]/.test(value)) types += 1
if (/\d/.test(value)) types += 1
if (/[^a-zA-Z0-9]/.test(value)) types += 1
return types >= 2
}