Skip to content

Commit 165005d

Browse files
johana-starjzaefferer
authored andcommitted
Verify nine-digit zip codes. Closes jquery-validationgh-726
1 parent 72f179f commit 165005d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

additional-methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jQuery.validator.addMethod("ziprange", function(value, element) {
5454
}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");
5555

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

6060
jQuery.validator.addMethod("integer", function(value, element) {

test/methods.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ test("zipcodeUS", function() {
959959
var method = methodTest("zipcodeUS");
960960
ok( method( "12345" ), "Valid zip" );
961961
ok( method( "12345-2345" ), "Valid zip" );
962+
ok( method( "90210-4567" ), "Valid zip" );
962963
ok(!method( "1" ), "Invalid zip" );
963964
ok(!method( "1234" ), "Invalid zip" );
964965
ok(!method( "123-23" ), "Invalid zip" );

0 commit comments

Comments
 (0)