forked from validatorjs/validator.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validator.min.js
23 lines (23 loc) · 13.1 KB
/
validator.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*!
* Copyright (c) 2015 Chris O'Hara <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* 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.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\u00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0-9A-F]{3}|[0-9A-F]{6})$/i,$=/^[\x00-\x7F]+$/,m=/[^\x00-\x7F]/,b=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/,D=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/,y=/[\uD800-\uDBFF][\uDC00-\uDFFF]/,I=/^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i,E={"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}$/},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;l<a.length;l++)if(!u.test(a[l]))return!1;return!0}),require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1,allow_private_host:!0,require_valid_port:!0,allow_auth_user_domain:!1};f.isURL=function(t,e){if(!t||2083<=t.length||/\s/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,n,i,o,s,u;if(e=j(e,C),1<(u=t.split("://")).length){if(r=u.shift(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;e.allow_protocol_relative_urls&&"//"===t.substr(0,2)&&(u[0]=t.substr(2))}if(1<(u=(t=(u=(t=(u=(t=(u=(t=u.join("://")).split("#")).shift()).split("?")).shift()).split("/")).shift()).split("@")).length){if(n=u.shift(),e.allow_auth_user_domain)for(;1<u.length;)n+="@"+u.shift();if(0<=n.indexOf(":")&&2<n.split(":").length)return!1}return i=(u=u.join("@").split(":")).shift(),!(u.length&&(s=u.join(":"),o=parseInt(s,10),e.require_valid_port&&(!/^[0-9]+$/.test(s)||o<=0||65535<o)))&&(!(!f.isIP(i)&&!f.isFQDN(i,e)&&"localhost"!==i)&&(!(!e.allow_private_host&&("localhost"===i||f.isPrivateIP(i)))&&((!e.host_whitelist||-1!==e.host_whitelist.indexOf(i))&&(!e.host_blacklist||-1===e.host_blacklist.indexOf(i)))))},f.isIP=function(t,e){if(!(e=f.toString(e)))return f.isIP(t,4)||f.isIP(t,6);if("4"===e)return!!_.test(t)&&t.split(".").sort(function(t,e){return t-e})[3]<=255;if("6"!==e)return!1;var r=t.split(":"),n=!1,i=f.isIP(r[r.length-1],4),o=i?7:8;if(r.length>o)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<r.length;++s)if(""===r[s]&&0<s&&s<r.length-1){if(n)return!1;n=!0}else if(i&&s==r.length-1);else if(!h.test(r[s]))return!1;return n?1<=r.length:r.length===o};var P={require_tld:!0,allow_underscores:!(f.isPrivateIP=function(t,e){return!!f.isIP(t,e)&&((e=f.toString(e))?"4"===e?/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(t)||/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/.test(t)||/^172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})/.test(t)||/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(t)||/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/.test(t)||/^0{1,3}\.0{1,3}\.0{1,3}\.0{1,3}/.test(t):"6"===e&&(/^fc00:/.test(t)||/^fe80:/.test(t)||/^::1$/.test(t)||/^::$/.test(t)):f.isPrivateIP(t,4)||f.isPrivateIP(t,6))}),allow_trailing_dot:!1};f.isFQDN=function(t,e){(e=j(e,P)).allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var r=t.split(".");if(e.require_tld){var n=r.pop();if(!r.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(n))return!1}for(var i,o=0;o<r.length;o++){if(i=r[o],e.allow_underscores){if(0<=i.indexOf("__"))return!1;i=i.replace(/_/g,"")}if(!/^[a-z\u00a1-\uffff0-9-]+$/i.test(i))return!1;if(/[\uff01-\uff5e]/.test(i))return!1;if("-"===i[0]||"-"===i[i.length-1]||0<=i.indexOf("---"))return!1}return!0},f.isBoolean=function(t){return 0<=["true","false","1","0"].indexOf(t)},f.isAlpha=function(t){return e.test(t)},f.isAlphanumeric=function(t){return r.test(t)},f.isNumeric=function(t){return i.test(t)},f.isDecimal=function(t){return""!==t&&A.test(t)},f.isHexadecimal=function(t){return v.test(t)},f.isHexColor=function(t){return w.test(t)},f.isLowercase=function(t){return t===t.toLowerCase()},f.isUppercase=function(t){return t===t.toUpperCase()},f.isInt=function(t,e){return e=e||{},o.test(t)&&(!e.hasOwnProperty("min")||t>=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<n)},f.isBefore=function(t,e){var r=f.toDate(e||new Date),n=f.toDate(t);return n&&r&&n<r},f.isIn=function(t,e){var r;if("[object Array]"!==Object.prototype.toString.call(e))return"object"==typeof e?e.hasOwnProperty(t):!(!e||"function"!=typeof e.indexOf)&&0<=e.indexOf(t);var n=[];for(r in e)n[r]=f.toString(e[r]);return 0<=n.indexOf(t)},f.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!u.test(e))return!1;for(var r,n,i,o=0,s=e.length-1;0<=s;s--)r=e.substring(s,s+1),n=parseInt(r,10),o+=i&&10<=(n*=2)?n%10+1:n,i=!i;return!(o%10!=0||!e)},f.isISIN=function(t){if(!a.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;0<=s;s--)e=n.substring(s,s+1),r=parseInt(e,10),i+=o&&10<=(r*=2)?r+1:r,o=!o;return parseInt(t.substr(t.length-1),10)===(1e4-i)%10},f.isISBN=function(t,e){if(!(e=f.toString(e)))return f.isISBN(t,10)||f.isISBN(t,13);var r,n=t.replace(/[\s-]+/g,""),i=0;if("10"===e){if(!s.test(n))return!1;for(r=0;r<9;r++)i+=(r+1)*n.charAt(r);if("X"===n.charAt(9)?i+=100:i+=10*n.charAt(9),i%11==0)return!!n}else if("13"===e){if(!l.test(n))return!1;var o=[1,3];for(r=0;r<12;r++)i+=o[r%2]*n.charAt(r);if(n.charAt(12)-(10-i%10)%10==0)return!!n}return!1};var N={symbol:"$",require_symbol:!(f.isMobilePhone=function(t,e){return e in E&&E[e].test(t)}),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};f.isCurrency=function(t,e){return function(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*",n="("+["0","[1-9]\\d*",r].join("|")+")?",i="(\\"+t.decimal_separator+"\\d{2})?",o=n+i;t.allow_negatives&&!t.parens_for_negatives&&(t.negative_sign_after_digits?o+="-?":t.negative_sign_before_digits&&(o="-?"+o));t.allow_negative_sign_placeholder?o="( (?!\\-))?"+o:t.allow_space_after_symbol?o=" ?"+o:t.allow_space_after_digits&&(o+="( (?!$))?");t.symbol_after_digits?o+=e:o=e+o;t.allow_negatives&&(t.parens_for_negatives?o="(\\("+o+"\\)|"+o+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(o="-?"+o));return new RegExp("^(?!-? )(?=.*\\d)"+o+"$")}(e=j(e,N)).test(t)},f.isJSON=function(t){try{var e=JSON.parse(t);return!!e&&"object"==typeof e}catch(t){}return!1},f.isMultibyte=function(t){return m.test(t)},f.isAscii=function(t){return $.test(t)},f.isFullWidth=function(t){return b.test(t)},f.isHalfWidth=function(t){return D.test(t)},f.isVariableWidth=function(t){return b.test(t)&&D.test(t)},f.isSurrogatePair=function(t){return y.test(t)},f.isBase64=function(t){return I.test(t)},f.isMongoId=function(t){return f.isHexadecimal(t)&&24===t.length},f.isISO8601=function(t){return O.test(t)},f.ltrim=function(t,e){var r=e?new RegExp("^["+e+"]+","g"):/^\s+/g;return t.replace(r,"")},f.rtrim=function(t,e){var r=e?new RegExp("["+e+"]+$","g"):/\s+$/g;return t.replace(r,"")},f.trim=function(t,e){var r=e?new RegExp("^["+e+"]+|["+e+"]+$","g"):/^\s+|\s+$/g;return t.replace(r,"")},f.escape=function(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/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});