| 2 |
lars |
1 |
/**
|
|
|
2 |
* Created for project jquery-validation.
|
|
|
3 |
* @Description Brazillian PIS or NIS number (Número de Identificação Social Pis ou Pasep) is the equivalent of a
|
|
|
4 |
* Brazilian tax registration number NIS of PIS numbers have 11 digits in total: 10 numbers followed by 1 check numbers
|
|
|
5 |
* that are being used for validation.
|
|
|
6 |
* @copyright (c) 21/08/2018 13:14, Cleiton da Silva Mendonça
|
|
|
7 |
* @author Cleiton da Silva Mendonça <cleiton.mendonca@gmail.com>
|
|
|
8 |
* @link http://gitlab.com/csmendonca Gitlab of Cleiton da Silva Mendonça
|
|
|
9 |
* @link http://github.com/csmendonca Github of Cleiton da Silva Mendonça
|
|
|
10 |
*/
|
|
|
11 |
$.validator.addMethod( "nisBR", function( value ) {
|
|
|
12 |
var number;
|
|
|
13 |
var cn;
|
|
|
14 |
var sum = 0;
|
|
|
15 |
var dv;
|
|
|
16 |
var count;
|
|
|
17 |
var multiplier;
|
|
|
18 |
|
|
|
19 |
// Removing special characters from value
|
|
|
20 |
value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" );
|
|
|
21 |
|
|
|
22 |
// Checking value to have 11 digits only
|
|
|
23 |
if ( value.length !== 11 ) {
|
|
|
24 |
return false;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
//Get check number of value
|
|
|
28 |
cn = parseInt( value.substring( 10, 11 ), 10 );
|
|
|
29 |
|
|
|
30 |
//Get number with 10 digits of the value
|
|
|
31 |
number = parseInt( value.substring( 0, 10 ), 10 );
|
|
|
32 |
|
|
|
33 |
for ( count = 2; count < 12; count++ ) {
|
|
|
34 |
multiplier = count;
|
|
|
35 |
if ( count === 10 ) {
|
|
|
36 |
multiplier = 2;
|
|
|
37 |
}
|
|
|
38 |
if ( count === 11 ) {
|
|
|
39 |
multiplier = 3;
|
|
|
40 |
}
|
|
|
41 |
sum += ( ( number % 10 ) * multiplier );
|
|
|
42 |
number = parseInt( number / 10, 10 );
|
|
|
43 |
}
|
|
|
44 |
dv = ( sum % 11 );
|
|
|
45 |
|
|
|
46 |
if ( dv > 1 ) {
|
|
|
47 |
dv = ( 11 - dv );
|
|
|
48 |
} else {
|
|
|
49 |
dv = 0;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
if ( cn === dv ) {
|
|
|
53 |
return true;
|
|
|
54 |
} else {
|
|
|
55 |
return false;
|
|
|
56 |
}
|
|
|
57 |
}, "Please specify a valid NIS/PIS number" );
|