我正在使用jquery验证,我有一个mobilePhone输入字段,它不是必填字段,但如果用户输入任何数字,我将使用以下命令进行掩码:
$('#mobilePhone').mask('000-000-0000');当用户在手机字段“手机号码的格式应该是xxx-xxx-xxxx”中输入错误的数据时,我会放入验证消息。但是当点击submit按钮而没有在移动电话字段中输入任何数据时,它会抛出验证消息“电话号码的格式应该是xxx-xxx-xxxx”。这是错误的。
以下是mobilePhone验证消息的代码:
jQuery.validator.addMethod("phoneUS", function(phone_number,
element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.length > 9
&& phone_number.match(/^\d{3}-\d{3}-\d{4}$/);
}, "Format of the Phone Number should be xxx-xxx-xxxx");
"mobilePhone" : {
phoneUS : true
}这个问题只在IE中发生,但它在火狐和chrome.Could中工作正常,你能告诉我我哪里错了吗?
发布于 2014-11-10 15:31:27
在深入研究之后,我修复了这个问题,删除了
"mobilePhone" : { phoneUS : true }并直接在字段中添加了data-rule。
https://stackoverflow.com/questions/26819098
复制相似问题