2024-04-07 18:06:06 +08:00

48 lines
1.2 KiB
TypeScript

/**
* @param {string} path
* @returns {Boolean}
*/
export function isExternal(path: string) {
return /^(https?:|mailto:|tel:)/.test(path);
}
//电话
export function isPhone(data: string) {
return /^1[3|4|5|7|8][0-9]{9}$/.test(data);
}
//身份号
export function isIdCard(data: string) {
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(data);
}
//邮箱
export function isEmail(data: string) {
return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(data);
}
// input框校验
// 电话
export function checkPhone(rules: any, value: any, callback: any) {
/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(
value
)
? callback()
: callback(new Error("请输入正确的手机号"));
}
//邮箱
export function checkEmail(rules: any, value: any, callback: any) {
/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(value)
? callback()
: callback(new Error("请输入正确的邮箱"));
}
//idcard
export function checkIdCard(rules: any, value: any, callback: any) {
/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value)
? callback()
: callback(new Error("请输入正确的身份证号码"));
}