// 判断是否数值
const isNumber = (val) => {
var regPos = /^\d+(\.\d+)?$/; //非负浮点数
var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
if (regPos.test(val) || regNeg.test(val)) {
return true;
} else {
return false;
}
}
// 判断是否座机号码
const isPhone = (e) => {
if (null == e || "" == e) return !1;
return /[0-9]{1}[0-9]{2,3}-[1-9]{1}[0-9]{5,8}/.test(e);
}
// 判断是否移动手机
const isMobile = (e) => {
if (null == e || "" == e) return false;
return /^1[3456789][0-9]{9}$/.test(e);
}
// 判断是否电话号码
const isPhoneNum = (e) => {
return isPhone(e) || isMobile(e);
}
// 判断邮箱
const checkEmail = (e) => {
return /^\w+((-\w+)|(\.\w+))*@\w+(\.\w{2,3}){1,3}$/.test(e);
}
// 判断链接
const validateURL = (e) => {
return /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/.test(e);
}
js常用正则判断函数,包括手机号,邮箱等
于 2022-05-24 09:01:51 首次发布