Files
aiot-uniapp/src/utils/validator.ts

42 lines
903 B
TypeScript
Raw Normal View History

/** 手机号正则表达式(中国) */
const MOBILE_REGEX = /^1[3-9]\d{9}$/
/** 邮箱正则表达式 */
const EMAIL_REGEX = /^[\w-]+(?:\.[\w-]+)*@[\w-]+(?:\.[\w-]+)+$/
/**
* nullundefined
*
* @param value
* @returns
*/
export function isBlank(value?: null | string): boolean {
return !value || value.trim().length === 0
}
/**
*
*
* @param value
* @returns
*/
export function isMobile(value?: null | string): boolean {
if (!value) {
return false
}
return MOBILE_REGEX.test(value)
}
/**
*
*
* @param value
* @returns
*/
export function isEmail(value?: null | string): boolean {
if (!value) {
return false
}
return EMAIL_REGEX.test(value)
}