四时宝库

程序员的知识宝库

vue.js 正则验证手机号(vue校验手机号)

html input框

<input type="tel" placeholder="请输入手机号" class="log_input" v-model.trim="tel" @focus="textF" @blur="change" />

js 方法验证

blur(event){

if(this.pass === "" ){

this.blurShow = "密码不能为空"

event.target.style.borderColor = 'red';

}else{

this.blurShow = ""

}

},

change(event) {

let myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;

if(this.tel && myreg.test(this.tel)) {

this.num = false;

this.numMsg = '';

event.target.style.borderColor = 'gainsboro';

}else if(this.tel === ""){

this.num = true;

this.numMsg = '手机号不能为空';

event.target.style.borderColor = 'red';

} else{

this.num = true;

this.numMsg = '手机号格式不正确';

event.target.style.borderColor = 'red';

}

},

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接