diff --git a/validator.js b/validator.js index 519636ae2..8020443bf 100644 --- a/validator.js +++ b/validator.js @@ -149,37 +149,78 @@ , allow_underscores: false }; - validator.isURL = function (str, options) { - if (!str || str.length >= 2083) { + validator.isURL = function (url, options) { + if (!url || url.length >= 2083) { + return false; + } + if (url.indexOf('mailto:') === 0) { return false; } options = merge(options, default_url_options); - var ipv4_url_parts = [ - '(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' - , '(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}', - , '(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' - ]; - var protocol = '(?:(?:' + options.protocols.join('|') + ')://)' + (options.require_protocol ? '' : '?') - , auth = '(?:\\S+(?::\\S*)?@)?' - , ipv4 = '(?:' + ipv4_url_parts.join('') + ')' - , hostname = '(' + ipv4 + '|' + domain(options) + '|localhost)' - , port = '(\\d{1,5})' - , host = hostname + '(?::' + port + ')?' - , path_query_anchor = '(?:(?:/|\\?|#)[^\\s]*)?'; - var is_url = new RegExp('^(?!mailto:)' + protocol + auth + host + path_query_anchor + '$', 'i') - , match = str.match(is_url); - if (!match) { + var protocol, user, pass, auth, host, hostname, port, + path, query, hash, split; + split = url.split('://'); + if (split.length > 1) { + protocol = split.shift(); + if (options.protocols.indexOf(protocol) === -1) { + return false; + } + } else if (options.require_protocol) { + return false; + } + url = split.join('://'); + split = url.split('#'); + url = split.shift(); + hash = split.join('#'); + if (hash && /\s/.test(hash)) { + return false; + } + split = url.split('?'); + url = split.shift(); + query = split.join('?'); + if (query && /\s/.test(query)) { return false; } - host = match[1]; - port = match[2]; - if (port && !(port > 0 && port <= 65535)) { + split = url.split('/'); + url = split.shift(); + path = split.join('/'); + if (path && /\s/.test(path)) { + return false; + } + split = url.split('@'); + if (split.length > 1) { + auth = split.shift(); + if (auth.indexOf(':') >= 0) { + auth = auth.split(':'); + user = auth.shift(); + if (!/^\S+$/.test(user)) { + return false; + } + pass = auth.join(':'); + if (!/^\S*$/.test(user)) { + return false; + } + } + } + hostname = split.join('@'); + split = hostname.split(':'); + host = split.shift(); + if (split.length) { + port = parseInt(split.join(':'), 10); + if (port <= 0 || port > 65535) { + return false; + } + } + if (!validator.isIP(host) && !validator.isFQDN(host, options) && + host !== 'localhost') { return false; } - if (options.host_whitelist && options.host_whitelist.indexOf(host) === -1) { + if (options.host_whitelist && + options.host_whitelist.indexOf(host) === -1) { return false; } - if (options.host_blacklist && options.host_blacklist.indexOf(host) !== -1) { + if (options.host_blacklist && + options.host_blacklist.indexOf(host) !== -1) { return false; } return true; @@ -207,8 +248,31 @@ }; validator.isFQDN = function (str, options) { - options = merge(options, default_fqdn_options); - return new RegExp('^' + domain(options) + '$', 'i').test(str); + options = merge(options, default_fqdn_options); + var parts = str.split('.'); + if (options.require_tld) { + var tld = parts.pop(); + if (!parts.length || !/^[a-z]{2,}$/i.test(tld)) { + return false; + } + } + for (var part, i = 0; i < parts.length; i++) { + part = parts[i]; + if (options.allow_underscores) { + if (part.indexOf('__') >= 0) { + return false; + } + part = part.replace(/_/g, ''); + } + if (!/^[a-z\\u00a1-\\uffff0-9-]+$/i.test(part)) { + return false; + } + if (part[0] === '-' || part[part.length - 1] === '-' || + part.indexOf('---') >= 0) { + return false; + } + } + return true; }; validator.isAlpha = function (str) { @@ -468,15 +532,6 @@ return obj; } - function domain(options) { - var sep = '-?-?' + (options.allow_underscores ? '_?' : '') - , alpha = 'a-z\\u00a1-\\uffff' - , alphanum = alpha + '0-9' - , subdomain = '(?:(?:[' + alphanum + ']+' + sep + ')*[' + alphanum + ']+)' - , tld = '(?:\\.(?:[' + alpha + ']{2,}))' + (options.require_tld ? '' : '?'); - return '(?:' + subdomain + '(?:\\.' + subdomain + ')*' + tld + ')'; - } - validator.init(); return validator; diff --git a/validator.min.js b/validator.min.js index f69cf7b2b..84ec077b0 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 n in e)"undefined"==typeof t[n]&&(t[n]=e[n]);return t}function n(t){var e="-?-?"+(t.allow_underscores?"_?":""),n="a-z\\u00a1-\\uffff",r=n+"0-9",u="(?:(?:["+r+"]+"+e+")*["+r+"]+)",i="(?:\\.(?:["+n+"]{2,}))"+(t.require_tld?"":"?");return"(?:"+u+"(?:\\."+u+")*"+i+")"}t={version:"3.20.0"};var r=/^((([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\uF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/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/,v=/[\uD800-\uDBFF][\uDC00-\uDFFF]/,$=/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/;t.extend=function(e,n){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),n.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,n){return e===t.toString(n)},t.contains=function(e,n){return e.indexOf(t.toString(n))>=0},t.matches=function(t,e,n){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,n)),e.test(t)},t.isEmail=function(t){return r.test(t)};var w={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,allow_underscores:!1};t.isURL=function(t,r){if(!t||t.length>=2083)return!1;r=e(r,w);var u=["(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])","(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}",,"(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))"],i="(?:(?:"+r.protocols.join("|")+")://)"+(r.require_protocol?"":"?"),F="(?:\\S+(?::\\S*)?@)?",o="(?:"+u.join("")+")",a="("+o+"|"+n(r)+"|localhost)",s="(\\d{1,5})",c=a+"(?::"+s+")?",f="(?:(?:/|\\?|#)[^\\s]*)?",l=new RegExp("^(?!mailto:)"+i+F+c+f+"$","i"),d=t.match(l);return d?(c=d[1],s=d[2],!s||s>0&&65535>=s?r.host_whitelist&&-1===r.host_whitelist.indexOf(c)?!1:r.host_blacklist&&-1!==r.host_blacklist.indexOf(c)?!1:!0:!1):!1},t.isIP=function(e,n){if(n=t.toString(n),!n)return t.isIP(e,4)||t.isIP(e,6);if("4"===n){if(!o.test(e))return!1;var r=e.split(".").sort(function(t,e){return t-e});return r[3]<=255}return"6"===n&&a.test(e)};var m={require_tld:!0,allow_underscores:!1};t.isFQDN=function(t,r){return r=e(r,m),new RegExp("^"+n(r)+"$","i").test(t)},t.isAlpha=function(t){return c.test(t)},t.isAlphanumeric=function(t){return f.test(t)},t.isNumeric=function(t){return l.test(t)},t.isHexadecimal=function(t){return D.test(t)},t.isHexColor=function(t){return x.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t){return d.test(t)},t.isFloat=function(t){return""!==t&&p.test(t)},t.isDivisibleBy=function(e,n){return t.toFloat(e)%t.toInt(n)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,n){var r=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],u=t.length-r.length;return u>=e&&("undefined"==typeof n||n>=u)},t.isByteLength=function(t,e,n){return t.length>=e&&("undefined"==typeof n||t.length<=n)},t.isUUID=function(t,e){var n=s[e?e:"all"];return n&&n.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,n){var r=t.toDate(n||new Date),u=t.toDate(e);return!!(u&&r&&u>r)},t.isBefore=function(e,n){var r=t.toDate(n||new Date),u=t.toDate(e);return u&&r&&r>u},t.isIn=function(e,n){if(!n||"function"!=typeof n.indexOf)return!1;if("[object Array]"===Object.prototype.toString.call(n)){for(var r=[],u=0,i=n.length;i>u;u++)r[u]=t.toString(n[u]);n=r}return n.indexOf(e)>=0},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!u.test(e))return!1;for(var n,r,i,F=0,o=e.length-1;o>=0;o--)n=e.substring(o,o+1),r=parseInt(n,10),i?(r*=2,F+=r>=10?r%10+1:r):F+=r,i=!i;return!!(F%10===0?e:!1)},t.isISBN=function(e,n){if(n=t.toString(n),!n)return t.isISBN(e,10)||t.isISBN(e,13);var r,u=e.replace(/[\s-]+/g,""),o=0;if("10"===n){if(!i.test(u))return!1;for(r=0;9>r;r++)o+=(r+1)*u.charAt(r);if(o+="X"===u.charAt(9)?100:10*u.charAt(9),o%11===0)return!!u}else if("13"===n){if(!F.test(u))return!1;var a=[1,3];for(r=0;12>r;r++)o+=a[r%2]*u.charAt(r);if(u.charAt(12)-(10-o%10)%10===0)return!!u}return!1},t.isJSON=function(t){try{JSON.parse(t)}catch(e){return!1}return!0},t.isMultibyte=function(t){return g.test(t)},t.isAscii=function(t){return A.test(t)},t.isFullWidth=function(t){return h.test(t)},t.isHalfWidth=function(t){return E.test(t)},t.isVariableWidth=function(t){return h.test(t)&&E.test(t)},t.isSurrogatePair=function(t){return v.test(t)},t.isBase64=function(t){return $.test(t)},t.ltrim=function(t,e){var n=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(n,"")},t.rtrim=function(t,e){var n=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(n,"")},t.trim=function(t,e){var n=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(n,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")},t.stripLow=function(e,n){var r=n?"\x00- \f-":"\x00-";return t.blacklist(e,r)},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 C={lowercase:!0};return t.normalizeEmail=function(n,r){if(r=e(r,C),!t.isEmail(n))return!1;var u=n.split("@",2);return u[1]=u[1].toLowerCase(),r.lowercase&&(u[0]=u[0].toLowerCase()),("gmail.com"===u[1]||"googlemail.com"===u[1])&&(r.lowercase||(u[0]=u[0].toLowerCase()),u[0]=u[0].replace(/\./g,"").split("+")[0],u[1]="gmail.com"),u.join("@")},t.init(),t}); \ No newline at end of file +!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 n in e)"undefined"==typeof t[n]&&(t[n]=e[n]);return t}t={version:"3.20.0"};var n=/^((([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\uFDF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E0-9a-zA-Z]/,E=/[\uD800-\uDBFF][\uDC00-\uDFFF]/,v=/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/;t.extend=function(e,n){t[e]=function(){var e=Array.prototype.slice.call(arguments);return e[0]=t.toString(e[0]),n.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,n){return e===t.toString(n)},t.contains=function(e,n){return e.indexOf(t.toString(n))>=0},t.matches=function(t,e,n){return"[object RegExp]"!==Object.prototype.toString.call(e)&&(e=new RegExp(e,n)),e.test(t)},t.isEmail=function(t){return n.test(t)};var $={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,allow_underscores:!1};t.isURL=function(n,r){if(!n||n.length>=2083)return!1;if(0===n.indexOf("mailto:"))return!1;r=e(r,$);var u,i,F,o,a,s,f,l,c,p,d;if(d=n.split("://"),d.length>1){if(u=d.shift(),-1===r.protocols.indexOf(u))return!1}else if(r.require_protocol)return!1;if(n=d.join("://"),d=n.split("#"),n=d.shift(),p=d.join("#"),p&&/\s/.test(p))return!1;if(d=n.split("?"),n=d.shift(),c=d.join("?"),c&&/\s/.test(c))return!1;if(d=n.split("/"),n=d.shift(),l=d.join("/"),l&&/\s/.test(l))return!1;if(d=n.split("@"),d.length>1&&(o=d.shift(),o.indexOf(":")>=0)){if(o=o.split(":"),i=o.shift(),!/^\S+$/.test(i))return!1;if(F=o.join(":"),!/^\S*$/.test(i))return!1}return s=d.join("@"),d=s.split(":"),a=d.shift(),d.length&&(f=parseInt(d.join(":"),10),0>=f||f>65535)?!1:t.isIP(a)||t.isFQDN(a,r)||"localhost"===a?r.host_whitelist&&-1===r.host_whitelist.indexOf(a)?!1:r.host_blacklist&&-1!==r.host_blacklist.indexOf(a)?!1:!0:!1},t.isIP=function(e,n){if(n=t.toString(n),!n)return t.isIP(e,4)||t.isIP(e,6);if("4"===n){if(!F.test(e))return!1;var r=e.split(".").sort(function(t,e){return t-e});return r[3]<=255}return"6"===n&&o.test(e)};var m={require_tld:!0,allow_underscores:!1};t.isFQDN=function(t,n){n=e(n,m);var r=t.split(".");if(n.require_tld){var u=r.pop();if(!r.length||!/^[a-z]{2,}$/i.test(u))return!1}for(var i,F=0;F=0)return!1;i=i.replace(/_/g,"")}if(!/^[a-z\\u00a1-\\uffff0-9-]+$/i.test(i))return!1;if("-"===i[0]||"-"===i[i.length-1]||i.indexOf("---")>=0)return!1}return!0},t.isAlpha=function(t){return s.test(t)},t.isAlphanumeric=function(t){return f.test(t)},t.isNumeric=function(t){return l.test(t)},t.isHexadecimal=function(t){return d.test(t)},t.isHexColor=function(t){return g.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t){return c.test(t)},t.isFloat=function(t){return""!==t&&p.test(t)},t.isDivisibleBy=function(e,n){return t.toFloat(e)%t.toInt(n)===0},t.isNull=function(t){return 0===t.length},t.isLength=function(t,e,n){var r=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],u=t.length-r.length;return u>=e&&("undefined"==typeof n||n>=u)},t.isByteLength=function(t,e,n){return t.length>=e&&("undefined"==typeof n||t.length<=n)},t.isUUID=function(t,e){var n=a[e?e:"all"];return n&&n.test(t)},t.isDate=function(t){return!isNaN(Date.parse(t))},t.isAfter=function(e,n){var r=t.toDate(n||new Date),u=t.toDate(e);return!!(u&&r&&u>r)},t.isBefore=function(e,n){var r=t.toDate(n||new Date),u=t.toDate(e);return u&&r&&r>u},t.isIn=function(e,n){if(!n||"function"!=typeof n.indexOf)return!1;if("[object Array]"===Object.prototype.toString.call(n)){for(var r=[],u=0,i=n.length;i>u;u++)r[u]=t.toString(n[u]);n=r}return n.indexOf(e)>=0},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!r.test(e))return!1;for(var n,u,i,F=0,o=e.length-1;o>=0;o--)n=e.substring(o,o+1),u=parseInt(n,10),i?(u*=2,F+=u>=10?u%10+1:u):F+=u,i=!i;return!!(F%10===0?e:!1)},t.isISBN=function(e,n){if(n=t.toString(n),!n)return t.isISBN(e,10)||t.isISBN(e,13);var r,F=e.replace(/[\s-]+/g,""),o=0;if("10"===n){if(!u.test(F))return!1;for(r=0;9>r;r++)o+=(r+1)*F.charAt(r);if(o+="X"===F.charAt(9)?100:10*F.charAt(9),o%11===0)return!!F}else if("13"===n){if(!i.test(F))return!1;var a=[1,3];for(r=0;12>r;r++)o+=a[r%2]*F.charAt(r);if(F.charAt(12)-(10-o%10)%10===0)return!!F}return!1},t.isJSON=function(t){try{JSON.parse(t)}catch(e){return!1}return!0},t.isMultibyte=function(t){return D.test(t)},t.isAscii=function(t){return x.test(t)},t.isFullWidth=function(t){return A.test(t)},t.isHalfWidth=function(t){return h.test(t)},t.isVariableWidth=function(t){return A.test(t)&&h.test(t)},t.isSurrogatePair=function(t){return E.test(t)},t.isBase64=function(t){return v.test(t)},t.ltrim=function(t,e){var n=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(n,"")},t.rtrim=function(t,e){var n=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(n,"")},t.trim=function(t,e){var n=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(n,"")},t.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")},t.stripLow=function(e,n){var r=n?"\x00- \f-":"\x00-";return t.blacklist(e,r)},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 w={lowercase:!0};return t.normalizeEmail=function(n,r){if(r=e(r,w),!t.isEmail(n))return!1;var u=n.split("@",2);return u[1]=u[1].toLowerCase(),r.lowercase&&(u[0]=u[0].toLowerCase()),("gmail.com"===u[1]||"googlemail.com"===u[1])&&(r.lowercase||(u[0]=u[0].toLowerCase()),u[0]=u[0].replace(/\./g,"").split("+")[0],u[1]="gmail.com"),u.join("@")},t.init(),t}); \ No newline at end of file