【问题标题】:How to add validation of mobile no dyanamically in js如何在js中动态添加手机验证
【发布时间】:2016-12-19 06:33:26
【问题描述】:

如何添加手机号码验证。 html代码:<input type="text" id="mob" name="mob[]" placeholder="Enter mobile no" required>

js代码

container.appendChild(document.createTextNode("mobile"));
var input_m = document.createElement("input");
input_m.type = "text";
input_m.id= id+'_mobile';
input_m.name= "mob[]";
container.appendChild(input_m);

【问题讨论】:

  • 你想要什么验证
  • 对于印度号码:/[7-9][0-9]{9}/。请注意,这是一个基本的验证正则表达式。这将不包括9999999999 之类的情况

标签: javascript html


【解决方案1】:

你可以通过正则表达式做到这一点:

function phonenumber(inputtxt)  {  
    var phoneno = /^\d{10}$/;  
    if((inputtxt.value.match(phoneno)) {  
        return true;  
    } else {  
        alert("message");  
        return false;  
    }  
}  

【讨论】:

  • 注意,最好使用regex.test
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-24
相关资源
最近更新 更多