前端vue+uniapp关于输入内容正则表达式判断

关于对输入内容正则表达式判断Vue+uniapp

			//方法名
			testt(){
      			 //要做验证的正则表达式
				const reg = /^[\u4e00-\u9fa5]+$/;
				//判断是否输入值是否通过了正则表达式
     			 if(reg.test("具体要判断的参数")){
					console.log("通过正则验证");
				}else{
					console.log("未通过正则验证")
				}
			},

例为uniapp代码,vue方法同理即可


<template>
	<view>
		<view class="page">
			<uni-easyinput type="number" maxlength="11" style="width: 60%; left: 20%; height: 20rpx;" v-model="content"
				placeholder="请输入要绑定手机号">
			</uni-easyinput>
		</view>
		<u-button class="button" style="position:absolute; bottom:0px; width:100%" type="primary" text="保存信息"
			@click="verifyNum">保存信息
		</u-button>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				content: "",
			}
		},
		methods: {
			verifyNum() {
				//正则表达式
				const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
				if (this.content == "") {
					uni.showToast({
						icon: "none",
						title: "请输入手机号!",
					});
				} else {
					//判断是否输入的是手机号
					if (reg.test(this.content)) {
						console.log("通过正则验证");
						uni.navigateTo({
						  url: "../attestation/embedded",
						});
					} else {
						uni.showToast({
							icon: "none",
							title: "您输入的手机号格式有误,请重新输入!",
						});
						this.content = "";
					}
				}

			},
		}
	}
</script>
<style>
</style>


实现后样式此为uniapp效果

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值