From 0d6071d5e5266c18c761a03db1814824af1561a7 Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Sun, 25 Jun 2017 23:56:19 +0300 Subject: [PATCH] [feat: isMobilePhone] add Kenya (en-KE) validation - Adds validation for Kenya phone numbers. See details of valid KE phone numbers here - https://en.wikipedia.org/wiki/Telephone_numbers_in_Kenya closes #656 --- README.md | 2 +- lib/isMobilePhone.js | 1 + src/lib/isMobilePhone.js | 1 + test/validators.js | 22 ++++++++++++++++++++++ validator.js | 1 + validator.min.js | 2 +- 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a8a5fa82..85bba8af5 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Passing anything other than a string is an error. - **isLowercase(str)** - check if the string is lowercase. - **isMACAddress(str)** - check if the string is a MAC address. - **isMD5(str)** - check if the string is a MD5 hash. -- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match). +- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']` OR 'any'. If 'any' is used, function will check if any of the locales match). - **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. - **isMultibyte(str)** - check if the string contains one or more multibyte chars. - **isNumeric(str)** - check if the string contains only numbers. diff --git a/lib/isMobilePhone.js b/lib/isMobilePhone.js index 2123ede61..2ed483907 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -25,6 +25,7 @@ var phones = { 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/, 'en-IN': /^(\+?91|0)?[789]\d{9}$/, + 'en-KE': /^(\+?254|0)?[7]\d{8}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)2\d{7,9}$/, 'en-ZA': /^(\+?27|0)\d{9}$/, diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index de031bb3c..f3c1a033a 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -14,6 +14,7 @@ const phones = { 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/, 'en-IN': /^(\+?91|0)?[789]\d{9}$/, + 'en-KE': /^(\+?254|0)?[7]\d{8}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)2\d{7,9}$/, 'en-ZA': /^(\+?27|0)\d{9}$/, diff --git a/test/validators.js b/test/validators.js index f42b5f553..9757864cf 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2386,6 +2386,28 @@ describe('Validators', function () { args: ['en-HK'], }); + var en_KE = { + valid: [ + '+254728590432', + '+254733875610', + '254728590234', + '0733346543', + '0700459022', + ], + invalid: [ + '999', + '+25489032', + '123456789', + '+254800723845', + ], + }; + test({ + validator: 'isMobilePhone', + valid: en_KE.valid, + invalid: en_KE.invalid, + args: ['en-KE'], + }); + var fr_FR = { valid: [ '0612457898', diff --git a/validator.js b/validator.js index 3e88aa33e..5a16312f3 100644 --- a/validator.js +++ b/validator.js @@ -896,6 +896,7 @@ var phones = { 'en-GB': /^(\+?44|0)7\d{9}$/, 'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/, 'en-IN': /^(\+?91|0)?[789]\d{9}$/, + 'en-KE': /^(\+?254|0)?[7]\d{8}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)2\d{7,9}$/, 'en-ZA': /^(\+?27|0)\d{9}$/, diff --git a/validator.min.js b/validator.min.js index 3e6c6404d..745d1573d 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){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.validator=e()}(this,function(){"use strict";function t(t){if(!("string"==typeof t||t instanceof String))throw new TypeError("This library (validator.js) validates strings only")}function e(e){return t(e),e=Date.parse(e),isNaN(e)?null:new Date(e)}function o(e){return t(e),parseFloat(e)}function r(t){return"object"===(void 0===t?"undefined":v(t))&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null===t||void 0===t||isNaN(t)&&!t.length)&&(t=""),String(t)}function i(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments[1];for(var o in e)void 0===t[o]&&(t[o]=e[o]);return t}function n(e,o){t(e);var r=void 0,i=void 0;"object"===(void 0===o?"undefined":v(o))?(r=o.min||0,i=o.max):(r=arguments[1],i=arguments[2]);var n=encodeURI(e).split(/%..|./).length-1;return n>=r&&(void 0===i||n<=i)}function l(e,o){t(e),(o=i(o,F)).allow_trailing_dot&&"."===e[e.length-1]&&(e=e.substring(0,e.length-1));var r=e.split(".");if(o.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 l,a=0;a1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(o=String(o)))return u(e,4)||u(e,6);if("4"===o)return!!k.test(e)&&e.split(".").sort(function(t,e){return t-e})[3]<=255;if("6"===o){var r=e.split(":"),i=!1,n=u(r[r.length-1],4),l=n?7:8;if(r.length>l)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(r.shift(),r.shift(),i=!0):"::"===e.substr(e.length-2)&&(r.pop(),r.pop(),i=!0);for(var a=0;a0&&a=1:r.length===l}return!1}function s(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function d(t,e){for(var o=0;o1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(o=String(o)))return f(e,10)||f(e,13);var r=e.replace(/[\s-]+/g,""),i=0,n=void 0;if("10"===o){if(!et.test(r))return!1;for(n=0;n<9;n++)i+=(n+1)*r.charAt(n);if("X"===r.charAt(9)?i+=100:i+=10*r.charAt(9),i%11==0)return!!r}else if("13"===o){if(!ot.test(r))return!1;for(n=0;n<12;n++)i+=rt[n%2]*r.charAt(n);if(r.charAt(12)-(10-i%10)%10==0)return!!r}return!1}function p(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),o="("+["0","[1-9]\\d*","[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*"].join("|")+")?"+("(\\"+t.decimal_separator+"\\d{2})?");return 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)),new RegExp("^(?!-? )(?=.*\\d)"+o+"$")}function g(e,o){t(e);var r=o?new RegExp("^["+o+"]+","g"):/^\s+/g;return e.replace(r,"")}function h(e,o){t(e);for(var r=o?new RegExp("["+o+"]"):/\s/,i=e.length-1;i>=0&&r.test(e[i]);)i--;return i$/i,A=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,w=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,y=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,b=/^([\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,k=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,S=/^[0-9A-F]{1,4}$/i,D={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},Z=/^\[([^\]]+)\](?::([0-9]+))?$/,E=/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/,O={"en-US":/^[A-Z]+$/i,"cs-CZ":/^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,"da-DK":/^[A-ZÆØÅ]+$/i,"de-DE":/^[A-ZÄÖÜß]+$/i,"es-ES":/^[A-ZÁÉÍÑÓÚÜ]+$/i,"fr-FR":/^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,"nl-NL":/^[A-ZÉËÏÓÖÜ]+$/i,"hu-HU":/^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,"pl-PL":/^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,"pt-PT":/^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,"ru-RU":/^[А-ЯЁ]+$/i,"sr-RS@latin":/^[A-ZČĆŽŠĐ]+$/i,"sr-RS":/^[А-ЯЂЈЉЊЋЏ]+$/i,"tr-TR":/^[A-ZÇĞİıÖŞÜ]+$/i,"uk-UA":/^[А-ЩЬЮЯЄIЇҐ]+$/i,ar:/^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},R={"en-US":/^[0-9A-Z]+$/i,"cs-CZ":/^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,"da-DK":/^[0-9A-ZÆØÅ]$/i,"de-DE":/^[0-9A-ZÄÖÜß]+$/i,"es-ES":/^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,"fr-FR":/^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,"hu-HU":/^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,"nl-NL":/^[0-9A-ZÉËÏÓÖÜ]+$/i,"pl-PL":/^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,"pt-PT":/^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,"ru-RU":/^[0-9А-ЯЁ]+$/i,"sr-RS@latin":/^[0-9A-ZČĆŽŠĐ]+$/i,"sr-RS":/^[0-9А-ЯЂЈЉЊЋЏ]+$/i,"tr-TR":/^[0-9A-ZÇĞİıÖŞÜ]+$/i,"uk-UA":/^[0-9А-ЩЬЮЯЄIЇҐ]+$/i,ar:/^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},C=["AU","GB","HK","IN","NZ","ZA","ZM"],I=0;I=0},matches:function(e,o,r){return t(e),"[object RegExp]"!==Object.prototype.toString.call(o)&&(o=new RegExp(o,r)),o.test(e)},isEmail:a,isURL:function(e,o){if(t(e),!e||e.length>=2083||/[\s<>]/.test(e))return!1;if(0===e.indexOf("mailto:"))return!1;o=i(o,D);var r=void 0,n=void 0,a=void 0,s=void 0,c=void 0,f=void 0,p=void 0,g=void 0;if(p=e.split("#"),e=p.shift(),p=e.split("?"),e=p.shift(),(p=e.split("://")).length>1){if(r=p.shift(),o.require_valid_protocol&&-1===o.protocols.indexOf(r))return!1}else{if(o.require_protocol)return!1;o.allow_protocol_relative_urls&&"//"===e.substr(0,2)&&(p[0]=e.substr(2))}if(e=p.join("://"),p=e.split("/"),""===(e=p.shift())&&!o.require_host)return!0;if((p=e.split("@")).length>1&&(n=p.shift()).indexOf(":")>=0&&n.split(":").length>2)return!1;f=null,g=null;var h=(s=p.join("@")).match(Z);return h?(a="",g=h[1],f=h[2]||null):(a=(p=s.split(":")).shift(),p.length&&(f=p.join(":"))),!(null!==f&&(c=parseInt(f,10),!/^[0-9]+$/.test(f)||c<=0||c>65535)||!(u(a)||l(a,o)||g&&u(g,6)||"localhost"===a)||(a=a||g,o.host_whitelist&&!d(a,o.host_whitelist)||o.host_blacklist&&d(a,o.host_blacklist)))},isMACAddress:function(e){return t(e),E.test(e)},isIP:u,isFQDN:l,isBoolean:function(e){return t(e),["true","false","1","0"].indexOf(e)>=0},isAlpha:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),o in O)return O[o].test(e);throw new Error("Invalid locale '"+o+"'")},isAlphanumeric:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),o in R)return R[o].test(e);throw new Error("Invalid locale '"+o+"'")},isNumeric:function(e){return t(e),P.test(e)},isLowercase:function(e){return t(e),e===e.toLowerCase()},isUppercase:function(e){return t(e),e===e.toUpperCase()},isAscii:function(e){return t(e),L.test(e)},isFullWidth:function(e){return t(e),N.test(e)},isHalfWidth:function(e){return t(e),B.test(e)},isVariableWidth:function(e){return t(e),N.test(e)&&B.test(e)},isMultibyte:function(e){return t(e),q.test(e)},isSurrogatePair:function(e){return t(e),T.test(e)},isInt:function(e,o){t(e);var r=(o=o||{}).hasOwnProperty("allow_leading_zeroes")&&!o.allow_leading_zeroes?H:K,i=!o.hasOwnProperty("min")||e>=o.min,n=!o.hasOwnProperty("max")||e<=o.max,l=!o.hasOwnProperty("lt")||eo.gt;return r.test(e)&&i&&n&&l&&a},isFloat:function(e,o){return t(e),o=o||{},""!==e&&"."!==e&&M.test(e)&&(!o.hasOwnProperty("min")||e>=o.min)&&(!o.hasOwnProperty("max")||e<=o.max)&&(!o.hasOwnProperty("lt")||eo.gt)},isDecimal:function(e){return t(e),""!==e&&W.test(e)},isHexadecimal:c,isDivisibleBy:function(e,r){return t(e),o(e)%parseInt(r,10)==0},isHexColor:function(e){return t(e),Y.test(e)},isISRC:function(e){return t(e),J.test(e)},isMD5:function(e){return t(e),Q.test(e)},isJSON:function(e){t(e);try{var o=JSON.parse(e);return!!o&&"object"===(void 0===o?"undefined":v(o))}catch(t){}return!1},isEmpty:function(e){return t(e),0===e.length},isLength:function(e,o){t(e);var r=void 0,i=void 0;"object"===(void 0===o?"undefined":v(o))?(r=o.min||0,i=o.max):(r=arguments[1],i=arguments[2]);var n=e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],l=e.length-n.length;return l>=r&&(void 0===i||l<=i)},isByteLength:n,isUUID:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all";t(e);var r=X[o];return r&&r.test(e)},isMongoId:function(e){return t(e),c(e)&&24===e.length},isAfter:function(o){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(o);var i=e(r),n=e(o);return!!(n&&i&&n>i)},isBefore:function(o){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(o);var i=e(r),n=e(o);return!!(n&&i&&n=0}return"object"===(void 0===o?"undefined":v(o))?o.hasOwnProperty(e):!(!o||"function"!=typeof o.indexOf)&&o.indexOf(e)>=0},isCreditCard:function(e){t(e);var o=e.replace(/[^0-9]+/g,"");if(!V.test(o))return!1;for(var r=0,i=void 0,n=void 0,l=void 0,a=o.length-1;a>=0;a--)i=o.substring(a,a+1),n=parseInt(i,10),r+=l&&(n*=2)>=10?n%10+1:n,l=!l;return!(r%10!=0||!o)},isISIN:function(e){if(t(e),!tt.test(e))return!1;for(var o=e.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),r=0,i=void 0,n=void 0,l=!0,a=o.length-2;a>=0;a--)i=o.substring(a,a+1),n=parseInt(i,10),r+=l&&(n*=2)>=10?n+1:n,l=!l;return parseInt(e.substr(e.length-1),10)===(1e4-r)%10},isISBN:f,isISSN:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(e);var r=it;if(r=o.require_hyphen?r.replace("?",""):r,!(r=o.case_sensitive?new RegExp(r):new RegExp(r,"i")).test(e))return!1;var i=e.replace("-",""),n=8,l=0,a=!0,u=!1,s=void 0;try{for(var d,c=i[Symbol.iterator]();!(a=(d=c.next()).done);a=!0){var f=d.value;l+=("X"===f.toUpperCase()?10:+f)*n,--n}}catch(t){u=!0,s=t}finally{try{!a&&c.return&&c.return()}finally{if(u)throw s}}return l%11==0},isMobilePhone:function(e,o){return t(e),o in nt?nt[o].test(e):"any"===o&&!!Object.values(nt).find(function(t){return t.test(e)})},isCurrency:function(e,o){return t(e),o=i(o,lt),p(o).test(e)},isISO8601:function(e){return t(e),at.test(e)},isBase64:function(e){t(e);var o=e.length;if(!o||o%4!=0||ut.test(e))return!1;var r=e.indexOf("=");return-1===r||r===o-1||r===o-2&&"="===e[o-1]},isDataURI:function(e){return t(e),st.test(e)},ltrim:g,rtrim:h,trim:function(t,e){return h(g(t,e),e)},escape:function(e){return t(e),e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(e){return t(e),e.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/`/g,"`")},stripLow:function(e,o){return t(e),m(e,o?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(e,o){return t(e),e.replace(new RegExp("[^"+o+"]+","g"),"")},blacklist:m,isWhitelisted:function(e,o){t(e);for(var r=e.length-1;r>=0;r--)if(-1===o.indexOf(e[r]))return!1;return!0},normalizeEmail:function(t,e){if(e=i(e,dt),!a(t))return!1;var o=t.split("@"),r=o.pop(),n=[o.join("@"),r];if(n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if(e.gmail_remove_subaddress&&(n[0]=n[0].split("+")[0]),e.gmail_remove_dots&&(n[0]=n[0].replace(/\./g,"")),!n[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(n[0]=n[0].toLowerCase()),n[1]=e.gmail_convert_googlemaildotcom?"gmail.com":n[1]}else if(~ct.indexOf(n[1])){if(e.icloud_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(n[0]=n[0].toLowerCase())}else if(~ft.indexOf(n[1])){if(e.outlookdotcom_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(n[0]=n[0].toLowerCase())}else if(~pt.indexOf(n[1])){if(e.yahoo_remove_subaddress){var l=n[0].split("-");n[0]=l.length>1?l.slice(0,-1).join("-"):l[0]}if(!n[0].length)return!1;(e.all_lowercase||e.yahoo_lowercase)&&(n[0]=n[0].toLowerCase())}else e.all_lowercase&&(n[0]=n[0].toLowerCase());return n.join("@")},toString:r}}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.validator=e()}(this,function(){"use strict";function t(t){if(!("string"==typeof t||t instanceof String))throw new TypeError("This library (validator.js) validates strings only")}function e(e){return t(e),e=Date.parse(e),isNaN(e)?null:new Date(e)}function o(e){return t(e),parseFloat(e)}function r(t){return"object"===(void 0===t?"undefined":v(t))&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null===t||void 0===t||isNaN(t)&&!t.length)&&(t=""),String(t)}function i(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments[1];for(var o in e)void 0===t[o]&&(t[o]=e[o]);return t}function n(e,o){t(e);var r=void 0,i=void 0;"object"===(void 0===o?"undefined":v(o))?(r=o.min||0,i=o.max):(r=arguments[1],i=arguments[2]);var n=encodeURI(e).split(/%..|./).length-1;return n>=r&&(void 0===i||n<=i)}function l(e,o){t(e),(o=i(o,F)).allow_trailing_dot&&"."===e[e.length-1]&&(e=e.substring(0,e.length-1));var r=e.split(".");if(o.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 l,a=0;a1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(o=String(o)))return u(e,4)||u(e,6);if("4"===o)return!!k.test(e)&&e.split(".").sort(function(t,e){return t-e})[3]<=255;if("6"===o){var r=e.split(":"),i=!1,n=u(r[r.length-1],4),l=n?7:8;if(r.length>l)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(r.shift(),r.shift(),i=!0):"::"===e.substr(e.length-2)&&(r.pop(),r.pop(),i=!0);for(var a=0;a0&&a=1:r.length===l}return!1}function s(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function d(t,e){for(var o=0;o1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(o=String(o)))return f(e,10)||f(e,13);var r=e.replace(/[\s-]+/g,""),i=0,n=void 0;if("10"===o){if(!et.test(r))return!1;for(n=0;n<9;n++)i+=(n+1)*r.charAt(n);if("X"===r.charAt(9)?i+=100:i+=10*r.charAt(9),i%11==0)return!!r}else if("13"===o){if(!ot.test(r))return!1;for(n=0;n<12;n++)i+=rt[n%2]*r.charAt(n);if(r.charAt(12)-(10-i%10)%10==0)return!!r}return!1}function p(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),o="("+["0","[1-9]\\d*","[1-9]\\d{0,2}(\\"+t.thousands_separator+"\\d{3})*"].join("|")+")?"+("(\\"+t.decimal_separator+"\\d{2})?");return 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)),new RegExp("^(?!-? )(?=.*\\d)"+o+"$")}function g(e,o){t(e);var r=o?new RegExp("^["+o+"]+","g"):/^\s+/g;return e.replace(r,"")}function h(e,o){t(e);for(var r=o?new RegExp("["+o+"]"):/\s/,i=e.length-1;i>=0&&r.test(e[i]);)i--;return i$/i,A=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,w=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,y=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,b=/^([\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,k=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,S=/^[0-9A-F]{1,4}$/i,D={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},E=/^\[([^\]]+)\](?::([0-9]+))?$/,Z=/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/,O={"en-US":/^[A-Z]+$/i,"cs-CZ":/^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,"da-DK":/^[A-ZÆØÅ]+$/i,"de-DE":/^[A-ZÄÖÜß]+$/i,"es-ES":/^[A-ZÁÉÍÑÓÚÜ]+$/i,"fr-FR":/^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,"nl-NL":/^[A-ZÉËÏÓÖÜ]+$/i,"hu-HU":/^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,"pl-PL":/^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,"pt-PT":/^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,"ru-RU":/^[А-ЯЁ]+$/i,"sr-RS@latin":/^[A-ZČĆŽŠĐ]+$/i,"sr-RS":/^[А-ЯЂЈЉЊЋЏ]+$/i,"tr-TR":/^[A-ZÇĞİıÖŞÜ]+$/i,"uk-UA":/^[А-ЩЬЮЯЄIЇҐ]+$/i,ar:/^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},R={"en-US":/^[0-9A-Z]+$/i,"cs-CZ":/^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,"da-DK":/^[0-9A-ZÆØÅ]$/i,"de-DE":/^[0-9A-ZÄÖÜß]+$/i,"es-ES":/^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,"fr-FR":/^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,"hu-HU":/^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,"nl-NL":/^[0-9A-ZÉËÏÓÖÜ]+$/i,"pl-PL":/^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,"pt-PT":/^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i,"ru-RU":/^[0-9А-ЯЁ]+$/i,"sr-RS@latin":/^[0-9A-ZČĆŽŠĐ]+$/i,"sr-RS":/^[0-9А-ЯЂЈЉЊЋЏ]+$/i,"tr-TR":/^[0-9A-ZÇĞİıÖŞÜ]+$/i,"uk-UA":/^[0-9А-ЩЬЮЯЄIЇҐ]+$/i,ar:/^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},C=["AU","GB","HK","IN","NZ","ZA","ZM"],I=0;I=0},matches:function(e,o,r){return t(e),"[object RegExp]"!==Object.prototype.toString.call(o)&&(o=new RegExp(o,r)),o.test(e)},isEmail:a,isURL:function(e,o){if(t(e),!e||e.length>=2083||/[\s<>]/.test(e))return!1;if(0===e.indexOf("mailto:"))return!1;o=i(o,D);var r=void 0,n=void 0,a=void 0,s=void 0,c=void 0,f=void 0,p=void 0,g=void 0;if(p=e.split("#"),e=p.shift(),p=e.split("?"),e=p.shift(),(p=e.split("://")).length>1){if(r=p.shift(),o.require_valid_protocol&&-1===o.protocols.indexOf(r))return!1}else{if(o.require_protocol)return!1;o.allow_protocol_relative_urls&&"//"===e.substr(0,2)&&(p[0]=e.substr(2))}if(e=p.join("://"),p=e.split("/"),""===(e=p.shift())&&!o.require_host)return!0;if((p=e.split("@")).length>1&&(n=p.shift()).indexOf(":")>=0&&n.split(":").length>2)return!1;f=null,g=null;var h=(s=p.join("@")).match(E);return h?(a="",g=h[1],f=h[2]||null):(a=(p=s.split(":")).shift(),p.length&&(f=p.join(":"))),!(null!==f&&(c=parseInt(f,10),!/^[0-9]+$/.test(f)||c<=0||c>65535)||!(u(a)||l(a,o)||g&&u(g,6)||"localhost"===a)||(a=a||g,o.host_whitelist&&!d(a,o.host_whitelist)||o.host_blacklist&&d(a,o.host_blacklist)))},isMACAddress:function(e){return t(e),Z.test(e)},isIP:u,isFQDN:l,isBoolean:function(e){return t(e),["true","false","1","0"].indexOf(e)>=0},isAlpha:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),o in O)return O[o].test(e);throw new Error("Invalid locale '"+o+"'")},isAlphanumeric:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),o in R)return R[o].test(e);throw new Error("Invalid locale '"+o+"'")},isNumeric:function(e){return t(e),P.test(e)},isLowercase:function(e){return t(e),e===e.toLowerCase()},isUppercase:function(e){return t(e),e===e.toUpperCase()},isAscii:function(e){return t(e),L.test(e)},isFullWidth:function(e){return t(e),N.test(e)},isHalfWidth:function(e){return t(e),B.test(e)},isVariableWidth:function(e){return t(e),N.test(e)&&B.test(e)},isMultibyte:function(e){return t(e),q.test(e)},isSurrogatePair:function(e){return t(e),T.test(e)},isInt:function(e,o){t(e);var r=(o=o||{}).hasOwnProperty("allow_leading_zeroes")&&!o.allow_leading_zeroes?H:K,i=!o.hasOwnProperty("min")||e>=o.min,n=!o.hasOwnProperty("max")||e<=o.max,l=!o.hasOwnProperty("lt")||eo.gt;return r.test(e)&&i&&n&&l&&a},isFloat:function(e,o){return t(e),o=o||{},""!==e&&"."!==e&&M.test(e)&&(!o.hasOwnProperty("min")||e>=o.min)&&(!o.hasOwnProperty("max")||e<=o.max)&&(!o.hasOwnProperty("lt")||eo.gt)},isDecimal:function(e){return t(e),""!==e&&W.test(e)},isHexadecimal:c,isDivisibleBy:function(e,r){return t(e),o(e)%parseInt(r,10)==0},isHexColor:function(e){return t(e),Y.test(e)},isISRC:function(e){return t(e),J.test(e)},isMD5:function(e){return t(e),Q.test(e)},isJSON:function(e){t(e);try{var o=JSON.parse(e);return!!o&&"object"===(void 0===o?"undefined":v(o))}catch(t){}return!1},isEmpty:function(e){return t(e),0===e.length},isLength:function(e,o){t(e);var r=void 0,i=void 0;"object"===(void 0===o?"undefined":v(o))?(r=o.min||0,i=o.max):(r=arguments[1],i=arguments[2]);var n=e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],l=e.length-n.length;return l>=r&&(void 0===i||l<=i)},isByteLength:n,isUUID:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all";t(e);var r=X[o];return r&&r.test(e)},isMongoId:function(e){return t(e),c(e)&&24===e.length},isAfter:function(o){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(o);var i=e(r),n=e(o);return!!(n&&i&&n>i)},isBefore:function(o){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(o);var i=e(r),n=e(o);return!!(n&&i&&n=0}return"object"===(void 0===o?"undefined":v(o))?o.hasOwnProperty(e):!(!o||"function"!=typeof o.indexOf)&&o.indexOf(e)>=0},isCreditCard:function(e){t(e);var o=e.replace(/[^0-9]+/g,"");if(!V.test(o))return!1;for(var r=0,i=void 0,n=void 0,l=void 0,a=o.length-1;a>=0;a--)i=o.substring(a,a+1),n=parseInt(i,10),r+=l&&(n*=2)>=10?n%10+1:n,l=!l;return!(r%10!=0||!o)},isISIN:function(e){if(t(e),!tt.test(e))return!1;for(var o=e.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),r=0,i=void 0,n=void 0,l=!0,a=o.length-2;a>=0;a--)i=o.substring(a,a+1),n=parseInt(i,10),r+=l&&(n*=2)>=10?n+1:n,l=!l;return parseInt(e.substr(e.length-1),10)===(1e4-r)%10},isISBN:f,isISSN:function(e){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(e);var r=it;if(r=o.require_hyphen?r.replace("?",""):r,!(r=o.case_sensitive?new RegExp(r):new RegExp(r,"i")).test(e))return!1;var i=e.replace("-",""),n=8,l=0,a=!0,u=!1,s=void 0;try{for(var d,c=i[Symbol.iterator]();!(a=(d=c.next()).done);a=!0){var f=d.value;l+=("X"===f.toUpperCase()?10:+f)*n,--n}}catch(t){u=!0,s=t}finally{try{!a&&c.return&&c.return()}finally{if(u)throw s}}return l%11==0},isMobilePhone:function(e,o){return t(e),o in nt?nt[o].test(e):"any"===o&&!!Object.values(nt).find(function(t){return t.test(e)})},isCurrency:function(e,o){return t(e),o=i(o,lt),p(o).test(e)},isISO8601:function(e){return t(e),at.test(e)},isBase64:function(e){t(e);var o=e.length;if(!o||o%4!=0||ut.test(e))return!1;var r=e.indexOf("=");return-1===r||r===o-1||r===o-2&&"="===e[o-1]},isDataURI:function(e){return t(e),st.test(e)},ltrim:g,rtrim:h,trim:function(t,e){return h(g(t,e),e)},escape:function(e){return t(e),e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(e){return t(e),e.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/`/g,"`")},stripLow:function(e,o){return t(e),m(e,o?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(e,o){return t(e),e.replace(new RegExp("[^"+o+"]+","g"),"")},blacklist:m,isWhitelisted:function(e,o){t(e);for(var r=e.length-1;r>=0;r--)if(-1===o.indexOf(e[r]))return!1;return!0},normalizeEmail:function(t,e){if(e=i(e,dt),!a(t))return!1;var o=t.split("@"),r=o.pop(),n=[o.join("@"),r];if(n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if(e.gmail_remove_subaddress&&(n[0]=n[0].split("+")[0]),e.gmail_remove_dots&&(n[0]=n[0].replace(/\./g,"")),!n[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(n[0]=n[0].toLowerCase()),n[1]=e.gmail_convert_googlemaildotcom?"gmail.com":n[1]}else if(~ct.indexOf(n[1])){if(e.icloud_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(n[0]=n[0].toLowerCase())}else if(~ft.indexOf(n[1])){if(e.outlookdotcom_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(n[0]=n[0].toLowerCase())}else if(~pt.indexOf(n[1])){if(e.yahoo_remove_subaddress){var l=n[0].split("-");n[0]=l.length>1?l.slice(0,-1).join("-"):l[0]}if(!n[0].length)return!1;(e.all_lowercase||e.yahoo_lowercase)&&(n[0]=n[0].toLowerCase())}else e.all_lowercase&&(n[0]=n[0].toLowerCase());return n.join("@")},toString:r}}); \ No newline at end of file