2

在我的项目中,我使用以下这些插件进行验证

     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-____]

但是在这里,错误应该通过而不是接受该值。观察:它认为______也有价值。

4

1 回答 1

0

我不知道您如何验证表单,但如果是默认程序,您只是检查该字段是否不为空(必需)。

您需要检查电话值是否与之前的掩码匹配...然后继续验证。

例子

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;
}​
于 2012-08-21T08:08:08.343 回答