From 7a29dbc2ec9c42dc3d6653dc633373466bd5daaa Mon Sep 17 00:00:00 2001 From: Stephen Palmer Date: Fri, 4 Sep 2015 11:57:32 -0500 Subject: [PATCH 1/4] Added isPrivateIP validator, and an allow_private_hosts (default: true) option for isURL --- README.md | 3 +- test/validators.js | 104 +++++++++++++++++++++++++++++++++++++++++++++ validator.js | 29 +++++++++++++ validator.min.js | 2 +- 4 files changed, 136 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 771a5fca1..f5bcdf9cf 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ $ bower install validator-js - **isHexColor(str)** - check if the string is a hexadecimal color. - **isHexadecimal(str)** - check if the string is a hexadecimal number. - **isIP(str [, version])** - check if the string is an IP (version 4 or 6). +- **isPrivateIP(str [, version])** - check if the string is a private network IP (version 4 or 6) - **isISBN(str [, version])** - check if the string is an ISBN (version 10 or 13). - **isISIN(str)** - check if the string is an [ISIN][ISIN] (stock/security identifier). - **isISO8601(str)** - check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date. @@ -70,7 +71,7 @@ $ bower install validator-js - **isNull(str)** - check if the string is null. - **isNumeric(str)** - check if the string contains only numbers. - **isSurrogatePair(str)** - check if the string contains any surrogate pairs chars. -- **isURL(str [, options])** - check if the string is an URL. `options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false }`. +- **isURL(str [, options])** - check if the string is an URL. `options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_private_hosts: true }`. - **isUUID(str [, version])** - check if the string is a UUID (version 3, 4 or 5). - **isUppercase(str)** - check if the string is uppercase. - **isVariableWidth(str)** - check if the string contains a mixture of full and half-width chars. diff --git a/test/validators.js b/test/validators.js index 6590c766b..a427dbf5c 100644 --- a/test/validators.js +++ b/test/validators.js @@ -397,6 +397,28 @@ describe('Validators', function () { }); }); + it('should let users exclude private ip addresses', function() { + test({ + validator: 'isURL' + , args: [{ + allow_private_host: false + }] + , valid: [ + 'http://1.2.3.4' + , 'http://foo.bar.com/' + , 'http://qux.com' + ] + , invalid: [ + 'http://127.0.0.1/' + , 'http://192.168.0.1/' + , 'http://172.16.10.1/' + , 'http://10.0.0.1/' + , 'http://169.254.169.254/' + , 'http://localhost/' + ] + }); + }); + it('should validate IP addresses', function () { test({ validator: 'isIP' @@ -485,6 +507,88 @@ describe('Validators', function () { }); }); + it('should validate private IP addresses', function() { + test({ + validator: 'isPrivateIP' + , valid: [ + '127.0.0.1' + , '10.0.0.1' + , '172.16.8.1' + , '192.168.0.1' + , '169.254.169.254' + , '::' + , '::1' + , 'fe80::a6db:30ff:fe98:e946' + ] + , invalid: [ + 'abc' + , '256.0.0.0' + , '0.0.0.0' + , '1.2.3.4' + , '0.0.0.256' + , '26.0.0.256' + , '::banana' + , 'banana::' + , '::1banana' + , '::1::' + , '1:' + , ':1' + , ':1:1:1::2' + , '1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1' + , '::11111' + , '11111:1:1:1:1:1:1:1' + , '2001:db8:0000:1:1:1:1::1' + , '0:0:0:0:0:0:ffff:127.0.0.1' + , '0:0:0:0:ffff:127.0.0.1' + ] + }); + test({ + validator: 'isPrivateIP' + , args: [ 4 ] + , valid: [ + '127.0.0.1' + , '10.0.0.1' + , '172.16.8.1' + , '192.168.0.1' + + ] + , invalid: [ + '::' + , '::1' + , 'fe80::a6db:30ff:fe98:e946' + ] + }); + test({ + validator: 'isPrivateIP' + , args: [ 6 ] + , valid: [ + '::' + , '::1' + , 'fe80::a6db:30ff:fe98:e946' + ] + , invalid: [ + '127.0.0.1' + , '10.0.0.1' + , '172.16.8.1' + , '192.168.0.1' + ] + }); + test({ + validator: 'isPrivateIP' + , args: [ 10 ] + , valid: [ + ] + , invalid: [ + '127.0.0.1' + , '0.0.0.0' + , '255.255.255.255' + , '1.2.3.4' + , '::1' + , '2001:db8:0000:1:1:1:1:1' + ] + }); + }); + it('should validate FQDN', function () { test({ validator: 'isFQDN' diff --git a/validator.js b/validator.js index 81bcc65b4..4055024e1 100644 --- a/validator.js +++ b/validator.js @@ -227,6 +227,7 @@ , allow_underscores: false , allow_trailing_dot: false , allow_protocol_relative_urls: false + , allow_private_host: true }; validator.isURL = function (url, options) { @@ -280,6 +281,10 @@ host !== 'localhost') { return false; } + if(!options.allow_private_host && + (host === 'localhost' || validator.isPrivateIP(host))) { + return false; + } if (options.host_whitelist && options.host_whitelist.indexOf(host) === -1) { return false; @@ -353,6 +358,30 @@ } return false; }; + + validator.isPrivateIP = function (str, version) { + if(!validator.isIP(str, version)) { + return false; + } + + version = validator.toString(version); + + if(!version) { + return validator.isPrivateIP(str, 4) || validator.isPrivateIP(str, 6); + } + else if(version === '4') { + return /^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || + /^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || + /^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || + /^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || + /^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(str); + } + else if(version === '6') { + return /^fc00:/.test(str) || /^fe80:/.test(str) || + /^::1$/.test(str) || /^::$/.test(str); + } + return false; + }; var default_fqdn_options = { require_tld: true diff --git a/validator.min.js b/validator.min.js index bddbc3c1b..69268ab60 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],u="("+o.join("|")+")?",s="(\\"+t.decimal_separator+"\\d{2})?",a=u+s;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,o=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,u=/^([\s\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]))*$/i,s=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~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F]/,I=/^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i,O={"zh-CN":/^(\+?0?86\-?)?1[345789]\d{9}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-HK":/^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"pt-PT":/^(\+351)?9[1236]\d{7}$/,"el-GR":/^(\+30)?((2\d{9})|(69\d{8}))$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-US":/^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,"en-ZM":/^(\+26)?09[567]\d{7}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/},C=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var S={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,S),a.allow_display_name){var l=r.match(s);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if(("gmail.com"===g||"googlemail.com"===g)&&(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?u.test(p):i.test(p);for(var F=a.allow_utf8_local_part?o:n,d=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,N);var i,o,u,s,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&-1===n.protocols.indexOf(i))return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2)?!1:(s=f.join("@"),f=s.split(":"),u=f.shift(),f.length&&(l=f.join(":"),a=parseInt(l,10),!/^[0-9]+$/.test(l)||0>=a||a>65535)?!1:t.isIP(u)||t.isFQDN(u,n)||"localhost"===u?n.host_whitelist&&-1===n.host_whitelist.indexOf(u)?!1:n.host_blacklist&&-1!==n.host_blacklist.indexOf(u)?!1:!0:!1)},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,u=t.isIP(i[i.length-1],4),s=u?7:8;if(i.length>s)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===s}return!1};var B={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,B),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,u=0;u=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return d.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return m.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||r>=i)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||r>=n)},t.isUUID=function(t,e){var r=F[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&n>i},t.isIn=function(e,r){var n;if("[object Array]"===Object.prototype.toString.call(r)){var i=[];for(n in r)i[n]=t.toString(r[n]);return i.indexOf(e)>=0}return"object"==typeof r?r.hasOwnProperty(e):r&&"function"==typeof r.indexOf?r.indexOf(e)>=0:!1},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,u=e.length-1;u>=0;u--)r=e.substring(u,u+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!!(o%10===0?e:!1)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,u=n.length-2;u>=0;u--)e=n.substring(u,u+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;9>n;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var u=[1,3];for(n=0;12>n;n++)o+=u[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O?O[e].test(t):!1};var j={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,j),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(r){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return w.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return E.test(t)},t.isBase64=function(t){return I.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return C.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var q={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,q),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); +!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],s="("+o.join("|")+")?",u="(\\"+t.decimal_separator+"\\d{2})?",a=s+u;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,o=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,s=/^([\s\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]))*$/i,u=/^[a-z\d!#\$%&'\*\+\-\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u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/,I=/[\uD800-\uDBFF][\uDC00-\uDFFF]/,E=/^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i,O={"zh-CN":/^(\+?0?86\-?)?1[345789]\d{9}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-HK":/^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"pt-PT":/^(\+351)?9[1236]\d{7}$/,"el-GR":/^(\+30)?((2\d{9})|(69\d{8}))$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-US":/^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,"en-ZM":/^(\+26)?09[567]\d{7}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/},S=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var C={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,C),a.allow_display_name){var l=r.match(u);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if(("gmail.com"===g||"googlemail.com"===g)&&(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?s.test(p):i.test(p);for(var F=a.allow_utf8_local_part?o:n,d=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,P);var i,o,s,u,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&-1===n.protocols.indexOf(i))return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2)?!1:(u=f.join("@"),f=u.split(":"),s=f.shift(),f.length&&(l=f.join(":"),a=parseInt(l,10),!/^[0-9]+$/.test(l)||0>=a||a>65535)?!1:(t.isIP(s)||t.isFQDN(s,n)||"localhost"===s)&&(n.allow_private_host||"localhost"!==s&&!t.isPrivateIP(s))?n.host_whitelist&&-1===n.host_whitelist.indexOf(s)?!1:n.host_blacklist&&-1!==n.host_blacklist.indexOf(s)?!1:!0:!1)},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,s=t.isIP(i[i.length-1],4),u=s?7:8;if(i.length>u)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===u}return!1},t.isPrivateIP=function(e,r){return t.isIP(e,r)?(r=t.toString(r),r?"4"===r?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(e):"6"===r?/^fc00:/.test(e)||/^fe80:/.test(e)||/^::1$/.test(e)||/^::$/.test(e):!1:t.isPrivateIP(e,4)||t.isPrivateIP(e,6)):!1};var N={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,N),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,s=0;s=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return d.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return w.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||r>=i)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||r>=n)},t.isUUID=function(t,e){var r=F[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&n>i},t.isIn=function(e,r){var n;if("[object Array]"===Object.prototype.toString.call(r)){var i=[];for(n in r)i[n]=t.toString(r[n]);return i.indexOf(e)>=0}return"object"==typeof r?r.hasOwnProperty(e):r&&"function"==typeof r.indexOf?r.indexOf(e)>=0:!1},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;s>=0;s--)r=e.substring(s,s+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!!(o%10===0?e:!1)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,s=n.length-2;s>=0;s--)e=n.substring(s,s+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;9>n;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var s=[1,3];for(n=0;12>n;n++)o+=s[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O?O[e].test(t):!1};var B={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,B),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(r){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return m.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return I.test(t)},t.isBase64=function(t){return E.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return S.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var j={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,j),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); From c377dd3a40486244ce2bec3e10aae8d62c6a75c6 Mon Sep 17 00:00:00 2001 From: Stephen Palmer Date: Sat, 5 Sep 2015 21:52:43 -0500 Subject: [PATCH 2/4] Add option require_valid_port (default: true) to allow skipping the port validation. Useful to allow git@host:path style URLs to validate. --- README.md | 2 +- test/validators.js | 13 +++++++++++++ validator.js | 3 ++- validator.min.js | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f5bcdf9cf..1ba5d69c8 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ $ bower install validator-js - **isNull(str)** - check if the string is null. - **isNumeric(str)** - check if the string contains only numbers. - **isSurrogatePair(str)** - check if the string contains any surrogate pairs chars. -- **isURL(str [, options])** - check if the string is an URL. `options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_private_hosts: true }`. +- **isURL(str [, options])** - check if the string is an URL. `options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, allow_private_hosts: true, require_valid_port: true }`. - **isUUID(str [, version])** - check if the string is a UUID (version 3, 4 or 5). - **isUppercase(str)** - check if the string is uppercase. - **isVariableWidth(str)** - check if the string contains a mixture of full and half-width chars. diff --git a/test/validators.js b/test/validators.js index a427dbf5c..a8e6bc3cd 100644 --- a/test/validators.js +++ b/test/validators.js @@ -419,6 +419,19 @@ describe('Validators', function () { }); }); + it('should let users specify if invalid ports are allowed', function() { + test({ + validator: 'isURL' + , args: [{ + require_valid_port: false + }] + , valid: [ + 'git@github.com:foo/bar.git', + 'http://www.foobar.com:999999999/' + ] + }); + }); + it('should validate IP addresses', function () { test({ validator: 'isIP' diff --git a/validator.js b/validator.js index 4055024e1..02fa15831 100644 --- a/validator.js +++ b/validator.js @@ -228,6 +228,7 @@ , allow_trailing_dot: false , allow_protocol_relative_urls: false , allow_private_host: true + , require_valid_port: true }; validator.isURL = function (url, options) { @@ -273,7 +274,7 @@ if (split.length) { port_str = split.join(':'); port = parseInt(port_str, 10); - if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) { + if (options.require_valid_port && (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535)) { return false; } } diff --git a/validator.min.js b/validator.min.js index 69268ab60..971e37761 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],s="("+o.join("|")+")?",u="(\\"+t.decimal_separator+"\\d{2})?",a=s+u;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,o=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,s=/^([\s\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]))*$/i,u=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i,a=/^(?:4[0-9]{12}(?:[0-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/]{4})$/i,O={"zh-CN":/^(\+?0?86\-?)?1[345789]\d{9}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-HK":/^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"pt-PT":/^(\+351)?9[1236]\d{7}$/,"el-GR":/^(\+30)?((2\d{9})|(69\d{8}))$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-US":/^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,"en-ZM":/^(\+26)?09[567]\d{7}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/},S=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var C={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,C),a.allow_display_name){var l=r.match(u);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if(("gmail.com"===g||"googlemail.com"===g)&&(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?s.test(p):i.test(p);for(var F=a.allow_utf8_local_part?o:n,d=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,P);var i,o,s,u,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&-1===n.protocols.indexOf(i))return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2)?!1:(u=f.join("@"),f=u.split(":"),s=f.shift(),f.length&&(l=f.join(":"),a=parseInt(l,10),!/^[0-9]+$/.test(l)||0>=a||a>65535)?!1:(t.isIP(s)||t.isFQDN(s,n)||"localhost"===s)&&(n.allow_private_host||"localhost"!==s&&!t.isPrivateIP(s))?n.host_whitelist&&-1===n.host_whitelist.indexOf(s)?!1:n.host_blacklist&&-1!==n.host_blacklist.indexOf(s)?!1:!0:!1)},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,s=t.isIP(i[i.length-1],4),u=s?7:8;if(i.length>u)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===u}return!1},t.isPrivateIP=function(e,r){return t.isIP(e,r)?(r=t.toString(r),r?"4"===r?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(e):"6"===r?/^fc00:/.test(e)||/^fe80:/.test(e)||/^::1$/.test(e)||/^::$/.test(e):!1:t.isPrivateIP(e,4)||t.isPrivateIP(e,6)):!1};var N={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,N),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,s=0;s=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return d.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return w.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||r>=i)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||r>=n)},t.isUUID=function(t,e){var r=F[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&n>i},t.isIn=function(e,r){var n;if("[object Array]"===Object.prototype.toString.call(r)){var i=[];for(n in r)i[n]=t.toString(r[n]);return i.indexOf(e)>=0}return"object"==typeof r?r.hasOwnProperty(e):r&&"function"==typeof r.indexOf?r.indexOf(e)>=0:!1},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;s>=0;s--)r=e.substring(s,s+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!!(o%10===0?e:!1)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,s=n.length-2;s>=0;s--)e=n.substring(s,s+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;9>n;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var s=[1,3];for(n=0;12>n;n++)o+=s[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O?O[e].test(t):!1};var B={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,B),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(r){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return m.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return I.test(t)},t.isBase64=function(t){return E.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return S.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var j={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,j),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); +!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],s="("+o.join("|")+")?",u="(\\"+t.decimal_separator+"\\d{2})?",a=s+u;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\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\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var C={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,C),a.allow_display_name){var l=r.match(u);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if(("gmail.com"===g||"googlemail.com"===g)&&(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?s.test(p):i.test(p);for(var d=a.allow_utf8_local_part?o:n,F=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,P);var i,o,s,u,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&-1===n.protocols.indexOf(i))return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2)?!1:(u=f.join("@"),f=u.split(":"),s=f.shift(),f.length&&(l=f.join(":"),a=parseInt(l,10),n.require_valid_port&&(!/^[0-9]+$/.test(l)||0>=a||a>65535))?!1:(t.isIP(s)||t.isFQDN(s,n)||"localhost"===s)&&(n.allow_private_host||"localhost"!==s&&!t.isPrivateIP(s))?n.host_whitelist&&-1===n.host_whitelist.indexOf(s)?!1:n.host_blacklist&&-1!==n.host_blacklist.indexOf(s)?!1:!0:!1)},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,s=t.isIP(i[i.length-1],4),u=s?7:8;if(i.length>u)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===u}return!1},t.isPrivateIP=function(e,r){return t.isIP(e,r)?(r=t.toString(r),r?"4"===r?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(e):"6"===r?/^fc00:/.test(e)||/^fe80:/.test(e)||/^::1$/.test(e)||/^::$/.test(e):!1:t.isPrivateIP(e,4)||t.isPrivateIP(e,6)):!1};var N={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,N),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,s=0;s=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return F.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return w.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||r>=i)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||r>=n)},t.isUUID=function(t,e){var r=d[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&n>i},t.isIn=function(e,r){var n;if("[object Array]"===Object.prototype.toString.call(r)){var i=[];for(n in r)i[n]=t.toString(r[n]);return i.indexOf(e)>=0}return"object"==typeof r?r.hasOwnProperty(e):r&&"function"==typeof r.indexOf?r.indexOf(e)>=0:!1},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;s>=0;s--)r=e.substring(s,s+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!!(o%10===0?e:!1)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,s=n.length-2;s>=0;s--)e=n.substring(s,s+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;9>n;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var s=[1,3];for(n=0;12>n;n++)o+=s[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O?O[e].test(t):!1};var B={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,B),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(r){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return m.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return I.test(t)},t.isBase64=function(t){return E.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return S.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var j={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,j),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); From f8346396f160c39258a10c4f85c56bcb260a0487 Mon Sep 17 00:00:00 2001 From: Danny Dyer Date: Tue, 19 Jul 2016 11:10:15 -0500 Subject: [PATCH 3/4] treat 0.0.0.0 as a private ip --- test/validators.js | 4 +++- validator.js | 3 ++- validator.min.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/validators.js b/test/validators.js index a8e6bc3cd..eec1904e7 100644 --- a/test/validators.js +++ b/test/validators.js @@ -414,6 +414,8 @@ describe('Validators', function () { , 'http://172.16.10.1/' , 'http://10.0.0.1/' , 'http://169.254.169.254/' + , 'http://0.0.0.0/' + , 'http://0.00.000.000/' , 'http://localhost/' ] }); @@ -525,6 +527,7 @@ describe('Validators', function () { validator: 'isPrivateIP' , valid: [ '127.0.0.1' + , '0.0.0.0' , '10.0.0.1' , '172.16.8.1' , '192.168.0.1' @@ -536,7 +539,6 @@ describe('Validators', function () { , invalid: [ 'abc' , '256.0.0.0' - , '0.0.0.0' , '1.2.3.4' , '0.0.0.256' , '26.0.0.256' diff --git a/validator.js b/validator.js index 02fa15831..f5a04e467 100644 --- a/validator.js +++ b/validator.js @@ -375,7 +375,8 @@ /^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || /^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || /^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || - /^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(str); + /^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(str) || + /^0{1,3}\.0{1,3}\.0{1,3}\.0{1,3}/.test(str); } else if(version === '6') { return /^fc00:/.test(str) || /^fe80:/.test(str) || diff --git a/validator.min.js b/validator.min.js index 971e37761..22a48c595 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],s="("+o.join("|")+")?",u="(\\"+t.decimal_separator+"\\d{2})?",a=s+u;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,o=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,s=/^([\s\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]))*$/i,u=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i,a=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])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\d{9}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-HK":/^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"pt-PT":/^(\+351)?9[1236]\d{7}$/,"el-GR":/^(\+30)?((2\d{9})|(69\d{8}))$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-US":/^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,"en-ZM":/^(\+26)?09[567]\d{7}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/},S=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var C={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,C),a.allow_display_name){var l=r.match(u);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if(("gmail.com"===g||"googlemail.com"===g)&&(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?s.test(p):i.test(p);for(var d=a.allow_utf8_local_part?o:n,F=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,P);var i,o,s,u,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&-1===n.protocols.indexOf(i))return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2)?!1:(u=f.join("@"),f=u.split(":"),s=f.shift(),f.length&&(l=f.join(":"),a=parseInt(l,10),n.require_valid_port&&(!/^[0-9]+$/.test(l)||0>=a||a>65535))?!1:(t.isIP(s)||t.isFQDN(s,n)||"localhost"===s)&&(n.allow_private_host||"localhost"!==s&&!t.isPrivateIP(s))?n.host_whitelist&&-1===n.host_whitelist.indexOf(s)?!1:n.host_blacklist&&-1!==n.host_blacklist.indexOf(s)?!1:!0:!1)},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,s=t.isIP(i[i.length-1],4),u=s?7:8;if(i.length>u)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===u}return!1},t.isPrivateIP=function(e,r){return t.isIP(e,r)?(r=t.toString(r),r?"4"===r?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(e):"6"===r?/^fc00:/.test(e)||/^fe80:/.test(e)||/^::1$/.test(e)||/^::$/.test(e):!1:t.isPrivateIP(e,4)||t.isPrivateIP(e,6)):!1};var N={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,N),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,s=0;s=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return F.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return w.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||r>=i)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||r>=n)},t.isUUID=function(t,e){var r=d[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&n>i},t.isIn=function(e,r){var n;if("[object Array]"===Object.prototype.toString.call(r)){var i=[];for(n in r)i[n]=t.toString(r[n]);return i.indexOf(e)>=0}return"object"==typeof r?r.hasOwnProperty(e):r&&"function"==typeof r.indexOf?r.indexOf(e)>=0:!1},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;s>=0;s--)r=e.substring(s,s+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!!(o%10===0?e:!1)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,s=n.length-2;s>=0;s--)e=n.substring(s,s+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;9>n;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var s=[1,3];for(n=0;12>n;n++)o+=s[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O?O[e].test(t):!1};var B={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,B),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(r){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return m.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return I.test(t)},t.isBase64=function(t){return E.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return S.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var j={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,j),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); +!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],s="("+o.join("|")+")?",u="(\\"+t.decimal_separator+"\\d{2})?",a=s+u;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\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\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var C={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,C),a.allow_display_name){var l=r.match(u);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if("gmail.com"!==g&&"googlemail.com"!==g||(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?s.test(p):i.test(p);for(var d=a.allow_utf8_local_part?o:n,F=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,P);var i,o,s,u,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&n.protocols.indexOf(i)===-1)return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),!(f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2))&&(u=f.join("@"),f=u.split(":"),s=f.shift(),!(f.length&&(l=f.join(":"),a=parseInt(l,10),n.require_valid_port&&(!/^[0-9]+$/.test(l)||a<=0||a>65535)))&&(!(!t.isIP(s)&&!t.isFQDN(s,n)&&"localhost"!==s)&&(!(!n.allow_private_host&&("localhost"===s||t.isPrivateIP(s)))&&((!n.host_whitelist||n.host_whitelist.indexOf(s)!==-1)&&(!n.host_blacklist||n.host_blacklist.indexOf(s)===-1)))))},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,s=t.isIP(i[i.length-1],4),u=s?7:8;if(i.length>u)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===u}return!1},t.isPrivateIP=function(e,r){return!!t.isIP(e,r)&&(r=t.toString(r),r?"4"===r?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^0{1,3}\.0{1,3}\.0{1,3}\.0{1,3}/.test(e):"6"===r&&(/^fc00:/.test(e)||/^fe80:/.test(e)||/^::1$/.test(e)||/^::$/.test(e)):t.isPrivateIP(e,4)||t.isPrivateIP(e,6))};var N={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,N),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,s=0;s=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return F.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return w.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||i<=r)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||n<=r)},t.isUUID=function(t,e){var r=d[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&i=0}return"object"==typeof r?r.hasOwnProperty(e):!(!r||"function"!=typeof r.indexOf)&&r.indexOf(e)>=0},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;s>=0;s--)r=e.substring(s,s+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!(o%10!==0||!e)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,s=n.length-2;s>=0;s--)e=n.substring(s,s+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;n<9;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var s=[1,3];for(n=0;n<12;n++)o+=s[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O&&O[e].test(t)};var B={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,B),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(t){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return m.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return I.test(t)},t.isBase64=function(t){return E.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return S.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var j={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,j),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); From 43643683ceb9365b7717bfbf11e5e2609f00caf0 Mon Sep 17 00:00:00 2001 From: Branwen Evans Date: Mon, 12 Aug 2019 11:58:33 -0500 Subject: [PATCH 4/4] Bugfix/auth segment (#4) * allow domain in auth username segment * added unit test --- test/validators.js | 12 ++++++++++++ validator.js | 7 +++++++ validator.min.js | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/validators.js b/test/validators.js index eec1904e7..a6a300b4d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -421,6 +421,18 @@ describe('Validators', function () { }); }); + it('should let users specify if domains are allowed in auth username segment', function() { + test({ + validator: 'isURL' + , args: [{ + allow_auth_user_domain: true + }] + , valid: [ + 'http://user@domain.com:pass@www.foobar.com/' + ] + }); + }); + it('should let users specify if invalid ports are allowed', function() { test({ validator: 'isURL' diff --git a/validator.js b/validator.js index f5a04e467..f2233d367 100644 --- a/validator.js +++ b/validator.js @@ -229,6 +229,7 @@ , allow_protocol_relative_urls: false , allow_private_host: true , require_valid_port: true + , allow_auth_user_domain: false }; validator.isURL = function (url, options) { @@ -264,6 +265,12 @@ split = url.split('@'); if (split.length > 1) { auth = split.shift(); + if (options.allow_auth_user_domain) { + while (split.length > 1) { + // auth segment continues until last '@' + auth += '@' + split.shift(); + } + } if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) { return false; } diff --git a/validator.min.js b/validator.min.js index 22a48c595..dd07c65bc 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this[t]=e()}("validator",function(t){"use strict";function e(t,e){t=t||{};for(var r in e)"undefined"==typeof t[r]&&(t[r]=e[r]);return t}function r(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="-?",n="[1-9]\\d*",i="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",o=["0",n,i],s="("+o.join("|")+")?",u="(\\"+t.decimal_separator+"\\d{2})?",a=s+u;return t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?a+=r:t.negative_sign_before_digits&&(a=r+a)),t.allow_negative_sign_placeholder?a="( (?!\\-))?"+a:t.allow_space_after_symbol?a=" ?"+a:t.allow_space_after_digits&&(a+="( (?!$))?"),t.symbol_after_digits?a+=e:a=e+a,t.allow_negatives&&(t.parens_for_negatives?a="(\\("+a+"\\)|"+a+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(a=r+a)),new RegExp("^(?!-? )(?=.*\\d)"+a+"$")}t={version:"4.0.5"};var n=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,i=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,o=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,s=/^([\s\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]))*$/i,u=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i,a=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/,l=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/,f=/^(?:[0-9]{9}X|[0-9]{10})$/,c=/^(?:[0-9]{13})$/,p=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/,g=/^[0-9A-F]{1,4}$/i,d={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A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?[2-9]\d{2}[2-9](?!11)\d{6}$/,"en-ZM":/^(\+26)?09[567]\d{7}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/},S=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;t.extend=function(e,r){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),r.apply(t,e)}},t.init=function(){for(var e in t)"function"==typeof t[e]&&"toString"!==e&&"toDate"!==e&&"extend"!==e&&"init"!==e&&t.extend(e,t[e])},t.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null===t||"undefined"==typeof t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},t.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},t.toFloat=function(t){return parseFloat(t)},t.toInt=function(t,e){return parseInt(t,e||10)},t.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},t.equals=function(e,r){return e===t.toString(r)},t.contains=function(e,r){return e.indexOf(t.toString(r))>=0},t.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)};var C={allow_display_name:!1,allow_utf8_local_part:!0,require_tld:!0};t.isEmail=function(r,a){if(a=e(a,C),a.allow_display_name){var l=r.match(u);l&&(r=l[1])}var f=r.split("@"),c=f.pop(),p=f.join("@"),g=c.toLowerCase();if("gmail.com"!==g&&"googlemail.com"!==g||(p=p.replace(/\./g,"").toLowerCase()),!t.isByteLength(p,0,64)||!t.isByteLength(c,0,256))return!1;if(!t.isFQDN(c,{require_tld:a.require_tld}))return!1;if('"'===p[0])return p=p.slice(1,p.length-1),a.allow_utf8_local_part?s.test(p):i.test(p);for(var d=a.allow_utf8_local_part?o:n,F=p.split("."),_=0;_=2083||/\s/.test(r))return!1;if(0===r.indexOf("mailto:"))return!1;n=e(n,P);var i,o,s,u,a,l,f;if(f=r.split("://"),f.length>1){if(i=f.shift(),n.require_valid_protocol&&n.protocols.indexOf(i)===-1)return!1}else{if(n.require_protocol)return!1;n.allow_protocol_relative_urls&&"//"===r.substr(0,2)&&(f[0]=r.substr(2))}return r=f.join("://"),f=r.split("#"),r=f.shift(),f=r.split("?"),r=f.shift(),f=r.split("/"),r=f.shift(),f=r.split("@"),!(f.length>1&&(o=f.shift(),o.indexOf(":")>=0&&o.split(":").length>2))&&(u=f.join("@"),f=u.split(":"),s=f.shift(),!(f.length&&(l=f.join(":"),a=parseInt(l,10),n.require_valid_port&&(!/^[0-9]+$/.test(l)||a<=0||a>65535)))&&(!(!t.isIP(s)&&!t.isFQDN(s,n)&&"localhost"!==s)&&(!(!n.allow_private_host&&("localhost"===s||t.isPrivateIP(s)))&&((!n.host_whitelist||n.host_whitelist.indexOf(s)!==-1)&&(!n.host_blacklist||n.host_blacklist.indexOf(s)===-1)))))},t.isIP=function(e,r){if(r=t.toString(r),!r)return t.isIP(e,4)||t.isIP(e,6);if("4"===r){if(!p.test(e))return!1;var n=e.split(".").sort(function(t,e){return t-e});return n[3]<=255}if("6"===r){var i=e.split(":"),o=!1,s=t.isIP(i[i.length-1],4),u=s?7:8;if(i.length>u)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(i.shift(),i.shift(),o=!0):"::"===e.substr(e.length-2)&&(i.pop(),i.pop(),o=!0);for(var a=0;a0&&a=1:i.length===u}return!1},t.isPrivateIP=function(e,r){return!!t.isIP(e,r)&&(r=t.toString(r),r?"4"===r?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(e)||/^0{1,3}\.0{1,3}\.0{1,3}\.0{1,3}/.test(e):"6"===r&&(/^fc00:/.test(e)||/^fe80:/.test(e)||/^::1$/.test(e)||/^::$/.test(e)):t.isPrivateIP(e,4)||t.isPrivateIP(e,6))};var N={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,r){r=e(r,N),r.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var n=t.split(".");if(r.require_tld){var i=n.pop();if(!n.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(i))return!1}for(var o,s=0;s=0)return!1;o=o.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(o))return!1;if(/[\uff01-\uff5e]/.test(o))return!1;if("-"===o[0]||"-"===o[o.length-1]||o.indexOf("---")>=0)return!1}return!0},t.isBoolean=function(t){return["true","false","1","0"].indexOf(t)>=0},t.isAlpha=function(t){return F.test(t)},t.isAlphanumeric=function(t){return _.test(t)},t.isNumeric=function(t){return x.test(t)},t.isDecimal=function(t){return""!==t&&$.test(t)},t.isHexadecimal=function(t){return A.test(t)},t.isHexColor=function(t){return w.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t,e){return e=e||{},h.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isFloat=function(t,e){return e=e||{},""!==t&&v.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},t.isDivisibleBy=function(e,r){return t.toFloat(e)%t.toInt(r)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return i>=e&&("undefined"==typeof r||i<=r)},t.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return n>=e&&("undefined"==typeof r||n<=r)},t.isUUID=function(t,e){var r=d[e?e:"all"];return r&&r.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return!!(i&&n&&i>n)},t.isBefore=function(e,r){var n=t.toDate(r||new Date),i=t.toDate(e);return i&&n&&i=0}return"object"==typeof r?r.hasOwnProperty(e):!(!r||"function"!=typeof r.indexOf)&&r.indexOf(e)>=0},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!a.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;s>=0;s--)r=e.substring(s,s+1),n=parseInt(r,10),i?(n*=2,o+=n>=10?n%10+1:n):o+=n,i=!i;return!(o%10!==0||!e)},t.isISIN=function(t){if(!l.test(t))return!1;for(var e,r,n=t.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),i=0,o=!0,s=n.length-2;s>=0;s--)e=n.substring(s,s+1),r=parseInt(e,10),o?(r*=2,i+=r>=10?r+1:r):i+=r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},t.isISBN=function(e,r){if(r=t.toString(r),!r)return t.isISBN(e,10)||t.isISBN(e,13);var n,i=e.replace(/[\s-]+/g,""),o=0;if("10"===r){if(!f.test(i))return!1;for(n=0;n<9;n++)o+=(n+1)*i.charAt(n);if(o+="X"===i.charAt(9)?100:10*i.charAt(9),o%11===0)return!!i}else if("13"===r){if(!c.test(i))return!1;var s=[1,3];for(n=0;n<12;n++)o+=s[n%2]*i.charAt(n);if(i.charAt(12)-(10-o%10)%10===0)return!!i}return!1},t.isMobilePhone=function(t,e){return e in O&&O[e].test(t)};var B={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_space_after_digits:!1};t.isCurrency=function(t,n){return n=e(n,B),r(n).test(t)},t.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(t){}return!1},t.isMultibyte=function(t){return b.test(t)},t.isAscii=function(t){return m.test(t)},t.isFullWidth=function(t){return D.test(t)},t.isHalfWidth=function(t){return y.test(t)},t.isVariableWidth=function(t){return D.test(t)&&y.test(t)},t.isSurrogatePair=function(t){return I.test(t)},t.isBase64=function(t){return E.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},t.isISO8601=function(t){return S.test(t)},t.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},t.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},t.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\`/g,"`")},t.stripLow=function(e,r){var n=r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return t.blacklist(e,n)},t.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},t.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var j={lowercase:!0};return t.normalizeEmail=function(r,n){if(n=e(n,j),!t.isEmail(r))return!1;var i=r.split("@",2);if(i[1]=i[1].toLowerCase(),"gmail.com"===i[1]||"googlemail.com"===i[1]){if(i[0]=i[0].toLowerCase().replace(/\./g,""),"+"===i[0][0])return!1;i[0]=i[0].split("+")[0],i[1]="gmail.com"}else n.lowercase&&(i[0]=i[0].toLowerCase());return i.join("@")},t.init(),t}); +!function(t,e){"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&"object"==typeof define.amd?define(e):this.validator=e()}(0,function(f){"use strict";var c=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,p=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,g=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,F=/^([\s\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]))*$/i,d=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i,u=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/,a=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/,s=/^(?:[0-9]{9}X|[0-9]{10})$/,l=/^(?:[0-9]{13})$/,_=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/,h=/^[0-9A-F]{1,4}$/i,n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9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?09[567]\d{7}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/},O=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;(f={version:"4.0.5"}).extend=function(t,e){f[t]=function(){var t=Array.prototype.slice.call(arguments);return t[0]=f.toString(t[0]),e.apply(f,t)}},f.init=function(){for(var t in f)"function"==typeof f[t]&&"toString"!==t&&"toDate"!==t&&"extend"!==t&&"init"!==t&&f.extend(t,f[t])},f.toString=function(t){return"object"==typeof t&&null!==t&&t.toString?t=t.toString():null==t||isNaN(t)&&!t.length?t="":"string"!=typeof t&&(t+=""),t},f.toDate=function(t){return"[object Date]"===Object.prototype.toString.call(t)?t:(t=Date.parse(t),isNaN(t)?null:new Date(t))},f.toFloat=function(t){return parseFloat(t)},f.toInt=function(t,e){return parseInt(t,e||10)},f.toBoolean=function(t,e){return e?"1"===t||"true"===t:"0"!==t&&"false"!==t&&""!==t},f.equals=function(t,e){return t===f.toString(e)},f.contains=function(t,e){return 0<=t.indexOf(f.toString(e))};var S={allow_display_name:!(f.matches=function(t,e,r){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,r)),e.test(t)}),allow_utf8_local_part:!0,require_tld:!0},C={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!(f.isEmail=function(t,e){if((e=j(e,S)).allow_display_name){var r=t.match(d);r&&(t=r[1])}var n=t.split("@"),i=n.pop(),o=n.join("@"),s=i.toLowerCase();if("gmail.com"!==s&&"googlemail.com"!==s||(o=o.replace(/\./g,"").toLowerCase()),!f.isByteLength(o,0,64)||!f.isByteLength(i,0,256))return!1;if(!f.isFQDN(i,{require_tld:e.require_tld}))return!1;if('"'===o[0])return o=o.slice(1,o.length-1),e.allow_utf8_local_part?F.test(o):p.test(o);for(var u=e.allow_utf8_local_part?g:c,a=o.split("."),l=0;lo)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(r.shift(),r.shift(),n=!0):"::"===t.substr(t.length-2)&&(r.pop(),r.pop(),n=!0);for(var s=0;s=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},f.isFloat=function(t,e){return e=e||{},""!==t&&x.test(t)&&(!e.hasOwnProperty("min")||t>=e.min)&&(!e.hasOwnProperty("max")||t<=e.max)},f.isDivisibleBy=function(t,e){return f.toFloat(t)%f.toInt(e)==0},f.isNull=function(t){return 0===t.length},f.isLength=function(t,e,r){var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return e<=i&&(void 0===r||i<=r)},f.isByteLength=function(t,e,r){var n=encodeURI(t).split(/%..|./).length-1;return e<=n&&(void 0===r||n<=r)},f.isUUID=function(t,e){var r=n[e||"all"];return r&&r.test(t)},f.isDate=function(t){return!isNaN(Date.parse(t))},f.isAfter=function(t,e){var r=f.toDate(e||new Date),n=f.toDate(t);return!!(n&&r&&r/g,">").replace(/\//g,"/").replace(/\`/g,"`")},f.stripLow=function(t,e){var r=e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";return f.blacklist(t,r)},f.whitelist=function(t,e){return t.replace(new RegExp("[^"+e+"]+","g"),"")},f.blacklist=function(t,e){return t.replace(new RegExp("["+e+"]+","g"),"")};var B={lowercase:!0};function j(t,e){for(var r in t=t||{},e)void 0===t[r]&&(t[r]=e[r]);return t}return f.normalizeEmail=function(t,e){if(e=j(e,B),!f.isEmail(t))return!1;var r=t.split("@",2);if(r[1]=r[1].toLowerCase(),"gmail.com"===r[1]||"googlemail.com"===r[1]){if(r[0]=r[0].toLowerCase().replace(/\./g,""),"+"===r[0][0])return!1;r[0]=r[0].split("+")[0],r[1]="gmail.com"}else e.lowercase&&(r[0]=r[0].toLowerCase());return r.join("@")},f.init(),f});