Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- affirmative | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 27 | var regex = /^(?:1|t(?:rue)?|y(?:es)?|on|ok(?:ay)?)$/; |
8 | ||
9 | 27 | return regex.test(str.toLowerCase()); |
10 | ||
11 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- alphabetic | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 19 | var regex = /^[a-z]+$/i; |
8 | ||
9 | 19 | return regex.test(str.toLowerCase()); |
10 | ||
11 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- alphanumeric | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 17 | var regex = /^[a-z0-9]+$/i; |
8 | ||
9 | 17 | return regex.test(str.toLowerCase()); |
10 | ||
11 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // -------------- credit card methods -------------- | |
4 | ||
5 | // ----- credit card check constructor | |
6 | // --------------------------------------- | |
7 | 1 | function CreditCard(regex) { |
8 | ||
9 | 11 | return function(str) { |
10 | ||
11 | 62 | return regex.test(str.toLowerCase()); |
12 | ||
13 | }; | |
14 | ||
15 | } | |
16 | ||
17 | ||
18 | // ----- specific card regexp validation | |
19 | // --------------------------------------- | |
20 | 1 | module.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 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | '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 | // --------------------------------------- | |
8 | 1 | module.exports = function(str) { |
9 | ||
10 | // [1] throws here if not a string | |
11 | 60 | str = str.toLowerCase(); |
12 | ||
13 | // [2] must be valid card length | |
14 | 58 | if (str.length < 13 || str.length > 19) { |
15 | 4 | 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 | |
20 | 54 | var testNumber = 0; |
21 | ||
22 | 54 | for (var i = str.length - 1, current, currentInteger = 0, even = false; i>=0; i--) { |
23 | ||
24 | 846 | current = str.charAt(i); |
25 | 846 | currentInteger = parseInt(current, 10); |
26 | ||
27 | 846 | if (even && (currentInteger *= 2) > 9 ) { |
28 | 102 | currentInteger -= 9; |
29 | } | |
30 | ||
31 | 846 | testNumber += currentInteger; |
32 | 846 | even = !even; |
33 | } | |
34 | ||
35 | 54 | return (testNumber % 10) === 0; |
36 | ||
37 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | ||
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 13 | 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 | ||
9 | 13 | return regex.test(str.toLowerCase()); |
10 | ||
11 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | 1 | var valid = module.exports = {}; |
4 | ||
5 | 1 | valid.affirmative = require('./affirmative.js'); |
6 | 1 | valid.alpha = require('./alpha.js'); |
7 | 1 | valid.alphaNumeric = require('./alphaNumeric.js'); |
8 | 1 | valid.card = require('./card.js'); |
9 | 1 | valid.creditCard = valid.card.generic = require('./creditCard.js'); |
10 | 1 | valid.email = require('./email.js'); |
11 | 1 | valid.negatory = require('./negatory.js'); |
12 | 1 | valid.numeric = require('./numeric.js'); |
13 | 1 | valid.url = require('./url.js'); |
14 | 1 | valid.value = require('./value.js'); |
15 | 1 | valid.zipCode = require('./zipCode.js'); |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- negatory | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 21 | var regex = /^(?:1|f(?:alse)?|n(?:o)?|off)$/; |
8 | ||
9 | 21 | return regex.test(str.toLowerCase()); |
10 | ||
11 | }; | |
12 |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- numeric | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 14 | str = str.toLowerCase(); |
8 | ||
9 | 13 | if (str === '') { |
10 | 1 | return false; |
11 | } | |
12 | ||
13 | 12 | return !isNaN(str); // http://stackoverflow.com/a/175787 |
14 | ||
15 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- url | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 23 | 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 | ||
9 | 23 | return regex.test(str.toLowerCase()); |
10 | ||
11 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- value | |
4 | // --------------------------------------- | |
5 | 1 | module.exports = function(str) { |
6 | ||
7 | 27 | str = str.toLowerCase().replace(',', ''); |
8 | ||
9 | 26 | var numbers = ['0','1','2','3','4','5','6','7','8','9', '-']; |
10 | ||
11 | // for $100 and #123, etc. | |
12 | 26 | if (numbers.indexOf(str[0]) === -1) { |
13 | 12 | str = str.slice(1); |
14 | } | |
15 | ||
16 | 26 | return !isNaN(parseInt(str), 10); |
17 | ||
18 | }; |
Line | Hits | Source |
---|---|---|
1 | 1 | 'use strict'; |
2 | ||
3 | // ----- zip code | |
4 | // -- 1. input must be a string | |
5 | // -- 2. check number | |
6 | // -- 3. perform regex test | |
7 | // --------------------------------------- | |
8 | 1 | module.exports = function(str) { |
9 | ||
10 | // [1] throws here if not a string | |
11 | 19 | str = str.toLowerCase(); |
12 | ||
13 | // [2] every zip code begins with a number, and none are < 00501 | |
14 | 18 | var numeric = parseInt(str, 10); |
15 | ||
16 | 18 | if (isNaN(numeric) || numeric < 501) { |
17 | 6 | return false; |
18 | } | |
19 | ||
20 | // [3] | |
21 | 12 | var regex = /^\d{5}(-\d{4})?$/; |
22 | ||
23 | 12 | return regex.test(str); |
24 | ||
25 | }; |