From bee93e1cfdfb876bad882d57df1840d4210dedc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Mon, 1 Oct 2018 11:07:23 -0300 Subject: [PATCH 01/15] Create cnhBR.js A validation of CNH (Brazilian License Driver) --- src/additional/cnhBR.js | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/additional/cnhBR.js diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js new file mode 100644 index 000000000..e786b9f11 --- /dev/null +++ b/src/additional/cnhBR.js @@ -0,0 +1,49 @@ +/* + * 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; + + firstChar = value.charAt(0) + + if(firstChar.repeat(11) == value) { + return false; + } + + // Step 1 - using first Check Number: + for ( var 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" ); From 44fd8bf5123a2c104f94de511d03045f4be4cb71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Mon, 1 Oct 2018 13:54:28 -0300 Subject: [PATCH 02/15] Update messages_pt_BR.js Added portuguese message for CNH validation --- src/localization/messages_pt_BR.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/localization/messages_pt_BR.js b/src/localization/messages_pt_BR.js index 08c2c94bd..4f9effad8 100644 --- a/src/localization/messages_pt_BR.js +++ b/src/localization/messages_pt_BR.js @@ -73,5 +73,6 @@ $.extend( $.validator.messages, { zipcodeUS: "Por favor, forneça um código postal americano válido.", ziprange: "O código postal deve estar entre 902xx-xxxx e 905xx-xxxx", cpfBR: "Por favor, forneça um CPF válido.", - nisBR: "Por favor, forneça um NIS/PIS válido" + nisBR: "Por favor, forneça um NIS/PIS válido", + cnhBR: "Por favor, forneça um CNH válido." } ); From 0552bdf2c3f8b698fa8e55a43234ffb855e98e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Mon, 1 Oct 2018 14:14:02 -0300 Subject: [PATCH 03/15] Change code style --- src/additional/cnhBR.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index e786b9f11..d44e57cf1 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -41,9 +41,9 @@ $.validator.addMethod( "cnhBR", function( value ) { if ( secondCN >= 10 ) { secondCN = 0; } else { - secondCN = secondCN - dsc; - } + secondCN = secondCN - dsc; + } - return String(firstCN).concat(secondCN) == value.substr(-2); + return (String(firstCN).concat(secondCN) == value.substr(-2)); }, "Please specify a valid CNH number" ); From d730c2fdd485b11c1925ffaff0de9bbbfa4c928e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Mon, 8 Oct 2018 15:19:40 -0300 Subject: [PATCH 04/15] Create CNHBR test --- test/additional/cnhBr.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/additional/cnhBr.js diff --git a/test/additional/cnhBr.js b/test/additional/cnhBr.js new file mode 100644 index 000000000..6da716d80 --- /dev/null +++ b/test/additional/cnhBr.js @@ -0,0 +1,6 @@ +QUnit.test( "cnhbr", function( assert ) { + var method = methodTest( "cnhbr" ); + assert.ok( method( "00000000119" ), "Valid driver's license number" ); + assert.ok( !method( "11111111111" ), "Invalid driver's license number" ); + assert.ok( !method( "asdf" ), "Invalid driver's license number" ); +} ); From 607c8abcbe51b1dd50a04c76cc2b81a4c0cbfe80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Mon, 8 Oct 2018 15:24:06 -0300 Subject: [PATCH 05/15] Update index.html added cnhBr --- test/index.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/index.html b/test/index.html index d02732856..6cd20d022 100644 --- a/test/index.html +++ b/test/index.html @@ -15,6 +15,7 @@ + @@ -446,6 +447,12 @@

+ +
+ + +
+

From 8c69e05912816aa0100fa212f1bbb46606bcafcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 17:38:55 -0300 Subject: [PATCH 06/15] Update code style --- src/additional/cnhBR.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index d44e57cf1..b6240f995 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -15,26 +15,26 @@ $.validator.addMethod( "cnhBR", function( value ) { var sum = 0, dsc = 0, firstChar, firstCN, secondCN, i, j; - firstChar = value.charAt(0) + firstChar = value.charAt( 0 ) - if(firstChar.repeat(11) == value) { + if( firstChar.repeat( 11 ) == value ) { return false; } // Step 1 - using first Check Number: for ( var i = 0, j = 9, v = 0; i < 9; ++i, --j ) { - sum += +( value.charAt(i) * j ); + sum += +( value.charAt( i ) * j ); } firstCN = sum % 11; - if ( firstCN >= 10) { + 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); + sum += +( value.charAt( i ) * j ); } secondCN = sum % 11; @@ -44,6 +44,6 @@ $.validator.addMethod( "cnhBR", function( value ) { secondCN = secondCN - dsc; } - return (String(firstCN).concat(secondCN) == value.substr(-2)); + return ( String( firstCN ).concat( secondCN ) == value.substr( -2 ) ); }, "Please specify a valid CNH number" ); From 3acea8f470bad0d3e7867550bab6e56890c4d545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 17:41:31 -0300 Subject: [PATCH 07/15] Update code style --- src/additional/cnhBR.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index b6240f995..b3f02afaf 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -15,14 +15,14 @@ $.validator.addMethod( "cnhBR", function( value ) { var sum = 0, dsc = 0, firstChar, firstCN, secondCN, i, j; - firstChar = value.charAt( 0 ) - + firstChar = value.charAt( 0 ); + if( firstChar.repeat( 11 ) == value ) { return false; } - // Step 1 - using first Check Number: - for ( var i = 0, j = 9, v = 0; i < 9; ++i, --j ) { + // Step 1 - using first Check Number: + for ( var i = 0, j = 9, v = 0; i < 9; ++i, --j ) { sum += +( value.charAt( i ) * j ); } From f02da4a9e2c63ed3b1e8bda5f9cb47c1c26b1757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 17:46:33 -0300 Subject: [PATCH 08/15] Fix code style --- src/additional/cnhBR.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index b3f02afaf..1f142435c 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -17,7 +17,7 @@ $.validator.addMethod( "cnhBR", function( value ) { firstChar = value.charAt( 0 ); - if( firstChar.repeat( 11 ) == value ) { + if ( firstChar.repeat( 11 ) == value ) { return false; } @@ -25,25 +25,25 @@ $.validator.addMethod( "cnhBR", function( value ) { for ( var 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" ); From e8377d4d3773082011310b963b8d4217b7dd19e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 17:49:23 -0300 Subject: [PATCH 09/15] fix code style --- src/additional/cnhBR.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index 1f142435c..713104812 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -4,15 +4,15 @@ */ $.validator.addMethod( "cnhBR", function( value ) { - // Removing special characters from value - value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" ); + // Removing special characters from value + value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" ); - // Checking value to have 11 digits only - if ( value.length !== 11 ) { - return false; - } + // Checking value to have 11 digits only + if ( value.length !== 11 ) { + return false; + } - var sum = 0, dsc = 0, firstChar, + var sum = 0, dsc = 0, firstChar, firstCN, secondCN, i, j; firstChar = value.charAt( 0 ); From b2f83a730c0fb004e7f8eab0b07bf3fa54627932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 17:52:13 -0300 Subject: [PATCH 10/15] Update --- src/additional/cnhBR.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index 713104812..609ad8557 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -41,7 +41,7 @@ $.validator.addMethod( "cnhBR", function( value ) { if ( secondCN >= 10 ) { secondCN = 0; } else { - secondCN = secondCN - dsc; + secondCN = secondCN - dsc; } return ( String( firstCN ).concat( secondCN ) == value.substr( -2 ) ); From 62a823b1e7ea61798eb13da6a2853cf95b1d6880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 17:57:15 -0300 Subject: [PATCH 11/15] Update conditionals --- src/additional/cnhBR.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index 609ad8557..f5a790ab8 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -17,12 +17,12 @@ $.validator.addMethod( "cnhBR", function( value ) { firstChar = value.charAt( 0 ); - if ( firstChar.repeat( 11 ) == value ) { + if ( firstChar.repeat( 11 ) === value ) { return false; } // Step 1 - using first Check Number: - for ( var i = 0, j = 9, v = 0; i < 9; ++i, --j ) { + for ( i = 0, j = 9, v = 0; i < 9; ++i, --j ) { sum += +( value.charAt( i ) * j ); } @@ -44,6 +44,6 @@ $.validator.addMethod( "cnhBR", function( value ) { secondCN = secondCN - dsc; } - return ( String( firstCN ).concat( secondCN ) == value.substr( -2 ) ); + return ( String( firstCN ).concat( secondCN ) === value.substr( -2 ) ); }, "Please specify a valid CNH number" ); From 97e709e6bf1c815f8e51119e9448af0e430fd32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 18:01:21 -0300 Subject: [PATCH 12/15] Define variable V --- src/additional/cnhBR.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index f5a790ab8..747547d92 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -13,7 +13,7 @@ $.validator.addMethod( "cnhBR", function( value ) { } var sum = 0, dsc = 0, firstChar, - firstCN, secondCN, i, j; + firstCN, secondCN, i, j, v; firstChar = value.charAt( 0 ); From 05e4264b95dc5556c7567043e0426af28a4b9d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 18:15:02 -0300 Subject: [PATCH 13/15] Update index.html --- test/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.html b/test/index.html index cc476210e..bf22a640a 100644 --- a/test/index.html +++ b/test/index.html @@ -15,7 +15,7 @@ - + From f92789d98387e03dad924171fa16dff27356e298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Issamu=20Francisco?= Date: Wed, 31 Oct 2018 18:15:50 -0300 Subject: [PATCH 14/15] Update and rename cnhBr.js to cnhBR.js --- test/additional/{cnhBr.js => cnhBR.js} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename test/additional/{cnhBr.js => cnhBR.js} (73%) diff --git a/test/additional/cnhBr.js b/test/additional/cnhBR.js similarity index 73% rename from test/additional/cnhBr.js rename to test/additional/cnhBR.js index 6da716d80..99bdf847d 100644 --- a/test/additional/cnhBr.js +++ b/test/additional/cnhBR.js @@ -1,5 +1,5 @@ -QUnit.test( "cnhbr", function( assert ) { - var method = methodTest( "cnhbr" ); +QUnit.test( "cnhBR", function( assert ) { + var method = methodTest( "cnhBR" ); assert.ok( method( "00000000119" ), "Valid driver's license number" ); assert.ok( !method( "11111111111" ), "Invalid driver's license number" ); assert.ok( !method( "asdf" ), "Invalid driver's license number" ); From efdccb1d9c045b35819bd3fa643d20eeb825b7b2 Mon Sep 17 00:00:00 2001 From: Brahim Arkni Date: Mon, 5 Nov 2018 14:49:01 -0200 Subject: [PATCH 15/15] Change ES6 to support IE Co-Authored-By: joaoissamu --- src/additional/cnhBR.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/additional/cnhBR.js b/src/additional/cnhBR.js index 747547d92..67ea7965a 100644 --- a/src/additional/cnhBR.js +++ b/src/additional/cnhBR.js @@ -17,7 +17,7 @@ $.validator.addMethod( "cnhBR", function( value ) { firstChar = value.charAt( 0 ); - if ( firstChar.repeat( 11 ) === value ) { + if ( new Array( 12 ).join( firstChar ) === value ) { return false; }