forked from validatorjs/validator.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.min.js
More file actions
23 lines (23 loc) · 10 KB
/
validator.min.js
File metadata and controls
23 lines (23 loc) · 10 KB
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) 2014 Chris O'Hara <cohara87@gmail.com>
*
* 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[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.30.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\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))/,r=/([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~\.]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~\.]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\s)*/,u=new RegExp("^"+n.source+"$","i"),i=new RegExp("^"+r.source+"<"+n.source+">$","i"),F=/^(?: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})$/,o=/^(?:[0-9]{9}X|[0-9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)?9[1236]\d{7}$/};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)};var m={allow_display_name:!1};t.isEmail=function(t,n){return n=e(n,m),u.test(t)||n.allow_display_name===!0&&i.test(t)};var y={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,allow_underscores:!1,allow_trailing_dot:!1};t.isURL=function(n,r){if(!n||n.length>=2083)return!1;if(0===n.indexOf("mailto:"))return!1;r=e(r,y);var u,i,F,o,a,s,f,l,c,p,d,x;if(x=n.split("://"),x.length>1){if(u=x.shift(),-1===r.protocols.indexOf(u))return!1}else if(r.require_protocol)return!1;if(n=x.join("://"),x=n.split("#"),n=x.shift(),d=x.join("#"),d&&/\s/.test(d))return!1;if(x=n.split("?"),n=x.shift(),p=x.join("?"),p&&/\s/.test(p))return!1;if(x=n.split("/"),n=x.shift(),c=x.join("/"),c&&/\s/.test(c))return!1;if(x=n.split("@"),x.length>1&&(o=x.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=x.join("@"),x=s.split(":"),a=x.shift(),x.length&&(l=x.join(":"),f=parseInt(l,10),!/^[0-9]+$/.test(l)||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(!s.test(e))return!1;var r=e.split(".").sort(function(t,e){return t-e});return r[3]<=255}return"6"===n&&f.test(e)};var z={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1};t.isFQDN=function(t,n){n=e(n,z),n.allow_trailing_dot&&"."===t[t.length-1]&&(t=t.substring(0,t.length-1));var r=t.split(".");if(n.require_tld){var u=r.pop();if(!r.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(u))return!1}for(var i,F=0;F<r.length;F++){if(i=r[F],n.allow_underscores){if(i.indexOf("__")>=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 c.test(t)},t.isAlphanumeric=function(t){return p.test(t)},t.isNumeric=function(t){return d.test(t)},t.isHexadecimal=function(t){return D.test(t)},t.isHexColor=function(t){return A.test(t)},t.isLowercase=function(t){return t===t.toLowerCase()},t.isUppercase=function(t){return t===t.toUpperCase()},t.isInt=function(t){return x.test(t)},t.isFloat=function(t){return""!==t&&g.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=l[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){var r;if("[object Array]"===Object.prototype.toString.call(n)){var u=[];for(r in n)u[r]=t.toString(n[r]);return u.indexOf(e)>=0}return"object"==typeof n?n.hasOwnProperty(e):n&&"function"==typeof n.indexOf?n.indexOf(e)>=0:!1},t.isCreditCard=function(t){var e=t.replace(/[^0-9]+/g,"");if(!F.test(e))return!1;for(var n,r,u,i=0,o=e.length-1;o>=0;o--)n=e.substring(o,o+1),r=parseInt(n,10),u?(r*=2,i+=r>=10?r%10+1:r):i+=r,u=!u;return!!(i%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,""),i=0;if("10"===n){if(!o.test(u))return!1;for(r=0;9>r;r++)i+=(r+1)*u.charAt(r);if(i+="X"===u.charAt(9)?100:10*u.charAt(9),i%11===0)return!!u}else if("13"===n){if(!a.test(u))return!1;var F=[1,3];for(r=0;12>r;r++)i+=F[r%2]*u.charAt(r);if(u.charAt(12)-(10-i%10)%10===0)return!!u}return!1},t.isMobilePhone=function(t,e){return e in C?C[e].test(t):!1},t.isJSON=function(t){try{JSON.parse(t)}catch(e){return!1}return!0},t.isMultibyte=function(t){return $.test(t)},t.isAscii=function(t){return h.test(t)},t.isFullWidth=function(t){return E.test(t)},t.isHalfWidth=function(t){return v.test(t)},t.isVariableWidth=function(t){return E.test(t)&&v.test(t)},t.isSurrogatePair=function(t){return w.test(t)},t.isBase64=function(t){return _.test(t)},t.isMongoId=function(e){return t.isHexadecimal(e)&&24===e.length},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,"<").replace(/>/g,">").replace(/\//g,"/")},t.stripLow=function(e,n){var r=n?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F";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 b={lowercase:!0};return t.normalizeEmail=function(n,r){if(r=e(r,b),!t.isEmail(n))return!1;var u=n.split("@",2);if(u[1]=u[1].toLowerCase(),"gmail.com"===u[1]||"googlemail.com"===u[1]){if(u[0]=u[0].toLowerCase().replace(/\./g,""),"+"===u[0][0])return!1;u[0]=u[0].split("+")[0],u[1]="gmail.com"}else r.lowercase&&(u[0]=u[0].toLowerCase());return u.join("@")},t.init(),t});