validate.ts 494 Bytes
Newer Older
zhangsan's avatar
zhangsan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 手机号验证
export const validatePhone = (phone: string): boolean => {
  const phoneRegex = /^1[3456789]\d{9}$/
  return phoneRegex.test(phone)
}

// 密码验证
export const validatePassword = (password: string): boolean => {
  const passwordRegex = /^[a-zA-Z0-9_-]{5,20}$/
  return passwordRegex.test(password)
}

// 用户名验证
export const validateUsername = (username: string): boolean => {
  const usernameRegex = /^[a-zA-Z0-9]{3,11}$/
  return usernameRegex.test(username)
}