Skip to content

Commit 4467bc3

Browse files
committed
Added support for hyphen in SSN and added unit tests
1 parent 6ca3c10 commit 4467bc3

File tree

9 files changed

+49
-12
lines changed

9 files changed

+49
-12
lines changed

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 1.9.35
15+
* @version 1.9.36
1616
*/
1717
(function($) {
1818

form-validator/jquery.form-validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
66
*
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 1.9.35
8+
* @version 1.9.36
99
*/
1010
(function($) {
1111

form-validator/jquery.form-validator.min.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/location.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* @license Dual licensed under the MIT or GPL Version 2 licenses
14-
* @version 1.9.35
14+
* @version 1.9.36
1515
*/
1616
(function($) {
1717

form-validator/security.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @website http://formvalidator.net/#security-validators
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 1.9.35
16+
* @version 1.9.36
1717
*/
1818
(function($) {
1919

form-validator/sweden.dev.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - validate_swephone
1414
*
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 1.9.35
16+
* @version 1.9.36
1717
*/
1818
(function($, window) {
1919

@@ -22,14 +22,25 @@
2222
*/
2323
$.formUtils.addValidator({
2424
name : 'validate_swesec',
25-
validate : function(securityNumber) {
25+
validate : function(securityNumber, $input) {
26+
27+
var year, month, day, ssnParts;
28+
29+
if( $input.valAttr('use-hyphen') ) {
30+
ssnParts = securityNumber.split('-');
31+
if( ssnParts.length != 2 ) {
32+
return false;
33+
}
34+
securityNumber = ssnParts.join('');
35+
}
36+
2637
if (!securityNumber.match(/^(\d{4})(\d{2})(\d{2})(\d{4})$/)) {
2738
return false;
2839
}
2940

30-
var year = RegExp.$1;
31-
var month = $.formUtils.parseDateInt(RegExp.$2);
32-
var day = $.formUtils.parseDateInt(RegExp.$3);
41+
year = RegExp.$1;
42+
month = $.formUtils.parseDateInt(RegExp.$2);
43+
day = $.formUtils.parseDateInt(RegExp.$3);
3344

3445
window.ssnGender = ( parseInt( (RegExp.$4).substring(2,3) ) % 2 ) === 0 ? 'female':'male';
3546

form-validator/sweden.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/test.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,32 @@
370370
});
371371
});
372372

373+
/*
374+
* SWEDISH SSN VALIDATION
375+
*/
376+
test("Swedish SSN validation", function() {
377+
378+
clearForm();
379+
380+
var links = [
381+
{val:'19:59', isValid:false},
382+
{val:'', isValid:false},
383+
{val:'198311084936', isValid:true},
384+
{val:'198311084935', isValid:false},
385+
{val:'198301128529', isValid:true},
386+
{val:'198301128528', isValid:false},
387+
{val:input('', {'use-hyphen' : 'true', '':'swesec'}), isValid:false},
388+
{val:input('198301128529', {'use-hyphen' : 'true', '':'swesec'}), isValid:false},
389+
{val:input('198311084936', {'use-hyphen' : 'true', '':'swesec'}), isValid:false},
390+
{val:input('19830112-8529', {'use-hyphen' : 'true', '':'swesec'}), isValid:true},
391+
{val:input('19831108-4936', {'use-hyphen' : 'true', '':'swesec'}), isValid:true}
392+
];
393+
394+
$.each(links, function(i, obj) {
395+
runTest(obj, 'swesec');
396+
});
397+
});
398+
373399
// TODO: Write more tests...
374400

375401
}

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* - validate_ukvatnumber
1010
*
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 1.9.35
12+
* @version 1.9.36
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'validate_ukvatnumber',

0 commit comments

Comments
 (0)