【发布时间】:2015-09-30 19:26:04
【问题描述】:
我正在使用 jquery 验证电话号码,格式如下:
+XX-XXXX-XXXX
+XX.XXXX.XXXX
+XX XXXX XXXX
但是,它在控制台中给了我一个错误:
未捕获的类型错误:无法读取未定义的属性“匹配”
function phonenumber(inputtxt) {
var phoneno = /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;
if(inputtxt.value.match(phoneno)) {
return true;
}
else {
alert("message");
return false;
}
}
jQuery(".btnchec").click(function(){
var inputtxt = jQuery("#inputcpf").val();
console.log(phonenumber(inputtxt));
});
<fieldset>
<legend>Validation</legend>
<div style= "padding-top:15px;">
<label style= "padding: 20px; font-size: 16px; font-weight:600; color: #AA6903;">ID: </label>
<input type="text" id="inputcpf" name="cpf" size="18" maxlength="18" autofocus>
<input type="button" style= "margin-top:10px;" class="btnchec" name="Submit" value="Check">
</div>
</fieldset>
【问题讨论】:
标签: javascript jquery html