PHP Classes

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

Recommend this page to a friend!
  Classes of fathurrahman   mnTemplate   public/asset/vendor/jquery-validation/src/additional/cnhBR.js   Download  
File: public/asset/vendor/jquery-validation/src/additional/cnhBR.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,212 bytes
 

Contents

Class file image Download
/* * Brazillian CNH number (Carteira Nacional de Habilitacao) is the License Driver number. * CNH numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation. */ $.validator.addMethod( "cnhBR", function( value ) { // Removing special characters from value value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" ); // Checking value to have 11 digits only if ( value.length !== 11 ) { return false; } var sum = 0, dsc = 0, firstChar, firstCN, secondCN, i, j, v; firstChar = value.charAt( 0 ); if ( new Array( 12 ).join( firstChar ) === value ) { return false; } // Step 1 - using first Check Number: for ( i = 0, j = 9, v = 0; i < 9; ++i, --j ) { sum += +( value.charAt( i ) * j ); } firstCN = sum % 11; if ( firstCN >= 10 ) { firstCN = 0; dsc = 2; } sum = 0; for ( i = 0, j = 1, v = 0; i < 9; ++i, ++j ) { sum += +( value.charAt( i ) * j ); } secondCN = sum % 11; if ( secondCN >= 10 ) { secondCN = 0; } else { secondCN = secondCN - dsc; } return ( String( firstCN ).concat( secondCN ) === value.substr( -2 ) ); }, "Please specify a valid CNH number" );