Skip to content

Commit 544a4e7

Browse files
committed
Merge pull request victorjonsson#390 from simivar/master
added new uk validators: utr number and nin
2 parents 4254ddb + 0236ef6 commit 544a4e7

File tree

8 files changed

+79
-5
lines changed

8 files changed

+79
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Read the documentation for the Swedish module at [http://formvalidator.net/#swed
115115

116116
### Module: uk
117117
* **ukvatnumber**
118+
* **uknin** - *validate UK National Insurance number*
119+
* **ukutr** - *validate UK Unique Taxpayer Reference number*
118120

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

form-validator/jquery.form-validator.min.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/jsconf.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* JQUERY-FORM-VALIDATOR
3+
*
4+
* @version 2.2.187
5+
* @website http://formvalidator.net/
6+
* @author Victor Jonsson, http://victorjonsson.se
7+
* @license MIT
8+
*/
9+
!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);

form-validator/lang/pl.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/uk.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lang/pl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
badInt: 'Wprowadzono nieprawidłowy numer',
3535
badSecurityNumber: 'Wprowadzono niepoprawny numer ubezpieczenia społecznego',
3636
badUKVatAnswer: 'Wprowadzono niepoprawny brytyjski numer VAT',
37+
badUKNin: 'Wprowadzono niepoprawny brytyjski numer NIP',
38+
badUKUtr: 'Wprowadzono niepoprawny brytyjski numer podatnika',
3739
badStrength: 'Twoje hasło nie jest wystarczająco mocne',
3840
badNumberOfSelectedOptionsStart: 'Musisz wybrać przynajmniej ',
3941
badNumberOfSelectedOptionsEnd: ' odpowiedzi',

src/main/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,8 @@
801801
badInt: 'The input value was not a correct number',
802802
badSecurityNumber: 'Your social security number was incorrect',
803803
badUKVatAnswer: 'Incorrect UK VAT Number',
804+
badUKNin: 'Incorrect UK NIN',
805+
badUKUtr: 'Incorrect UK UTR Number',
804806
badStrength: 'The password isn\'t strong enough',
805807
badNumberOfSelectedOptionsStart: 'You have to choose at least ',
806808
badNumberOfSelectedOptionsEnd: ' answers',

src/modules/uk.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
/**
2-
* jQuery Form Validator Module: Security
2+
* jQuery Form Validator Module: UK
33
* ------------------------------------------
44
* Created by Victor Jonsson <http://www.victorjonsson.se>
55
*
66
* This form validation module adds validators typically used on
77
* websites in the UK. This module adds the following validators:
88
* - ukvatnumber
9+
* - ukutr
10+
* - uknin
911
*
1012
* @website http://formvalidator.net/#uk-validators
1113
* @license MIT
1214
*/
13-
$.formUtils.addValidator({
15+
(function($) {
16+
17+
'use strict';
18+
19+
/**
20+
* UK VAT Validator
21+
*/
22+
$.formUtils.addValidator({
1423
name : 'ukvatnumber',
1524
validatorFunction : function(number) {
1625

@@ -82,3 +91,49 @@ $.formUtils.addValidator({
8291
errorMessage : '',
8392
errorMessageKey: 'badUKVatAnswer'
8493
});
94+
95+
/**
96+
* UK Unique Taxpayer Reference Validator
97+
*/
98+
$.formUtils.addValidator({
99+
name: 'ukutr',
100+
validatorFunction: function (val)
101+
{
102+
var weights = [0, 6, 7, 8, 9, 10, 5, 4, 3, 2, 0],
103+
checkDigits = [2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1],
104+
checkSum = 0,
105+
utr = val + 'K';
106+
107+
if( /\d{10}K/.test( utr ) ){
108+
for (var i = 0; i < 10; i++) {
109+
checkSum += utr[ i ] * weights[ i ];
110+
}
111+
112+
if( utr.charAt( 0 ) === checkDigits[ checkSum % 11 ]){
113+
return true;
114+
}
115+
}
116+
117+
return false;
118+
},
119+
errorMessage: '',
120+
errorMessageKey: 'badUkUtr'
121+
});
122+
123+
/**
124+
* UK National Insurance number Validator
125+
*/
126+
$.formUtils.addValidator({
127+
name: 'uknin',
128+
validatorFunction: function(val){
129+
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 ) ){
130+
return true;
131+
}
132+
133+
return false;
134+
},
135+
errorMessage: '',
136+
errorMessageKey: 'badUkNin'
137+
});
138+
139+
})(jQuery);

0 commit comments

Comments
 (0)