在我的项目中,我使用以下插件进行验证
jquery.validate.min.js,
jquery.ui.core.js,
jquery.ui.widget.js,
jquery.ui.mask.js
我这样称呼它:
$('#txtShippingInfoPhone').mask({mask:"999-999-9999",clearEmpty: false});
默认情况下,输入框为空。像这样
Phone number:
当我键入该文本框时,它看起来像这样
Phone number:___ ___ ____
而且,如果我输入了错误的电话号码,那么它正在接受。例如:
[407-555-____]
但在这里,错误应该通过而不是接受价值。观察:它认为__ __ ____也是值。
我不知道你如何验证表单,但如果是默认的继续,你只是检查该字段是否为空(必需)。
您需要检查电话值是否与之前的掩码匹配...然后继续验证。
例
if($('#txtShippingInfoPhone').mask("valid")){
/* It's valid, continue with the submit... */
return true;
}else{
/* It's NOT valid, trigger the error msg, and interrupt the submit... */
return false;
}