1
我有两种方法来验证邮政编码。jquery中的条件验证
我有国家列表框,在这里如果我选择美国,我需要使用usazipRegex方法来验证,或者如果我选择加拿大,我需要使用canadazipRegex验证。假设我选择任何其他国家只是我需要需要
//USA zipcode validation methode
jQuery.validator.addMethod("usazipRegex", function(value, element) {
return this.optional(element) || /^[0-9]{5}(?:-[0-9]{4})?$/i.test(value);
}, "You must enter your postal code in this format: #####-####");
//Canada zipcode validation methode
jQuery.validator.addMethod("canadazipRegex", function(value, element) {
return this.optional(element) || /^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$/i.test(value);
}, "You must enter your postal code in this format: A#A #A#");
我该怎么办this.Suggest我!
其他国家呢!你能解释一下吗?我应该把美国和加拿大的班级加入列表框 – Gowri 2011-05-07 08:23:10