Skip to content

Commit 2dfd33c

Browse files
jcspaderArkni
authored andcommitted
Additional: Don't fail when field is optional in CNPJBR & CPFBR rules (jquery-validation#2236)
1 parent 3242f0f commit 2dfd33c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/additional/cnpjBR.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
* Brazillian value number (Cadastrado de Pessoas Juridica).
33
* value numbers have 14 digits in total: 12 numbers followed by 2 check numbers that are being used for validation.
44
*/
5-
$.validator.addMethod( "cnpjBR", function( value ) {
5+
$.validator.addMethod( "cnpjBR", function( value, element ) {
6+
"use strict";
7+
8+
if ( this.optional( element ) ) {
9+
return true;
10+
}
611

712
// Removing no number
813
value = value.replace( /[^\d]+/g, "" );

src/additional/cpfBR.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
* Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number.
33
* CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
44
*/
5-
$.validator.addMethod( "cpfBR", function( value ) {
5+
$.validator.addMethod( "cpfBR", function( value, element ) {
6+
"use strict";
7+
8+
if ( this.optional( element ) ) {
9+
return true;
10+
}
611

712
// Removing special characters from value
813
value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );

0 commit comments

Comments
 (0)