Skip to content

added new uk validators: utr number and nin #390

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 3 commits into from
Feb 25, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Read the documentation for the Swedish module at [http://formvalidator.net/#swed

### Module: uk
* **ukvatnumber**
* **uknin** - *validate UK National Insurance number*
* **ukutr** - *validate UK Unique Taxpayer Reference number*

Read the documentation for the UK module at [http://formvalidator.net/#uk-validators](http://formvalidator.net/#uk-validators)

Expand Down
6 changes: 5 additions & 1 deletion form-validator/jquery.form-validator.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions form-validator/jsconf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* JQUERY-FORM-VALIDATOR
*
* @version 2.2.187
* @website http://formvalidator.net/
* @author Victor Jonsson, http://victorjonsson.se
* @license MIT
*/
!function(a){"use strict";a.setupValidation=function(b){var c=a(b.form||"form");a.each(b.validate||b.validation||{},function(b,d){var e;e="#"===b[0]?a(b):c.find("."===b[0]?b:'*[name="'+b+'"]'),e.attr("data-validation",d.validation),a.each(d,function(a,b){"validation"!==a&&b!==!1&&(b===!0&&(b="true"),"_"===a[0]?(a=a.substring(1),b===!1?e.removeAttr(a):e.attr(a,b)):e.valAttr(a,b))})}),a.validate(b)}}(jQuery);
2 changes: 1 addition & 1 deletion form-validator/lang/pl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion form-validator/uk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/lang/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
badInt: 'Wprowadzono nieprawidłowy numer',
badSecurityNumber: 'Wprowadzono niepoprawny numer ubezpieczenia społecznego',
badUKVatAnswer: 'Wprowadzono niepoprawny brytyjski numer VAT',
badUKNin: 'Wprowadzono niepoprawny brytyjski numer NIP',
badUKUtr: 'Wprowadzono niepoprawny brytyjski numer podatnika',
badStrength: 'Twoje hasło nie jest wystarczająco mocne',
badNumberOfSelectedOptionsStart: 'Musisz wybrać przynajmniej ',
badNumberOfSelectedOptionsEnd: ' odpowiedzi',
Expand Down
2 changes: 2 additions & 0 deletions src/main/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@
badInt: 'The input value was not a correct number',
badSecurityNumber: 'Your social security number was incorrect',
badUKVatAnswer: 'Incorrect UK VAT Number',
badUKNin: 'Incorrect UK NIN',
badUKUtr: 'Incorrect UK UTR Number',
badStrength: 'The password isn\'t strong enough',
badNumberOfSelectedOptionsStart: 'You have to choose at least ',
badNumberOfSelectedOptionsEnd: ' answers',
Expand Down
59 changes: 57 additions & 2 deletions src/modules/uk.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
/**
* jQuery Form Validator Module: Security
* jQuery Form Validator Module: UK
* ------------------------------------------
* Created by Victor Jonsson <http://www.victorjonsson.se>
*
* This form validation module adds validators typically used on
* websites in the UK. This module adds the following validators:
* - ukvatnumber
* - ukutr
* - uknin
*
* @website http://formvalidator.net/#uk-validators
* @license MIT
*/
$.formUtils.addValidator({
(function($) {

'use strict';

/**
* UK VAT Validator
*/
$.formUtils.addValidator({
name : 'ukvatnumber',
validatorFunction : function(number) {

Expand Down Expand Up @@ -82,3 +91,49 @@ $.formUtils.addValidator({
errorMessage : '',
errorMessageKey: 'badUKVatAnswer'
});

/**
* UK Unique Taxpayer Reference Validator
*/
$.formUtils.addValidator({
name: 'ukutr',
validatorFunction: function (val)
{
var weights = [0, 6, 7, 8, 9, 10, 5, 4, 3, 2, 0],
checkDigits = [2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],
checkSum = 0,
utr = val + 'K';

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

if( utr.charAt( 0 ) === checkDigits[ checkSum % 11 ]){
return true;
}
}

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

/**
* UK National Insurance number Validator
*/
$.formUtils.addValidator({
name: 'uknin',
validatorFunction: function(val){
if( /^(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)(?:[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z])(?:\s*\d\s*){6}([A-D]|\s)$/i.test( val ) ){
return true;
}

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

})(jQuery);