uniapp正则表达式校验(复制粘贴即可)

<template>
<view>
<input type="number" @blur="doInput(submitForm.phone)" v-model="submitForm.phone" placeholder="请输入手机号码" maxlength="11" />
</view>
</template>

<script>
export default {
data() {
return {
submitForm: {
phone: ""
}
}
},
methods: {
doInput(val) {
var regPhone = (/^(13[0-9]|14[1579]|15[0-3,5-9]|16[6]|17[0123456789]|18[0-9]|19[89])\d{8}$/); //手机号码
if(!regPhone.test(val)){
uni.showToast({
title: '手机号格式错误',
icon: 'none'
});
return;
}
}
}
}
</script>

<style>
input {
width: 500rpx;
height: 50rpx;
border: 1px solid red;
}
</style>

 

直接复制粘贴根据需求更改校验即可,正则代码在其它的帖子有,可以前往复制

posted @ 2020-12-11 15:47  时光SHG  阅读(6968)  评论(0编辑  收藏  举报