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