回车间隔输入手机号的手机校验

原创 motu_1991 随笔 vueJs 269阅读 2017-11-08 16:36:26 举报

之前的写法有点问题,就是前后有空格的时候不对,特修改以下并优化一下代码:

<el-form :label-position="label_position" class="base-form" ref="base_info" :model="base_info" :rules="rules">
<el-form-item label="可见用户:" prop="visibleUserStr">
<el-radio class="radio" v-model="radio" label="0">情况1</el-radio><br/>
<el-radio class="radio" v-model="radio" label="1">情况1</el-radio><br/>
<el-input type="textarea" v-model="visible_user" :disabled=" radio == 1 ? false : true" ></el-input>
</el-form-item>
</el-form>####

var Mobile = (rule, value, callback) => {
if(this.base_info.product_type == sku_type.SKU_DQ){
let mobileStr = this.visible_user;
if(mobileStr != "" || mobileStr != "undefined"){
let reg = /^1[3|4|5|7|8][0-9]{9}$/;
var string = mobileStr;
try{
string=string.replace(/[\r\n]/g,"<br>")
string=string.replace(/\s+/g,"<br>");
string=string.replace(/ /g,"<br>");
}catch(e) {
console.log(e.message);
}
string.split('<br>').filter(val => val).some((mobile, index) => { //filter直接写在这里,省去重新声明一个数组,some返回true的时候就停止,不用往下继续执行
let check = reg.test(mobile);
if(!check){
this.checkMobile = false;
callback(new Error(第${+index+1}个手机号有误));
}
return !check;
});
}else{
this.checkMobile = true;
return callback();
}

            }
        }
评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复