Coverage

100%
77
77
0

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/affirmative.js

100%
4
4
0
LineHitsSource
11'use strict';
2
3// ----- affirmative
4// ---------------------------------------
51module.exports = function(str) {
6
727 var regex = /^(?:1|t(?:rue)?|y(?:es)?|on|ok(?:ay)?)$/;
8
927 return regex.test(str.toLowerCase());
10
11};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/alpha.js

100%
4
4
0
LineHitsSource
11'use strict';
2
3// ----- alphabetic
4// ---------------------------------------
51module.exports = function(str) {
6
719 var regex = /^[a-z]+$/i;
8
919 return regex.test(str.toLowerCase());
10
11};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/alphaNumeric.js

100%
4
4
0
LineHitsSource
11'use strict';
2
3// ----- alphanumeric
4// ---------------------------------------
51module.exports = function(str) {
6
717 var regex = /^[a-z0-9]+$/i;
8
917 return regex.test(str.toLowerCase());
10
11};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/card.js

100%
5
5
0
LineHitsSource
11'use strict';
2
3// -------------- credit card methods --------------
4
5// ----- credit card check constructor
6// ---------------------------------------
71function CreditCard(regex) {
8
911 return function(str) {
10
1162 return regex.test(str.toLowerCase());
12
13 };
14
15}
16
17
18// ----- specific card regexp validation
19// ---------------------------------------
201module.exports = {
21 visa: new CreditCard(/^4[0-9]{12}(?:[0-9]{3})?$/),
22 mastercard: new CreditCard(/^5[1-5][0-9]{14}$/),
23 amex: new CreditCard(/^3[47][0-9]{13}$/),
24 carteBlanche: new CreditCard(/^389[0-9]{11}$|^380[0-9]{11}$/),
25 dinersClub: new CreditCard(/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/),
26 discover: new CreditCard(/^65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$/),
27 jcb: new CreditCard(/^(?:2131|1800|35\d{3})\d{11}$/),
28 lasercard: new CreditCard(/^(6304|6706|6709|6771)[0-9]{12,15}$/),
29 maestro: new CreditCard(/^(5018|5020|5038|6304|6759|6761|6763|6799)[0-9]{8,19}$/),
30 solo: new CreditCard(/^(6334|6767)[0-9]{12}|(6334|6767)[0-9]{14}|(6334|6767)[0-9]{15}$|^(4903|4905|4911|4936|6333|6759)[0-9]{12}|(4903|4905|4911|4936|6333|6759)[0-9]{14}|(4903|4905|4911|4936|6333|6759)[0-9]{15}|564182[0-9]{10}|564182[0-9]{12}|564182[0-9]{13}|633110[0-9]{10}|633110[0-9]{12}|633110[0-9]{13}$/),
31 unionpay: new CreditCard(/^(62[0-9]{14,17})$/)
32};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/creditCard.js

100%
14
14
0
LineHitsSource
11'use strict';
2
3// ----- generic card validation
4// -- 1. input must be a string
5// -- 2. input length must be valid
6// -- 3. perform check based on number
7// ---------------------------------------
81module.exports = function(str) {
9
10 // [1] throws here if not a string
1160 str = str.toLowerCase();
12
13 // [2] must be valid card length
1458 if (str.length < 13 || str.length > 19) {
154 return false;
16 }
17
18 // [3] method of testing credit cards from
19 // http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js
2054 var testNumber = 0;
21
2254 for (var i = str.length - 1, current, currentInteger = 0, even = false; i>=0; i--) {
23
24846 current = str.charAt(i);
25846 currentInteger = parseInt(current, 10);
26
27846 if (even && (currentInteger *= 2) > 9 ) {
28102 currentInteger -= 9;
29 }
30
31846 testNumber += currentInteger;
32846 even = !even;
33 }
34
3554 return (testNumber % 10) === 0;
36
37};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/email.js

100%
4
4
0
LineHitsSource
11'use strict';
2
3// ----- email
4// ---------------------------------------
51module.exports = function(str) {
6
713 var regex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
8
913 return regex.test(str.toLowerCase());
10
11};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/index.js

100%
13
13
0
LineHitsSource
11'use strict';
2
31var valid = module.exports = {};
4
51valid.affirmative = require('./affirmative.js');
61valid.alpha = require('./alpha.js');
71valid.alphaNumeric = require('./alphaNumeric.js');
81valid.card = require('./card.js');
91valid.creditCard = valid.card.generic = require('./creditCard.js');
101valid.email = require('./email.js');
111valid.negatory = require('./negatory.js');
121valid.numeric = require('./numeric.js');
131valid.url = require('./url.js');
141valid.value = require('./value.js');
151valid.zipCode = require('./zipCode.js');

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/negatory.js

100%
4
4
0
LineHitsSource
11'use strict';
2
3// ----- negatory
4// ---------------------------------------
51module.exports = function(str) {
6
721 var regex = /^(?:1|f(?:alse)?|n(?:o)?|off)$/;
8
921 return regex.test(str.toLowerCase());
10
11};
12

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/numeric.js

100%
6
6
0
LineHitsSource
11'use strict';
2
3// ----- numeric
4// ---------------------------------------
51module.exports = function(str) {
6
714 str = str.toLowerCase();
8
913 if (str === '') {
101 return false;
11 }
12
1312 return !isNaN(str); // http://stackoverflow.com/a/175787
14
15};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/url.js

100%
4
4
0
LineHitsSource
11'use strict';
2
3// ----- url
4// ---------------------------------------
51module.exports = function(str) {
6
723 var regex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/i;
8
923 return regex.test(str.toLowerCase());
10
11};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/value.js

100%
7
7
0
LineHitsSource
11'use strict';
2
3// ----- value
4// ---------------------------------------
51module.exports = function(str) {
6
727 str = str.toLowerCase().replace(',', '');
8
926 var numbers = ['0','1','2','3','4','5','6','7','8','9', '-'];
10
11 // for $100 and #123, etc.
1226 if (numbers.indexOf(str[0]) === -1) {
1312 str = str.slice(1);
14 }
15
1626 return !isNaN(parseInt(str), 10);
17
18};

/Users/sebastiansandqvist/Documents/Sites & Projects/apps/modules/s-valid/zipCode.js

100%
8
8
0
LineHitsSource
11'use strict';
2
3// ----- zip code
4// -- 1. input must be a string
5// -- 2. check number
6// -- 3. perform regex test
7// ---------------------------------------
81module.exports = function(str) {
9
10 // [1] throws here if not a string
1119 str = str.toLowerCase();
12
13 // [2] every zip code begins with a number, and none are < 00501
1418 var numeric = parseInt(str, 10);
15
1618 if (isNaN(numeric) || numeric < 501) {
176 return false;
18 }
19
20 // [3]
2112 var regex = /^\d{5}(-\d{4})?$/;
22
2312 return regex.test(str);
24
25};