You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
677 B
35 lines
677 B
|
3 weeks ago
|
/**
|
||
|
|
* 判断是否为有效 URL
|
||
|
|
*/
|
||
|
|
export function isExternal(path: string): boolean {
|
||
|
|
return /^(https?:|mailto:|tel:)/.test(path)
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 判断是否为有效用户名
|
||
|
|
*/
|
||
|
|
export function validUsername(str: string): boolean {
|
||
|
|
return str.trim().length >= 2
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 判断是否为有效密码
|
||
|
|
*/
|
||
|
|
export function validPassword(str: string): boolean {
|
||
|
|
return str.length >= 5
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 判断是否为合法手机号
|
||
|
|
*/
|
||
|
|
export function isPhone(str: string): boolean {
|
||
|
|
return /^1[3-9]\d{9}$/.test(str)
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 判断是否为合法邮箱
|
||
|
|
*/
|
||
|
|
export function isEmail(str: string): boolean {
|
||
|
|
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(str)
|
||
|
|
}
|