Skip to content

Commit f84ffa2

Browse files
victorjonssonsimivar
authored andcommitted
fixed issue victorjonsson#153 if-checked renamed to depends-on and works with any type of input
minor refactoring... new uk validators: utr number and nin Update uk.dev.js
1 parent d9c086e commit f84ffa2

File tree

7 files changed

+76
-5
lines changed

7 files changed

+76
-5
lines changed

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: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
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+
* - utr
910
*
1011
* @website http://formvalidator.net/#uk-validators
1112
* @license MIT
1213
*/
13-
$.formUtils.addValidator({
14+
(function($) {
15+
16+
'use strict';
17+
18+
/**
19+
* UK VAT Validator
20+
*/
21+
$.formUtils.addValidator({
1422
name : 'ukvatnumber',
1523
validatorFunction : function(number) {
1624

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

0 commit comments

Comments
 (0)