当前位置:网站首页>Common regular expression collation

Common regular expression collation

2022-07-06 11:35:00 iatkotworld

Regular expression collation is often used for form verification ( Continuous updating )


Sort out common regular expressions

const verifyObj = {
    
	money: function (value, item) {
    
		if (value && !(/^([1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(value))) {
    
			return ' Please enter the correct amount , Two decimal places at most '
		}
	},
	emails: function (value, item) {
    
		if (value && !(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value))) {
    
			return ' Please enter the correct email '
		}
	},
	number: function (value, item) {
    
		if (value && !(/^\d*$/.test(value))) {
    
			return ' Please enter a pure number '
		}
	},
	bankCard: function (value, item) {
    
		if (value && !(/^([1-9]{1})(\d{14}|\d{18})$/.test(value))) {
    
			return ' Please enter the correct bank card number '
		}
	},
	mobilephone: function (value, item) {
    
		if (value && !(/^1[3,4,5,6,7,8,9]\d{9}$/.test(value))) {
    
			return ' Enter the correct phone number '
		}
	},
	phone: function (value, item) {
    
		if (value && !(/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/.test(value))) {
    
			return ' Enter the correct contact information '
		}
	},
	idCard: function() {
    
		if (value && !(v.test(value))) {
    
			return ' Please enter the correct ID number '
		}
	},
	num1t100: function (value, item) {
    
		if (value && !(/^\d{1,2}\.?\d{0,4}$|100/.test(value))) {
    
			return ' Please enter 0-100 The number of , Keep up to four decimal places '
		}
	}
};
原网站

版权声明
本文为[iatkotworld]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060913000186.html