PHP Classes

File: public/asset/vendor/jquery-validation/src/additional/cnpjBR.js

Recommend this page to a friend!
  Classes of fathurrahman   mnTemplate   public/asset/vendor/jquery-validation/src/additional/cnpjBR.js   Download  
File: public/asset/vendor/jquery-validation/src/additional/cnpjBR.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: mnTemplate
Route HTTP requests to callback functions
Author: By
Last change:
Date: 1 year ago
Size: 1,720 bytes
 

Contents

Class file image Download
/* * 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, element ) { "use strict"; if ( this.optional( element ) ) { return true; } // Removing no number value = value.replace( /[^\d]+/g, "" ); // Checking value to have 14 digits only if ( value.length !== 14 ) { return false; } // Elimina values invalidos conhecidos if ( value === "00000000000000" || value === "11111111111111" || value === "22222222222222" || value === "33333333333333" || value === "44444444444444" || value === "55555555555555" || value === "66666666666666" || value === "77777777777777" || value === "88888888888888" || value === "99999999999999" ) { return false; } // Valida DVs var tamanho = ( value.length - 2 ); var numeros = value.substring( 0, tamanho ); var digitos = value.substring( tamanho ); var soma = 0; var pos = tamanho - 7; for ( var i = tamanho; i >= 1; i-- ) { soma += numeros.charAt( tamanho - i ) * pos--; if ( pos < 2 ) { pos = 9; } } var resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; if ( resultado !== parseInt( digitos.charAt( 0 ), 10 ) ) { return false; } tamanho = tamanho + 1; numeros = value.substring( 0, tamanho ); soma = 0; pos = tamanho - 7; for ( var il = tamanho; il >= 1; il-- ) { soma += numeros.charAt( tamanho - il ) * pos--; if ( pos < 2 ) { pos = 9; } } resultado = soma % 11 < 2 ? 0 : 11 - soma % 11; if ( resultado !== parseInt( digitos.charAt( 1 ), 10 ) ) { return false; } return true; }, "Please specify a CNPJ value number" );