直播软件搭建,姓名,身份证input验证过滤

直播软件搭建,姓名,身份证input验证过滤

姓名验证:需求,可输入英文、汉字

 


for(let i=0;i<e.length;i++){
  if(/^[a-zA-Z\u4e00-\u9fa5]+$/.test(e[i])){
      this.ruleForm.name= e;
   }else{
      if(i == 0){
         this.ruleForm.name = ''
      }else {
         this.ruleForm.name = e.substr(0,i)
      }
      return
   }
}

这个方法就利用@input来获取到$event,然后遍历每个字符是否符合规范,然后把符合规范的截取下来赋值给我们的value。

 

身份证验证:需求,数组、字母

 


for(let i=0;i<e.length;i++){
   if(/^[0-9a-zA-Z]+$/.test(e[i])){
      this.ruleForm.idNumber= e;
   }else{
      if(i == 0){
          this.ruleForm.idNumber = ''
      }else {
          this.ruleForm.idNumber = e.substr(0,i)
      }
      return
   }
}

 

方法同理上面的姓名验证。

 

这里加一个身份证匹配的正则方法

 


if(!this.ruleForm.idNumber || !/^\d{6}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/i.test(this.ruleForm.idNumber)){
    alert('身份证错误,请重新输入!');
    return false;
}

 

以上就是直播软件搭建,姓名,身份证input验证过滤, 更多内容欢迎关注之后的文章 

 

posted @ 2023-02-28 14:13  云豹科技-苏凌霄  阅读(54)  评论(0)    收藏  举报