Skip to content

Commit

Permalink
Verify nine-digit zip codes. Closes gh-726
Browse files Browse the repository at this point in the history
  • Loading branch information
johana-star authored and jzaefferer committed May 12, 2013
1 parent 72f179f commit 165005d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion additional-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jQuery.validator.addMethod("ziprange", function(value, element) {
}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");

jQuery.validator.addMethod("zipcodeUS", function(value, element) {
return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value);
return this.optional(element) || /^\d{5}-\d{4}$|^\d{5}$/.test(value);
}, "The specified US ZIP Code is invalid");

jQuery.validator.addMethod("integer", function(value, element) {
Expand Down
1 change: 1 addition & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ test("zipcodeUS", function() {
var method = methodTest("zipcodeUS");
ok( method( "12345" ), "Valid zip" );
ok( method( "12345-2345" ), "Valid zip" );
ok( method( "90210-4567" ), "Valid zip" );
ok(!method( "1" ), "Invalid zip" );
ok(!method( "1234" ), "Invalid zip" );
ok(!method( "123-23" ), "Invalid zip" );
Expand Down

0 comments on commit 165005d

Please sign in to comment.