常用的正则判断

手机号的验证

const isPhone = function(p) {
	let reg = /^1[34578]\d{9}$/;
	let regz = /0\d{2,3}-\d{7,8}/ //座机验证
	if (!reg.test(p) && !regz.test(p)) {
		return true
	}
	return false
}

密码的验证

不少于6位且字母和数字都必须有

const isPwd = function(p) {
	let pwd = p.replace(/\s/g, '');
	if (pwd.length < 6) {
		return true
	}
	return false
}

银行卡验证

const isBankCard = function(num){
	var reg = /^(\d{16}|\d{19})$/;	
	if(!reg.test(data.receivingAccount)){
		_self.$toast('银行卡号有误')
		return				
	}
}

判断输入的是否为空

const isNull = function(str) {
	return typeof str == 'string' ? str !== 0 && !str :
		str instanceof Array ? str.length === 0 :
		str instanceof Object ? JSON.stringify(str) == '{}' : !str;
}

重复验证

判断 两个 框输入的是否相同
const equally = function(a, b) {
return a != b;
}

支付密码判断

必须为6 位纯数字

const paYPwd = function(p) {
	let Pwd = /^\d{6}$/;
	if(!Pwd.test(p)){
		return true
	}
	return false
}
发布了47 篇原创文章 · 获赞 22 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wuwenjie_1997/article/details/95955581
今日推荐