uniapp手机号码正则验证

<input type="number" placeholder="请输入手机号" maxlength=11 v-model="userPhone"/>
<input type="text" :password="showPassword" placeholder="请输入密码至少6位" v-model="password" maxlength=12 />

return里 返回手机号和密码默认为空

            login(){
				let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/
				if (!this.userPhone) {      //判断如果手机号为空,提示用户输入手机号
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					})
					return
				} else if (!reg.test(this.userPhone)) {        //判断手机号格式时候正确
					uni.showToast({
						title: '请输入正确的手机号',
						icon: 'none'
					})
					return
				}
				let passwd = 123456
				if(this.password==''){   //这里也可以写!this.password
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
					return
				}
				if(this.password!=passwd){
					uni.showToast({
						title: '密码错误,请再次输入',
						icon: 'none'
					})
				} else {
					uni.switchTab({
					url: `/pages/vip/vip`,   //密码正确 进入到会员中心
					});
				}
			},

猜你喜欢

转载自blog.csdn.net/weixin_57607714/article/details/124122814