如何在js中添加没有动态的移动验证

时间:2016-12-19 06:33:26

标签: javascript html

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

js code

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);

1 个答案:

答案 0 :(得分:1)

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

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