Skip to content

Added new module: Poland #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ Read the documentation for the Swedish module at [http://formvalidator.net/#swed
Read the documentation for the UK module at [http://formvalidator.net/#uk-validators](http://formvalidator.net/#uk-validators)

### Module: brazil
* **brphone** — Validate a brazilian telephone number
* **brphone** — *Validate a brazilian telephone number*
* **cep**
* **cpf**

### Module: poland
* **plpesel** - *validate polish personal identity number (in Polish identity cards)*
* **plnip** - *validate polish VAT identification number*
* **plregon** - *validate polish bussiness identity number*

### Module: sanitation
* **trim**
Expand Down
5 changes: 4 additions & 1 deletion src/lang/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
imageRatioNotAccepted: 'Proporcje obrazu są niepoprawne',
badBrazilTelephoneAnswer: 'Wprowadzono niepoprawny numer telefonu',
badBrazilCEPAnswer: 'Wprowadzono niepoprawny CEP',
badBrazilCPFAnswer: 'Wprowadzono niepoprawny CPF'
badBrazilCPFAnswer: 'Wprowadzono niepoprawny CPF',
badPlPesel: 'Wprowadzono niepoprawny numer PESEL',
badPlNip: 'Wprowadzono niepoprawny numer NIP',
badPlRegon: 'Wprowadzono niepoprawny numer REGON'
};

});
Expand Down
5 changes: 4 additions & 1 deletion src/main/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,10 @@
imageRatioNotAccepted : 'Image ratio is not be accepted',
badBrazilTelephoneAnswer: 'The phone number entered is invalid',
badBrazilCEPAnswer: 'The CEP entered is invalid',
badBrazilCPFAnswer: 'The CPF entered is invalid'
badBrazilCPFAnswer: 'The CPF entered is invalid',
badPlPesel: 'The PESEL entered is invalid',
badPlNip: 'The NIP entered is invalid',
badPlRegon: 'The REGON entered is invalid'
}
});

Expand Down
115 changes: 115 additions & 0 deletions src/modules/poland.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* jQuery Form Validator Module: Poland
* ------------------------------------------
* Created by simivar <https://github.com/simivar>
*
* This form validation module adds validators typically used on
* websites in Poland. This module adds the following validators:
* - plpesel
*
* @website http://formvalidator.net/#poland-validators
* @license MIT
*/
(function($) {

/**
* PL PESEL - polish personal identity number (in Polish identity cards) validator
*/
$.formUtils.addValidator({
name: 'plpesel',
validatorFunction: function(pesel){
var weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3],
checkSum = 0, checkDigit = 0;

if( /\d{11}/.test( pesel ) && pesel.length === 11 ){
for (var i = 0; i < 10; i++) {
checkSum += pesel[ i ] * weights[ i ];
}

if( checkSum % 10 !== 0 ){
checkDigit = 10 - (checkSum % 10);
}

if( parseInt( pesel.charAt( 10 ) ) === checkDigit ){
return true;
}
}

return false;
},
errorMessage: '',
errorMessageKey: 'badPlPesel'
});

/**
* PL NIP - polish VAT identification number validator
*/
$.formUtils.addValidator({
name: 'plnip',
validatorFunction: function(nip){
var weights = [6, 5, 7, 2, 3, 4, 5, 6, 7],
checkSum = 0;

if( /\d{10}/.test( nip ) && nip.length === 10 ){
for (var i = 0; i < 9; i++) {
checkSum += nip[ i ] * weights[ i ];
}

if( parseInt( nip.charAt( 9 ) ) === checkSum % 11 ){
return true;
}
}

return false;
},
errorMessage: '',
errorMessageKey: 'badPlNip'
});

/**
* PL REGON - polish bussiness identity number validator
*/
$.formUtils.addValidator({
name: 'plregon',
validatorFunction: function(regon){
var weightsNine = [8, 9, 2, 3, 4, 5, 6, 7],
weightsFourteen = [2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8],
checkSum = 0, checkDigit = 0;

if( /(\d{14}|\d{9})/.test( regon ) && ( regon.length === 9 || regon.length === 14 ) ){
for (var i = 0; i < 8; i++) {
checkSum += regon[ i ] * weightsNine[ i ];
}

if( checkSum % 11 !== 10 ){
checkDigit = checkSum % 11;
}

if( parseInt( regon.charAt( 8 ) ) === checkDigit ){
if( regon.length === 14 ){
checkSum = 0;

for (i = 0; i < 13; i++) {
checkSum += regon[ i ] * weightsFourteen[ i ];
}

if( checkSum % 11 !== 10 ){
checkDigit = checkSum % 11;
}

if( parseInt( regon.charAt( 13 ) ) === checkDigit ){
return true;
}
} else {
return true;
}
}
}

return false;
},
errorMessage: '',
errorMessageKey: 'badPlRegon'
});

})(jQuery);
Loading