mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-14 20:35:47 +01:00
Additionals: Make postalCodeCA method more lenient
This commit is contained in:
@@ -12,5 +12,5 @@
|
|||||||
* @cat Plugins/Validate/Methods
|
* @cat Plugins/Validate/Methods
|
||||||
*/
|
*/
|
||||||
$.validator.addMethod( "postalCodeCA", function( value, element ) {
|
$.validator.addMethod( "postalCodeCA", function( value, element ) {
|
||||||
return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d$/.test( value );
|
return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[A-Z] *\d[A-Z]\d$/i.test( value );
|
||||||
}, "Please specify a valid postal code" );
|
}, "Please specify a valid postal code" );
|
||||||
|
|||||||
@@ -1181,12 +1181,14 @@ test("currency", function() { // Works with any symbol
|
|||||||
|
|
||||||
test("postalCodeCA", function() {
|
test("postalCodeCA", function() {
|
||||||
var method = methodTest("postalCodeCA");
|
var method = methodTest("postalCodeCA");
|
||||||
ok( method( "H0H 0H0"), "Valid CA Postal Code; Single space" );
|
ok( method( "H0H0H0"), "Valid Canadian postal code: all upper case with no space" );
|
||||||
ok( !method( "H0H0H0"), "Inalid CA Postal Code; No space" );
|
ok( method( "H0H 0H0"), "Valid Canadian postal code: all upper case with one space" );
|
||||||
ok( !method( "H0H-0H0"), "Invalid CA Postal Code; Single dash" );
|
ok( method( "H0H 0H0"), "Valid Canadian postal code: all upper case with multiple spaces" );
|
||||||
ok( !method( "H0H 0H"), "Invalid CA Postal Code; Too Short" );
|
ok( method( "h0h 0h0"), "Valid Canadian postal code: all lower case with space" );
|
||||||
ok( !method( "Z0H 0H"), "Invalid CA Postal Code; Only 'ABCEGHJKLMNPRSTVXY' are valid starting characters" );
|
ok( method( "h0h0h0" ), "Valid Canadian postal code: all lower case with no space" );
|
||||||
ok( !method( "h0h 0h0"), "Invalid CA Postal Code; Only upper case characters" );
|
ok( !method( "H0H-0H0"), "Invalid Canadian postal code: dash used as separator" );
|
||||||
|
ok( !method( "H0H 0H"), "Invalid Canadian postal code: too short" );
|
||||||
|
ok( !method( "Z0H 0H"), "Invalid Canadian postal code: only 'ABCEGHJKLMNPRSTVXY' are valid starting characters" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("stateUS", function() {
|
test("stateUS", function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user