Skip to content

Commit da04010

Browse files
committed
Merge pull request victorjonsson#396 from simivar/master
Added new module: Poland
2 parents b73de7b + 8e5118c commit da04010

File tree

6 files changed

+315
-103
lines changed

6 files changed

+315
-103
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ Read the documentation for the Swedish module at [http://formvalidator.net/#swed
120120
Read the documentation for the UK module at [http://formvalidator.net/#uk-validators](http://formvalidator.net/#uk-validators)
121121

122122
### Module: brazil
123-
* **brphone** — Validate a brazilian telephone number
123+
* **brphone***Validate a brazilian telephone number*
124124
* **cep**
125125
* **cpf**
126+
127+
### Module: poland
128+
* **plpesel** - *validate polish personal identity number (in Polish identity cards)*
129+
* **plnip** - *validate polish VAT identification number*
130+
* **plregon** - *validate polish bussiness identity number*
126131

127132
### Module: sanitation
128133
* **trim**

src/lang/pl.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
imageRatioNotAccepted: 'Proporcje obrazu są niepoprawne',
5959
badBrazilTelephoneAnswer: 'Wprowadzono niepoprawny numer telefonu',
6060
badBrazilCEPAnswer: 'Wprowadzono niepoprawny CEP',
61-
badBrazilCPFAnswer: 'Wprowadzono niepoprawny CPF'
61+
badBrazilCPFAnswer: 'Wprowadzono niepoprawny CPF',
62+
badPlPesel: 'Wprowadzono niepoprawny numer PESEL',
63+
badPlNip: 'Wprowadzono niepoprawny numer NIP',
64+
badPlRegon: 'Wprowadzono niepoprawny numer REGON'
6265
};
6366

6467
});

src/main/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,10 @@
827827
imageRatioNotAccepted : 'Image ratio is not be accepted',
828828
badBrazilTelephoneAnswer: 'The phone number entered is invalid',
829829
badBrazilCEPAnswer: 'The CEP entered is invalid',
830-
badBrazilCPFAnswer: 'The CPF entered is invalid'
830+
badBrazilCPFAnswer: 'The CPF entered is invalid',
831+
badPlPesel: 'The PESEL entered is invalid',
832+
badPlNip: 'The NIP entered is invalid',
833+
badPlRegon: 'The REGON entered is invalid'
831834
}
832835
});
833836

src/modules/poland.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* jQuery Form Validator Module: Poland
3+
* ------------------------------------------
4+
* Created by simivar <https://github.com/simivar>
5+
*
6+
* This form validation module adds validators typically used on
7+
* websites in Poland. This module adds the following validators:
8+
* - plpesel
9+
*
10+
* @website http://formvalidator.net/#poland-validators
11+
* @license MIT
12+
*/
13+
(function($) {
14+
15+
/**
16+
* PL PESEL - polish personal identity number (in Polish identity cards) validator
17+
*/
18+
$.formUtils.addValidator({
19+
name: 'plpesel',
20+
validatorFunction: function(pesel){
21+
var weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3],
22+
checkSum = 0, checkDigit = 0;
23+
24+
if( /\d{11}/.test( pesel ) && pesel.length === 11 ){
25+
for (var i = 0; i < 10; i++) {
26+
checkSum += pesel[ i ] * weights[ i ];
27+
}
28+
29+
if( checkSum % 10 !== 0 ){
30+
checkDigit = 10 - (checkSum % 10);
31+
}
32+
33+
if( parseInt( pesel.charAt( 10 ) ) === checkDigit ){
34+
return true;
35+
}
36+
}
37+
38+
return false;
39+
},
40+
errorMessage: '',
41+
errorMessageKey: 'badPlPesel'
42+
});
43+
44+
/**
45+
* PL NIP - polish VAT identification number validator
46+
*/
47+
$.formUtils.addValidator({
48+
name: 'plnip',
49+
validatorFunction: function(nip){
50+
var weights = [6, 5, 7, 2, 3, 4, 5, 6, 7],
51+
checkSum = 0;
52+
53+
if( /\d{10}/.test( nip ) && nip.length === 10 ){
54+
for (var i = 0; i < 9; i++) {
55+
checkSum += nip[ i ] * weights[ i ];
56+
}
57+
58+
if( parseInt( nip.charAt( 9 ) ) === checkSum % 11 ){
59+
return true;
60+
}
61+
}
62+
63+
return false;
64+
},
65+
errorMessage: '',
66+
errorMessageKey: 'badPlNip'
67+
});
68+
69+
/**
70+
* PL REGON - polish bussiness identity number validator
71+
*/
72+
$.formUtils.addValidator({
73+
name: 'plregon',
74+
validatorFunction: function(regon){
75+
var weightsNine = [8, 9, 2, 3, 4, 5, 6, 7],
76+
weightsFourteen = [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8],
77+
checkSum = 0, checkDigit = 0;
78+
79+
if( /(\d{14}|\d{9})/.test( regon ) && ( regon.length === 9 || regon.length === 14 ) ){
80+
for (var i = 0; i < 8; i++) {
81+
checkSum += regon[ i ] * weightsNine[ i ];
82+
}
83+
84+
if( checkSum % 11 !== 10 ){
85+
checkDigit = checkSum % 11;
86+
}
87+
88+
if( parseInt( regon.charAt( 8 ) ) === checkDigit ){
89+
if( regon.length === 14 ){
90+
checkSum = 0;
91+
92+
for (i = 0; i < 13; i++) {
93+
checkSum += regon[ i ] * weightsFourteen[ i ];
94+
}
95+
96+
if( checkSum % 11 !== 10 ){
97+
checkDigit = checkSum % 11;
98+
}
99+
100+
if( parseInt( regon.charAt( 13 ) ) === checkDigit ){
101+
return true;
102+
}
103+
} else {
104+
return true;
105+
}
106+
}
107+
}
108+
109+
return false;
110+
},
111+
errorMessage: '',
112+
errorMessageKey: 'badPlRegon'
113+
});
114+
115+
})(jQuery);

0 commit comments

Comments
 (0)