mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2026-06-12 15:37:05 +02:00
Additionals: Add postalcodeBR method
Validates brazialian postal codes Closes #1291
This commit is contained in:
committed by
Jörn Zaefferer
parent
52debd4509
commit
cc6c4a4fd6
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Valida CEPs do brasileiros:
|
||||
*
|
||||
* Formatos aceitos:
|
||||
* 99999-999
|
||||
* 99.999-999
|
||||
* 99999999
|
||||
*/
|
||||
$.validator.addMethod("postalcodeBR", function(cep_value, element) {
|
||||
return this.optional(element) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
|
||||
}, "Informe um CEP válido.");
|
||||
@@ -23,5 +23,6 @@ $.extend($.validator.messages, {
|
||||
min: $.validator.format("Por favor, forneça um valor maior ou igual a {0}."),
|
||||
nifES: "Por favor, forneça um NIF válido.",
|
||||
nieES: "Por favor, forneça um NIE válido.",
|
||||
cifEE: "Por favor, forneça um CIF válido."
|
||||
cifEE: "Por favor, forneça um CIF válido.",
|
||||
postalcodeBR: "Por favor, forneça um CEP válido."
|
||||
});
|
||||
|
||||
@@ -1261,4 +1261,12 @@ test("stateUS", function() {
|
||||
ok(!method( "mp", { caseSensitive: false, includeTerritories: false } ), "US territories not allowed" );
|
||||
});
|
||||
|
||||
test("postalcodeBR", function() {
|
||||
var method = methodTest("postalcodeBR");
|
||||
ok( method( "99999-999"), "Valid BR Postal Code");
|
||||
ok( method( "99999999"), "Valid BR Postal Code");
|
||||
ok( method( "99.999-999"), "Valid BR Postal Code");
|
||||
ok( !method( "99.999999"), "Invalid BR Postal Code");
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
||||
Reference in New Issue
Block a user