From bd4fe97017cb38bd2f3518ed9590c8618190c177 Mon Sep 17 00:00:00 2001 From: Tyler DeVos Date: Fri, 1 Jun 2018 16:09:07 -0500 Subject: [PATCH 1/2] Fix isMobilePhone regex to allow for ###-###-#### format --- lib/isMobilePhone.js | 2 +- src/lib/isMobilePhone.js | 2 +- validator.js | 2 +- validator.min.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/isMobilePhone.js b/lib/isMobilePhone.js index ce59064d3..9b26703d0 100644 --- a/lib/isMobilePhone.js +++ b/lib/isMobilePhone.js @@ -16,7 +16,7 @@ var phones = { 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, - 'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/, + 'en-US': /^(\+?1)?[2-9]\d{2}(-?)[2-9](?!11)\d{2}\2\d{4}$/, 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, 'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/, 'da-DK': /^(\+?45)?(\d{8})$/, diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 120f1c0e0..51b64227c 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -5,7 +5,7 @@ const phones = { 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, - 'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/, + 'en-US': /^(\+?1)?[2-9]\d{2}(-?)[2-9](?!11)\d{2}\2\d{4}$/, 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, 'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/, 'da-DK': /^(\+?45)?(\d{8})$/, diff --git a/validator.js b/validator.js index b381288da..3d4aeb618 100644 --- a/validator.js +++ b/validator.js @@ -899,7 +899,7 @@ var phones = { 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, - 'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/, + 'en-US': /^(\+?1)?[2-9]\d{2}(-?)[2-9](?!11)\d{2}\2\d{4}$/, 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, 'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/, 'da-DK': /^(\+?45)?(\d{8})$/, diff --git a/validator.min.js b/validator.min.js index 1282ba839..0ed747663 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 r(e){return t(e),parseFloat(e)}function o(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 r in e)void 0===t[r]&&(t[r]=e[r]);return t}function n(e,r){t(e);var o=void 0,i=void 0;"object"===(void 0===r?"undefined":v(r))?(o=r.min||0,i=r.max):(o=arguments[1],i=arguments[2]);var n=encodeURI(e).split(/%..|./).length-1;return n>=o&&(void 0===i||n<=i)}function l(e,r){t(e),(r=i(r,F)).allow_trailing_dot&&"."===e[e.length-1]&&(e=e.substring(0,e.length-1));var o=e.split(".");if(r.require_tld){var n=o.pop();if(!o.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(n))return!1;if(/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(n))return!1}for(var l,a=0;a1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(r=String(r)))return u(e,4)||u(e,6);if("4"===r)return!!k.test(e)&&e.split(".").sort(function(t,e){return t-e})[3]<=255;if("6"===r){var o=e.split(":"),i=!1,n=u(o[o.length-1],4),l=n?7:8;if(o.length>l)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(o.shift(),o.shift(),i=!0):"::"===e.substr(e.length-2)&&(o.pop(),o.pop(),i=!0);for(var a=0;a0&&a=1:o.length===l}return!1}function s(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function d(t,e){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(r=String(r)))return f(e,10)||f(e,13);var o=e.replace(/[\s-]+/g,""),i=0,n=void 0;if("10"===r){if(!et.test(o))return!1;for(n=0;n<9;n++)i+=(n+1)*o.charAt(n);if("X"===o.charAt(9)?i+=100:i+=10*o.charAt(9),i%11==0)return!!o}else if("13"===r){if(!rt.test(o))return!1;for(n=0;n<12;n++)i+=ot[n%2]*o.charAt(n);if(o.charAt(12)-(10-i%10)%10==0)return!!o}return!1}function p(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="("+["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?r+="-?":t.negative_sign_before_digits&&(r="-?"+r)),t.allow_negative_sign_placeholder?r="( (?!\\-))?"+r:t.allow_space_after_symbol?r=" ?"+r:t.allow_space_after_digits&&(r+="( (?!$))?"),t.symbol_after_digits?r+=e:r=e+r,t.allow_negatives&&(t.parens_for_negatives?r="(\\("+r+"\\)|"+r+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(r="-?"+r)),new RegExp("^(?!-? )(?=.*\\d)"+r+"$")}function g(e,r){t(e);var o=r?new RegExp("^["+r+"]+","g"):/^\s+/g;return e.replace(o,"")}function h(e,r){t(e);for(var o=r?new RegExp("["+r+"]"):/\s/,i=e.length-1;i>=0&&o.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})$/,D=/^[0-9A-F]{1,4}$/i,S={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,r,o){return t(e),"[object RegExp]"!==Object.prototype.toString.call(r)&&(r=new RegExp(r,o)),r.test(e)},isEmail:a,isURL:function(e,r){if(t(e),!e||e.length>=2083||/[\s<>]/.test(e))return!1;if(0===e.indexOf("mailto:"))return!1;r=i(r,S);var o=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(o=p.shift(),r.require_valid_protocol&&-1===r.protocols.indexOf(o))return!1}else{if(r.require_protocol)return!1;r.allow_protocol_relative_urls&&"//"===e.substr(0,2)&&(p[0]=e.substr(2))}if(""===(e=p.join("://")))return!1;if(p=e.split("/"),""===(e=p.shift())&&!r.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,r)||g&&u(g,6))||(a=a||g,r.host_whitelist&&!d(a,r.host_whitelist)||r.host_blacklist&&d(a,r.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 r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),r in O)return O[r].test(e);throw new Error("Invalid locale '"+r+"'")},isAlphanumeric:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),r in R)return R[r].test(e);throw new Error("Invalid locale '"+r+"'")},isNumeric:function(e){return t(e),B.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),P.test(e)},isFullWidth:function(e){return t(e),L.test(e)},isHalfWidth:function(e){return t(e),N.test(e)},isVariableWidth:function(e){return t(e),L.test(e)&&N.test(e)},isMultibyte:function(e){return t(e),q.test(e)},isSurrogatePair:function(e){return t(e),T.test(e)},isInt:function(e,r){t(e);var o=(r=r||{}).hasOwnProperty("allow_leading_zeroes")&&!r.allow_leading_zeroes?H:K,i=!r.hasOwnProperty("min")||e>=r.min,n=!r.hasOwnProperty("max")||e<=r.max,l=!r.hasOwnProperty("lt")||er.gt;return o.test(e)&&i&&n&&l&&a},isFloat:function(e,r){return t(e),r=r||{},""!==e&&"."!==e&&M.test(e)&&(!r.hasOwnProperty("min")||e>=r.min)&&(!r.hasOwnProperty("max")||e<=r.max)&&(!r.hasOwnProperty("lt")||er.gt)},isDecimal:function(e){return t(e),""!==e&&W.test(e)},isHexadecimal:c,isDivisibleBy:function(e,o){return t(e),r(e)%parseInt(o,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 r=JSON.parse(e);return!!r&&"object"===(void 0===r?"undefined":v(r))}catch(t){}return!1},isEmpty:function(e){return t(e),0===e.length},isLength:function(e,r){t(e);var o=void 0,i=void 0;"object"===(void 0===r?"undefined":v(r))?(o=r.min||0,i=r.max):(o=arguments[1],i=arguments[2]);var n=e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],l=e.length-n.length;return l>=o&&(void 0===i||l<=i)},isByteLength:n,isUUID:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all";t(e);var o=X[r];return o&&o.test(e)},isMongoId:function(e){return t(e),c(e)&&24===e.length},isAfter:function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(r);var i=e(o),n=e(r);return!!(n&&i&&n>i)},isBefore:function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(r);var i=e(o),n=e(r);return!!(n&&i&&n=0}return"object"===(void 0===r?"undefined":v(r))?r.hasOwnProperty(e):!(!r||"function"!=typeof r.indexOf)&&r.indexOf(e)>=0},isCreditCard:function(e){t(e);var r=e.replace(/[- ]+/g,"");if(!V.test(r))return!1;for(var o=0,i=void 0,n=void 0,l=void 0,a=r.length-1;a>=0;a--)i=r.substring(a,a+1),n=parseInt(i,10),o+=l&&(n*=2)>=10?n%10+1:n,l=!l;return!(o%10!=0||!r)},isISIN:function(e){if(t(e),!tt.test(e))return!1;for(var r=e.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),o=0,i=void 0,n=void 0,l=!0,a=r.length-2;a>=0;a--)i=r.substring(a,a+1),n=parseInt(i,10),o+=l&&(n*=2)>=10?n+1:n,l=!l;return parseInt(e.substr(e.length-1),10)===(1e4-o)%10},isISBN:f,isISSN:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(e);var o=it;if(o=r.require_hyphen?o.replace("?",""):o,!(o=r.case_sensitive?new RegExp(o):new RegExp(o,"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,r){if(t(e),r in nt)return nt[r].test(e);if("any"===r)return!!Object.values(nt).find(function(t){return t.test(e)});throw new Error("Invalid locale '"+r+"'")},isCurrency:function(e,r){return t(e),r=i(r,lt),p(r).test(e)},isISO8601:function(e){return t(e),at.test(e)},isBase64:function(e){t(e);var r=e.length;if(!r||r%4!=0||ut.test(e))return!1;var o=e.indexOf("=");return-1===o||o===r-1||o===r-2&&"="===e[r-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,r){return t(e),m(e,r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(e,r){return t(e),e.replace(new RegExp("[^"+r+"]+","g"),"")},blacklist:m,isWhitelisted:function(e,r){t(e);for(var o=e.length-1;o>=0;o--)if(-1===r.indexOf(e[o]))return!1;return!0},normalizeEmail:function(t,e){if(e=i(e,dt),!a(t))return!1;var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];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:o}}); \ 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 r(e){return t(e),parseFloat(e)}function o(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 r in e)void 0===t[r]&&(t[r]=e[r]);return t}function n(e,r){t(e);var o=void 0,i=void 0;"object"===(void 0===r?"undefined":v(r))?(o=r.min||0,i=r.max):(o=arguments[1],i=arguments[2]);var n=encodeURI(e).split(/%..|./).length-1;return n>=o&&(void 0===i||n<=i)}function l(e,r){t(e),(r=i(r,F)).allow_trailing_dot&&"."===e[e.length-1]&&(e=e.substring(0,e.length-1));var o=e.split(".");if(r.require_tld){var n=o.pop();if(!o.length||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(n))return!1;if(/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(n))return!1}for(var l,a=0;a1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(r=String(r)))return u(e,4)||u(e,6);if("4"===r)return!!k.test(e)&&e.split(".").sort(function(t,e){return t-e})[3]<=255;if("6"===r){var o=e.split(":"),i=!1,n=u(o[o.length-1],4),l=n?7:8;if(o.length>l)return!1;if("::"===e)return!0;"::"===e.substr(0,2)?(o.shift(),o.shift(),i=!0):"::"===e.substr(e.length-2)&&(o.pop(),o.pop(),i=!0);for(var a=0;a0&&a=1:o.length===l}return!1}function s(t){return"[object RegExp]"===Object.prototype.toString.call(t)}function d(t,e){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(r=String(r)))return f(e,10)||f(e,13);var o=e.replace(/[\s-]+/g,""),i=0,n=void 0;if("10"===r){if(!et.test(o))return!1;for(n=0;n<9;n++)i+=(n+1)*o.charAt(n);if("X"===o.charAt(9)?i+=100:i+=10*o.charAt(9),i%11==0)return!!o}else if("13"===r){if(!rt.test(o))return!1;for(n=0;n<12;n++)i+=ot[n%2]*o.charAt(n);if(o.charAt(12)-(10-i%10)%10==0)return!!o}return!1}function p(t){var e="(\\"+t.symbol.replace(/\./g,"\\.")+")"+(t.require_symbol?"":"?"),r="("+["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?r+="-?":t.negative_sign_before_digits&&(r="-?"+r)),t.allow_negative_sign_placeholder?r="( (?!\\-))?"+r:t.allow_space_after_symbol?r=" ?"+r:t.allow_space_after_digits&&(r+="( (?!$))?"),t.symbol_after_digits?r+=e:r=e+r,t.allow_negatives&&(t.parens_for_negatives?r="(\\("+r+"\\)|"+r+")":t.negative_sign_before_digits||t.negative_sign_after_digits||(r="-?"+r)),new RegExp("^(?!-? )(?=.*\\d)"+r+"$")}function g(e,r){t(e);var o=r?new RegExp("^["+r+"]+","g"):/^\s+/g;return e.replace(o,"")}function h(e,r){t(e);for(var o=r?new RegExp("["+r+"]"):/\s/,i=e.length-1;i>=0&&o.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})$/,Z=/^[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},S=/^\[([^\]]+)\](?::([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,"nb-NO":/^[A-ZÆØÅ]+$/i,"nl-NL":/^[A-ZÉËÏÓÖÜ]+$/i,"nn-NO":/^[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,"nb-NO":/^[0-9A-ZÆØÅ]+$/i,"nl-NL":/^[0-9A-ZÉËÏÓÖÜ]+$/i,"nn-NO":/^[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,r,o){return t(e),"[object RegExp]"!==Object.prototype.toString.call(r)&&(r=new RegExp(r,o)),r.test(e)},isEmail:a,isURL:function(e,r){if(t(e),!e||e.length>=2083||/[\s<>]/.test(e))return!1;if(0===e.indexOf("mailto:"))return!1;r=i(r,D);var o=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(o=p.shift(),r.require_valid_protocol&&-1===r.protocols.indexOf(o))return!1}else{if(r.require_protocol)return!1;r.allow_protocol_relative_urls&&"//"===e.substr(0,2)&&(p[0]=e.substr(2))}if(""===(e=p.join("://")))return!1;if(p=e.split("/"),""===(e=p.shift())&&!r.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(S);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,r)||g&&u(g,6))||(a=a||g,r.host_whitelist&&!d(a,r.host_whitelist)||r.host_blacklist&&d(a,r.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 r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),r in O)return O[r].test(e);throw new Error("Invalid locale '"+r+"'")},isAlphanumeric:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en-US";if(t(e),r in R)return R[r].test(e);throw new Error("Invalid locale '"+r+"'")},isNumeric:function(e){return t(e),z.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),B.test(e)},isFullWidth:function(e){return t(e),P.test(e)},isHalfWidth:function(e){return t(e),L.test(e)},isVariableWidth:function(e){return t(e),P.test(e)&&L.test(e)},isMultibyte:function(e){return t(e),q.test(e)},isSurrogatePair:function(e){return t(e),T.test(e)},isInt:function(e,r){t(e);var o=(r=r||{}).hasOwnProperty("allow_leading_zeroes")&&!r.allow_leading_zeroes?H:K,i=!r.hasOwnProperty("min")||e>=r.min,n=!r.hasOwnProperty("max")||e<=r.max,l=!r.hasOwnProperty("lt")||er.gt;return o.test(e)&&i&&n&&l&&a},isFloat:function(e,r){return t(e),r=r||{},""!==e&&"."!==e&&M.test(e)&&(!r.hasOwnProperty("min")||e>=r.min)&&(!r.hasOwnProperty("max")||e<=r.max)&&(!r.hasOwnProperty("lt")||er.gt)},isDecimal:function(e){return t(e),""!==e&&W.test(e)},isHexadecimal:c,isDivisibleBy:function(e,o){return t(e),r(e)%parseInt(o,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 r=JSON.parse(e);return!!r&&"object"===(void 0===r?"undefined":v(r))}catch(t){}return!1},isEmpty:function(e){return t(e),0===e.length},isLength:function(e,r){t(e);var o=void 0,i=void 0;"object"===(void 0===r?"undefined":v(r))?(o=r.min||0,i=r.max):(o=arguments[1],i=arguments[2]);var n=e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],l=e.length-n.length;return l>=o&&(void 0===i||l<=i)},isByteLength:n,isUUID:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all";t(e);var o=X[r];return o&&o.test(e)},isMongoId:function(e){return t(e),c(e)&&24===e.length},isAfter:function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(r);var i=e(o),n=e(r);return!!(n&&i&&n>i)},isBefore:function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:String(new Date);t(r);var i=e(o),n=e(r);return!!(n&&i&&n=0}return"object"===(void 0===r?"undefined":v(r))?r.hasOwnProperty(e):!(!r||"function"!=typeof r.indexOf)&&r.indexOf(e)>=0},isCreditCard:function(e){t(e);var r=e.replace(/[- ]+/g,"");if(!V.test(r))return!1;for(var o=0,i=void 0,n=void 0,l=void 0,a=r.length-1;a>=0;a--)i=r.substring(a,a+1),n=parseInt(i,10),o+=l&&(n*=2)>=10?n%10+1:n,l=!l;return!(o%10!=0||!r)},isISIN:function(e){if(t(e),!tt.test(e))return!1;for(var r=e.replace(/[A-Z]/g,function(t){return parseInt(t,36)}),o=0,i=void 0,n=void 0,l=!0,a=r.length-2;a>=0;a--)i=r.substring(a,a+1),n=parseInt(i,10),o+=l&&(n*=2)>=10?n+1:n,l=!l;return parseInt(e.substr(e.length-1),10)===(1e4-o)%10},isISBN:f,isISSN:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(e);var o=it;if(o=r.require_hyphen?o.replace("?",""):o,!(o=r.case_sensitive?new RegExp(o):new RegExp(o,"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,r){if(t(e),r in nt)return nt[r].test(e);if("any"===r)return!!Object.values(nt).find(function(t){return t.test(e)});throw new Error("Invalid locale '"+r+"'")},isCurrency:function(e,r){return t(e),r=i(r,lt),p(r).test(e)},isISO8601:function(e){return t(e),at.test(e)},isBase64:function(e){t(e);var r=e.length;if(!r||r%4!=0||ut.test(e))return!1;var o=e.indexOf("=");return-1===o||o===r-1||o===r-2&&"="===e[r-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,r){return t(e),m(e,r?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(e,r){return t(e),e.replace(new RegExp("[^"+r+"]+","g"),"")},blacklist:m,isWhitelisted:function(e,r){t(e);for(var o=e.length-1;o>=0;o--)if(-1===r.indexOf(e[o]))return!1;return!0},normalizeEmail:function(t,e){if(e=i(e,dt),!a(t))return!1;var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];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:o}}); \ No newline at end of file From daab91f4fd11ce04f62ba25dc0501ed2e3d6fb92 Mon Sep 17 00:00:00 2001 From: Tyler DeVos Date: Fri, 6 Jul 2018 16:16:59 -0500 Subject: [PATCH 2/2] Added test case for regex to allow for ###-###-#### --- test/validators.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/validators.js b/test/validators.js index 22d8ab61e..f1bb3d26a 100644 --- a/test/validators.js +++ b/test/validators.js @@ -3567,6 +3567,7 @@ describe('Validators', () => { '19876543210', '8005552222', '+15673628910', + '800-555-2222', ], invalid: [ '564785',