关于对输入内容正则表达式判断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效果
