正则
只允许填写数字和.,且不能以.开头,保留小数点后两位
// 只允许填写数字和.,且不能以.开头,保留小数点后两位
export function checkNum(num) {
var num = "" + num;
num = num
.replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
.replace(/\.{2,}/g, ".") // 只保留第一个. 清除多余的
.replace(/^\./g, "") //保证第一个为数字而不是.
.replace(".", "$#$")
.replace(/\./g, "")
.replace("$#$", ".")
.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); // 只能输入两个小数
if (num.indexOf(".") < 0 && num != "") {
// 以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
num = parseFloat(num);
}
return num;
}
不能为0
const validatebuildingAreaFzz = (rule, value, callback) => {
if (parseFloat(value) <= parseFloat(0)) {
callback(new Error("面积不能为0"));
} else {
callback();
}
};
*字母数字中文: /^[A-Za-z0-9\u4e00-\u9fa5]+$/
电话正则: ^(((13[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[3-8]{1})|(18[0-9]{1})|(19[0-9]{1})|(14[5-7]{1}))+\d{8})$
邮箱正则: ^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$
表情正则: /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;
mac地址正则: /^[A-F0-9]{2}([-:]?[A-F0-9]{2})([-:.]?[A-F0-9]{2})([-:]?[A-F0-9]{2})([-:.]?[A-F0-9]{2})([-:]?[A-F0-9]{2})$
//密码为八位及以上并且字母数字特殊字符三项都包括
//密码为八位及以上并且字母数字特殊字符三项都包括
var strongRegex = /(?=.*[a-z])(?=.*[A-Z])(?=.*[_!@#$%^&*`~()\-+=])^[a-zA-Z_!@#$%^&*`~()\-+=]{8,16}$|(?=.*[0-9])(?=.*[A-Z])(?=.*[_!@#$%^&*`~()\-+=])^[0-9A-Z_!@#$%^&*`~()\-+=]{8,16}$|(?=.*[a-z])(?=.*[0-9])(?=.*[_!@#$%^&*`~()\-+=])^[a-z0-9_!@#$%^&*`~()\-+=]{8,16}$|(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])^[a-z0-9A-Z]{8,16}$|(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?=.*[_!@#$%^&*`~()\-+=])^[a-z0-9A-Z_!@#$%^&*`~()\-+=]{8,16}$/g;
//密码为八位及以上并且字母、数字、特殊字符三项中有两项,强度是中等
var mediumRegex = /^(?![0-9]+$)(?![a-z]+$)[0-9a-z]{8,18}$|^(?![0-9]+$)(?![A-Z]+$)[0-9A-Z]{8,18}$|^(?![0-9]+$)(?![_!@#$%^&*`~()\-+=]+$)[0-9_!@#$%^&*`~()\-+=]{8,18}$|^(?![a-z]+$)(?![A-Z]+$)[A-Za-z]{8,18}$|^(?![_!@#$%^&*`~()\-+=]+$)(?![a-z]+$)[_!@#$%^&*`~()\-+=a-z]{8,18}$|^(?![_!@#$%^&*`~()\-+=]+$)(?![A-Z]+$)[_!@#$%^&*`~()\-+=A-Z]{8,18}$/g;
var enoughRegex = /^[0-9]{8,18}$|^[A-Z]{8,18}$|^[a-z]{8,18}$|^[_!@#$%^&*`~()\-+=]{8,18}$/g;
var wordRegex = /[\u4e00-\u9fa5]{1,}$/g;
if (value.length < 8 || value.length > 18) {
this.$refs.tip2.style.display = "none";
callback(new Error("密码位数为8位 ~ 18位"));
} else if (wordRegex.test(value)) {
this.$refs.tip2.style.display = "none";
callback(new Error("请不要输入文字"));
} else if (strongRegex.test(value)) {
this.$refs.level2.innerText = "强";
this.$refs.tip2.style.display = "block";
callback();
} else if (mediumRegex.test(value)) {
this.$refs.level2.innerText = "中";
this.$refs.tip2.style.display = "block";
callback();
} else if (enoughRegex.test(value)) {
this.$refs.level2.innerText = "弱";
this.$refs.tip2.style.display = "block";
callback();
}