当前位置:   article > 正文

uniApp正则表达式校验手机、邮箱_uniapp regexp

uniapp regexp

主要介绍下uniApp中正则的使用,以校验手机、邮箱为例。

//util.js文件主要写的是会经常使用到的工具类
//校验邮箱格式
function checkEmail(email){
	return RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/).test(email);
}
//校验手机格式
function checkMobile(mobile){
	return RegExp(/^1[34578]\d{9}$/).test(mobile);
}

module.exports = {
	checkEmail : checkEmail,
	checkMobile : checkMobile
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
//register.js
//点击获取验证码,校验手机号和邮箱格式
obtain(){
	if(this.table == 'tel'){
		if(!until.checkMobile(this.mobile)){
			uni.showToast({title: '手机号格式错误',icon: 'none'});
			return;
		}
		this.getMobileVerify()
	}else if(this.table == 'email'){
		if(!until.checkEmail(this.email)){
			uni.showToast({title: '邮箱格式错误',icon: 'none'});
			return;
		}
		this.getEmailVerify()
	}
},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/287096
推荐阅读