Skip to content

Additional (CNPJBR and CPFBR): Fix not to fail when field is not required #2236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/additional/cnpjBR.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* Brazillian value number (Cadastrado de Pessoas Juridica).
* value numbers have 14 digits in total: 12 numbers followed by 2 check numbers that are being used for validation.
*/
$.validator.addMethod( "cnpjBR", function( value ) {
$.validator.addMethod( "cnpjBR", function( value, element ) {
"use strict";

if ( this.optional( element ) ) {
return true;
}

// Removing no number
value = value.replace( /[^\d]+/g, "" );
Expand Down
7 changes: 6 additions & 1 deletion src/additional/cpfBR.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number.
* CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation.
*/
$.validator.addMethod( "cpfBR", function( value ) {
$.validator.addMethod( "cpfBR", function( value, element ) {
"use strict";

if ( this.optional( element ) ) {
return true;
}

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