From 41ae944152e20bc2dd05c2089f7482d164be883d Mon Sep 17 00:00:00 2001 From: Mika Nikolai Sundland Date: Thu, 7 Sep 2017 23:33:22 +0200 Subject: [PATCH 1/4] Add remaining dutch diacritics to isAlpha and isAlphanumeric If some are there then we might as well have them all. --- lib/alpha.js | 4 +-- src/lib/alpha.js | 4 +-- test/validators.js | 38 +++++++++++++++++++++++ validator.js | 4 +-- validator.min.js | 76 +++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 119 insertions(+), 7 deletions(-) diff --git a/lib/alpha.js b/lib/alpha.js index 78eb1c832..d557bea61 100644 --- a/lib/alpha.js +++ b/lib/alpha.js @@ -12,7 +12,7 @@ var alpha = exports.alpha = { 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, 'nb-NO': /^[A-ZÆØÅ]+$/i, - 'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i, + 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i, 'nn-NO': /^[A-ZÆØÅ]+$/i, 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, @@ -35,7 +35,7 @@ var alphanumeric = exports.alphanumeric = { 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'nb-NO': /^[0-9A-ZÆØÅ]+$/i, - 'nl-NL': /^[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, diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 66566df0a..80dfe2c60 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -7,7 +7,7 @@ export const alpha = { 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, 'nb-NO': /^[A-ZÆØÅ]+$/i, - 'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i, + 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i, 'nn-NO': /^[A-ZÆØÅ]+$/i, 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, @@ -30,7 +30,7 @@ export const alphanumeric = { 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'nb-NO': /^[0-9A-ZÆØÅ]+$/i, - 'nl-NL': /^[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, diff --git a/test/validators.js b/test/validators.js index 3329389ee..22bb865d7 100644 --- a/test/validators.js +++ b/test/validators.js @@ -729,6 +729,25 @@ describe('Validators', function () { }); }); + it('should validate dutch alpha strings', function () { + test({ + validator: 'isAlpha', + args: ['nl-NL'], + valid: [ + 'Kán', + 'één', + 'vóór', + 'nú', + 'héél', + ], + invalid: [ + 'äca ', + 'abcß', + 'Øre', + ], + }); + }); + it('should validate german alpha strings', function () { test({ validator: 'isAlpha', @@ -989,6 +1008,25 @@ describe('Validators', function () { }); }); + it('should validate dutch alphanumeric strings', function () { + test({ + validator: 'isAlphanumeric', + args: ['nl-NL'], + valid: [ + 'Kán123', + 'één354', + 'v4óór', + 'nú234', + 'hé54él', + ], + invalid: [ + '1äca ', + 'ab3cß', + 'Øre', + ], + }); + }); + it('should validate german alphanumeric strings', function () { test({ validator: 'isAlphanumeric', diff --git a/validator.js b/validator.js index 8d634caf2..56c720d33 100644 --- a/validator.js +++ b/validator.js @@ -443,7 +443,7 @@ var alpha = { 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, 'nb-NO': /^[A-ZÆØÅ]+$/i, - 'nl-NL': /^[A-ZÉËÏÓÖÜ]+$/i, + 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i, 'nn-NO': /^[A-ZÆØÅ]+$/i, 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, @@ -466,7 +466,7 @@ var alphanumeric = { 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, 'nb-NO': /^[0-9A-ZÆØÅ]+$/i, - 'nl-NL': /^[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, diff --git a/validator.min.js b/validator.min.js index 6a976a09a..ef1968e43 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,78 @@ * 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,$)).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!!Z.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,x=/^[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,Z=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,S=/^[0-9A-F]{1,4}$/i,E={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},k=/^\[([^\]]+)\](?::([0-9]+))?$/,D=/^([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,"it-IT":/^[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:/^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},I={"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,"it-IT":/^[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ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},R=["AU","GB","HK","IN","NZ","ZA","ZM"],C=0;C=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,E);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(k);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),D.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 I)return I[r].test(e);throw new Error("Invalid locale '"+r+"'")},isNumeric:function(e){return t(e),U.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),z.test(e)},isFullWidth:function(e){return t(e),B.test(e)},isHalfWidth:function(e){return t(e),j.test(e)},isVariableWidth:function(e){return t(e),B.test(e)&&j.test(e)},isMultibyte:function(e){return t(e),T.test(e)},isSurrogatePair:function(e){return t(e),q.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&&G.test(e)},isHexadecimal:c,isDivisibleBy:function(e,o){return t(e),r(e)%parseInt(o,10)==0},isHexColor:function(e){return t(e),W.test(e)},isISRC:function(e){return t(e),X.test(e)},isMD5:function(e){return t(e),Y.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=V[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(!Q.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){for(var o in nt)if(nt.hasOwnProperty(o)&&nt[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isPostalCode:function(e,r){if(t(e),r in ht)return ht[r].test(e);if("any"===r){for(var o in ht)if(ht.hasOwnProperty(o)&&ht[o].test(e))return!0;return!1}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)},isLatLong:function(e){if(t(e),!e.includes(","))return!1;var r=e.split(",");return dt.test(r[0])&&ct.test(r[1])},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,"\\").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,mt),!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(~_t.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(~vt.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(~$t.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}/* eslint-disable prefer-rest-params */ +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):( +// backwards compatibility: isByteLength(str, min [, 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),/* Remove the optional trailing dot before checking validity */ +(r=i(r,$)).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; +// disallow spaces +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!!Z.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; +// initial or final :: +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})?"); +// ensure there's a dollar and/or decimal amount, and that +// it doesn't start with a space or a negative sign followed by a space +// default is negative sign before symbol, but there are two other options (besides parens) +// South African Rand, for example, uses R 123 (space) and R-123 (no space) +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,x=/^[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,Z=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,S=/^[0-9A-F]{1,4}$/i,E={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},k=/^\[([^\]]+)\](?::([0-9]+))?$/,D=/^([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,"it-IT":/^[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:/^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},I={"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,"it-IT":/^[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ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},R=["AU","GB","HK","IN","NZ","ZA","ZM"],C=0;C=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,E);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(k);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),D.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 I)return I[r].test(e);throw new Error("Invalid locale '"+r+"'")},isNumeric:function(e){return t(e),U.test(e)},isLowercase:function(e){return t(e),e===e.toLowerCase()},isUppercase:function(e){return t(e),e===e.toUpperCase()},isAscii:/* eslint-enable no-control-regex */ +function(e){return t(e),z.test(e)},isFullWidth:function(e){return t(e),B.test(e)},isHalfWidth:function(e){return t(e),j.test(e)},isVariableWidth:function(e){return t(e),B.test(e)&&j.test(e)},isMultibyte:/* eslint-enable no-control-regex */ +function(e){return t(e),T.test(e)},isSurrogatePair:function(e){return t(e),q.test(e)},isInt:function(e,r){t(e); +// Get the regex to use for testing, based on whether +// leading zeroes are allowed or not. +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&&G.test(e)},isHexadecimal:c,isDivisibleBy:function(e,o){return t(e),r(e)%parseInt(o,10)==0},isHexColor:function(e){return t(e),W.test(e)},isISRC:function(e){return t(e),X.test(e)},isMD5:function(e){return t(e),Y.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:/* eslint-disable prefer-rest-params */ +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):( +// backwards compatibility: isLength(str, min [, 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=V[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:/* eslint-enable max-len */ +function(e){t(e);var r=e.replace(/[- ]+/g,"");if(!Q.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){for(var o in nt)if(nt.hasOwnProperty(o)&&nt[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isPostalCode:function(e,r){if(t(e),r in ht)return ht[r].test(e);if("any"===r){for(var o in ht)if(ht.hasOwnProperty(o)&&ht[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isCurrency:function(e,r){return t(e),r=i(r,lt),p(r).test(e)},isISO8601:/* eslint-enable max-len */ +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:// eslint-disable-line max-len +function(e){return t(e),st.test(e)},isLatLong:function(e){if(t(e),!e.includes(","))return!1;var r=e.split(",");return dt.test(r[0])&&ct.test(r[1])},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,"\\").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,mt),!a(t))return!1;var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];if( +// The domain is always lowercased, as it's case-insensitive per RFC 1035 +n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if( +// Address is GMail +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(~_t.indexOf(n[1])){if( +// Address is iCloud +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(~vt.indexOf(n[1])){if( +// Address is Outlook.com +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(~$t.indexOf(n[1])){ +// Address is Yahoo +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&&( +// Any other address +n[0]=n[0].toLowerCase());return n.join("@")},toString:o}}); \ No newline at end of file From e96292667c04d0dc3cfc1ae0b7a2546d79bad0c2 Mon Sep 17 00:00:00 2001 From: Mika Nikolai Sundland Date: Thu, 7 Sep 2017 23:41:34 +0200 Subject: [PATCH 2/4] Fix and add some unit tests --- test/validators.js | 64 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/test/validators.js b/test/validators.js index 22bb865d7..5e5aab3ba 100644 --- a/test/validators.js +++ b/test/validators.js @@ -846,9 +846,30 @@ describe('Validators', function () { }); }); + it('should validate polish alpha strings', function () { + test({ + validator: 'isAlpha', + args: ['pl-PL'], + valid: [ + 'kreską', + 'zamknięte', + 'zwykłe', + 'kropką', + 'przyjęły', + 'święty', + 'Pozwól', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + it('should validate serbian cyrillic alpha strings', function () { test({ - validator: 'isAlphanumeric', + validator: 'isAlpha', args: ['sr-RS'], valid: [ 'ШћжЂљЕ', @@ -864,7 +885,7 @@ describe('Validators', function () { it('should validate serbian latin alpha strings', function () { test({ - validator: 'isAlphanumeric', + validator: 'isAlpha', args: ['sr-RS@latin'], valid: [ 'ŠAabčšđćž', @@ -878,6 +899,24 @@ describe('Validators', function () { }); }); + it('should validate spanish alpha strings', function () { + test({ + validator: 'isAlpha', + args: ['es-ES'], + valid: [ + 'ábcó', + 'ÁBCÓ', + 'dormís', + 'volvés', + 'español', + ], + invalid: [ + 'äca ', + 'abcß', + 'föö!!', + ], + }); + }); it('should validate defined arabic locales alpha strings', function () { test({ @@ -1151,6 +1190,27 @@ describe('Validators', function () { }); }); + it('should validate polish alphanumeric strings', function () { + test({ + validator: 'isAlphanumeric', + args: ['pl-PL'], + valid: [ + 'kre123ską', + 'zam21knięte', + 'zw23ykłe', + '123', + 'prz23yjęły', + 'świ23ęty', + 'Poz1322wól', + ], + invalid: [ + '12řiď ', + 'blé!!', + 'föö!2!', + ], + }); + }); + it('should validate serbian cyrillic alphanumeric strings', function () { test({ validator: 'isAlphanumeric', From ece5911eab7be0ffe88746cbb87898952b5ef929 Mon Sep 17 00:00:00 2001 From: Mika Nikolai Sundland Date: Thu, 7 Sep 2017 23:53:32 +0200 Subject: [PATCH 3/4] Add Swedish locale to isAlpha and isAlphanumeric --- lib/alpha.js | 2 ++ src/lib/alpha.js | 2 ++ test/validators.js | 36 ++++++++++++++++++++++++++++++++++++ validator.js | 2 ++ validator.min.js | 16 ++++++++-------- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/alpha.js b/lib/alpha.js index d557bea61..884b2f28f 100644 --- a/lib/alpha.js +++ b/lib/alpha.js @@ -20,6 +20,7 @@ var alpha = exports.alpha = { 'ru-RU': /^[А-ЯЁ]+$/i, 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i, 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i, + 'sv-SE': /^[A-ZÅÄÖ]+$/i, 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i, 'uk-UA': /^[А-ЩЬЮЯЄIЇҐ]+$/i, ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/ @@ -42,6 +43,7 @@ var alphanumeric = exports.alphanumeric = { 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i, 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i, + 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i, 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i, 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐ]+$/i, ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/ diff --git a/src/lib/alpha.js b/src/lib/alpha.js index 80dfe2c60..c41769152 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -15,6 +15,7 @@ export const alpha = { 'ru-RU': /^[А-ЯЁ]+$/i, 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i, 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i, + 'sv-SE': /^[A-ZÅÄÖ]+$/i, 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i, 'uk-UA': /^[А-ЩЬЮЯЄIЇҐ]+$/i, ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, @@ -37,6 +38,7 @@ export const alphanumeric = { 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i, 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i, + 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i, 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i, 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐ]+$/i, ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, diff --git a/test/validators.js b/test/validators.js index 5e5aab3ba..2ca4703b0 100644 --- a/test/validators.js +++ b/test/validators.js @@ -918,6 +918,24 @@ describe('Validators', function () { }); }); + it('should validate swedish alpha strings', function () { + test({ + validator: 'isAlpha', + args: ['sv-SE'], + valid: [ + 'religiös', + 'stjäla', + 'västgöte', + 'Åre', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'religiös23', + '', + ], + }); + }); + it('should validate defined arabic locales alpha strings', function () { test({ validator: 'isAlpha', @@ -1243,6 +1261,24 @@ describe('Validators', function () { }); }); + it('should validate swedish alphanumeric strings', function () { + test({ + validator: 'isAlphanumeric', + args: ['sv-SE'], + valid: [ + 'religiös13', + 'st23jäla', + 'västgöte123', + '123Åre', + ], + invalid: [ + 'AİıÖöÇ窺ĞğÜüZ', + 'foo!!', + '', + ], + }); + }); + it('should validate turkish alphanumeric strings', function () { test({ validator: 'isAlphanumeric', diff --git a/validator.js b/validator.js index 56c720d33..7e40f3bb3 100644 --- a/validator.js +++ b/validator.js @@ -451,6 +451,7 @@ var alpha = { 'ru-RU': /^[А-ЯЁ]+$/i, 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i, 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i, + 'sv-SE': /^[A-ZÅÄÖ]+$/i, 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i, 'uk-UA': /^[А-ЩЬЮЯЄIЇҐ]+$/i, ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/ @@ -473,6 +474,7 @@ var alphanumeric = { 'ru-RU': /^[0-9А-ЯЁ]+$/i, 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i, 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i, + 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i, 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i, 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐ]+$/i, ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/ diff --git a/validator.min.js b/validator.min.js index ef1968e43..32d0e8d7a 100644 --- a/validator.min.js +++ b/validator.min.js @@ -30,19 +30,19 @@ if(/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(n))return!1}for( // disallow full-width chars if(/[\uff01-\uff5e]/.test(l))return!1;if("-"===l[0]||"-"===l[l.length-1])return!1}return!0}/* eslint-enable max-len */ /* eslint-enable no-control-regex */ -function a(e,r){if(t(e),(r=i(r,F)).require_display_name||r.allow_display_name){var o=e.match(A);if(o)e=o[1];else if(r.require_display_name)return!1}var a=e.split("@"),u=a.pop(),s=a.join("@"),d=u.toLowerCase();if("gmail.com"!==d&&"googlemail.com"!==d||(s=s.replace(/\./g,"").toLowerCase()),!n(s,{max:64})||!n(u,{max:254}))return!1;if(!l(u,{require_tld:r.require_tld}))return!1;if('"'===s[0])return s=s.slice(1,s.length-1),r.allow_utf8_local_part?b.test(s):w.test(s);for(var c=r.allow_utf8_local_part?y:x,f=s.split("."),p=0;p1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(r=String(r)))return u(e,4)||u(e,6);if("4"===r)return!!Z.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; +function a(e,r){if(t(e),(r=i(r,F)).require_display_name||r.allow_display_name){var o=e.match(A);if(o)e=o[1];else if(r.require_display_name)return!1}var a=e.split("@"),s=a.pop(),u=a.join("@"),d=s.toLowerCase();if("gmail.com"!==d&&"googlemail.com"!==d||(u=u.replace(/\./g,"").toLowerCase()),!n(u,{max:64})||!n(s,{max:254}))return!1;if(!l(s,{require_tld:r.require_tld}))return!1;if('"'===u[0])return u=u.slice(1,u.length-1),r.allow_utf8_local_part?b.test(u):w.test(u);for(var c=r.allow_utf8_local_part?y:x,f=u.split("."),p=0;p1&&void 0!==arguments[1]?arguments[1]:"";if(t(e),!(r=String(r)))return s(e,4)||s(e,6);if("4"===r)return!!Z.test(e)&&e.split(".").sort(function(t,e){return t-e})[3]<=255;if("6"===r){var o=e.split(":"),i=!1,n=s(o[o.length-1],4),l=n?7:8;if(o.length>l)return!1; // initial or final :: 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})?"); +if(""===o[a]&&a>0&&a=1:o.length===l}return!1}function u(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})?"); // ensure there's a dollar and/or decimal amount, and that // it doesn't start with a space or a negative sign followed by a space // default is negative sign before symbol, but there are two other options (besides parens) // South African Rand, for example, uses R 123 (space) and R-123 (no space) -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,x=/^[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,Z=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,S=/^[0-9A-F]{1,4}$/i,E={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},k=/^\[([^\]]+)\](?::([0-9]+))?$/,D=/^([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,"it-IT":/^[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:/^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},I={"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,"it-IT":/^[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ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},R=["AU","GB","HK","IN","NZ","ZA","ZM"],C=0;C=0&&o.test(e[i]);)i--;return i$/i,x=/^[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,Z=/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/,S=/^[0-9A-F]{1,4}$/i,E={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},k=/^\[([^\]]+)\](?::([0-9]+))?$/,D=/^([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,"it-IT":/^[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,"sv-SE":/^[A-ZÅÄÖ]+$/i,"tr-TR":/^[A-ZÇĞİıÖŞÜ]+$/i,"uk-UA":/^[А-ЩЬЮЯЄIЇҐ]+$/i,ar:/^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},I={"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,"it-IT":/^[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,"sv-SE":/^[0-9A-ZÅÄÖ]+$/i,"tr-TR":/^[0-9A-ZÇĞİıÖŞÜ]+$/i,"uk-UA":/^[0-9А-ЩЬЮЯЄIЇҐ]+$/i,ar:/^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/},R=["AU","GB","HK","IN","NZ","ZA","ZM"],C=0;C=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,E);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(k);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),D.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 I)return I[r].test(e);throw new Error("Invalid locale '"+r+"'")},isNumeric:function(e){return t(e),U.test(e)},isLowercase:function(e){return t(e),e===e.toLowerCase()},isUppercase:function(e){return t(e),e===e.toUpperCase()},isAscii:/* eslint-enable no-control-regex */ +icloud_remove_subaddress:!0},_t=["icloud.com","me.com"],vt=["hotmail.at","hotmail.be","hotmail.ca","hotmail.cl","hotmail.co.il","hotmail.co.nz","hotmail.co.th","hotmail.co.uk","hotmail.com","hotmail.com.ar","hotmail.com.au","hotmail.com.br","hotmail.com.gr","hotmail.com.mx","hotmail.com.pe","hotmail.com.tr","hotmail.com.vn","hotmail.cz","hotmail.de","hotmail.dk","hotmail.es","hotmail.fr","hotmail.hu","hotmail.id","hotmail.ie","hotmail.in","hotmail.it","hotmail.jp","hotmail.kr","hotmail.lv","hotmail.my","hotmail.ph","hotmail.pt","hotmail.sa","hotmail.sg","hotmail.sk","live.be","live.co.uk","live.com","live.com.ar","live.com.mx","live.de","live.es","live.eu","live.fr","live.it","live.nl","msn.com","outlook.at","outlook.be","outlook.cl","outlook.co.il","outlook.co.nz","outlook.co.th","outlook.com","outlook.com.ar","outlook.com.au","outlook.com.br","outlook.com.gr","outlook.com.pe","outlook.com.tr","outlook.com.vn","outlook.cz","outlook.de","outlook.dk","outlook.es","outlook.fr","outlook.hu","outlook.id","outlook.ie","outlook.in","outlook.it","outlook.jp","outlook.kr","outlook.lv","outlook.my","outlook.ph","outlook.pt","outlook.sa","outlook.sg","outlook.sk","passport.com"],$t=["rocketmail.com","yahoo.ca","yahoo.co.uk","yahoo.com","yahoo.de","yahoo.fr","yahoo.in","yahoo.it","ymail.com"];return{version:"8.1.0",toDate:e,toFloat:r,toInt:function(e,r){return t(e),parseInt(e,r||10)},toBoolean:function(e,r){return t(e),r?"1"===e||"true"===e:"0"!==e&&"false"!==e&&""!==e},equals:function(e,r){return t(e),e===r},contains:function(e,r){return t(e),e.indexOf(o(r))>=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,E);var o=void 0,n=void 0,a=void 0,u=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=(u=p.join("@")).match(k);return h?(a="",g=h[1],f=h[2]||null):(a=(p=u.split(":")).shift(),p.length&&(f=p.join(":"))),!(null!==f&&(c=parseInt(f,10),!/^[0-9]+$/.test(f)||c<=0||c>65535)||!(s(a)||l(a,r)||g&&s(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),D.test(e)},isIP:s,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 I)return I[r].test(e);throw new Error("Invalid locale '"+r+"'")},isNumeric:function(e){return t(e),U.test(e)},isLowercase:function(e){return t(e),e===e.toLowerCase()},isUppercase:function(e){return t(e),e===e.toUpperCase()},isAscii:/* eslint-enable no-control-regex */ function(e){return t(e),z.test(e)},isFullWidth:function(e){return t(e),B.test(e)},isHalfWidth:function(e){return t(e),j.test(e)},isVariableWidth:function(e){return t(e),B.test(e)&&j.test(e)},isMultibyte:/* eslint-enable no-control-regex */ function(e){return t(e),T.test(e)},isSurrogatePair:function(e){return t(e),q.test(e)},isInt:function(e,r){t(e); // Get the regex to use for testing, based on whether @@ -80,9 +80,9 @@ var o=(r=r||{}).hasOwnProperty("allow_leading_zeroes")&&!r.allow_leading_zeroes? 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):( // backwards compatibility: isLength(str, min [, 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=V[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:/* eslint-enable max-len */ -function(e){t(e);var r=e.replace(/[- ]+/g,"");if(!Q.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){for(var o in nt)if(nt.hasOwnProperty(o)&&nt[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isPostalCode:function(e,r){if(t(e),r in ht)return ht[r].test(e);if("any"===r){for(var o in ht)if(ht.hasOwnProperty(o)&&ht[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isCurrency:function(e,r){return t(e),r=i(r,lt),p(r).test(e)},isISO8601:/* eslint-enable max-len */ -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:// eslint-disable-line max-len -function(e){return t(e),st.test(e)},isLatLong:function(e){if(t(e),!e.includes(","))return!1;var r=e.split(",");return dt.test(r[0])&&ct.test(r[1])},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,"\\").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,mt),!a(t))return!1;var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];if( +function(e){t(e);var r=e.replace(/[- ]+/g,"");if(!Q.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,s=!1,u=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){s=!0,u=t}finally{try{!a&&c.return&&c.return()}finally{if(s)throw u}}return l%11==0},isMobilePhone:function(e,r){if(t(e),r in nt)return nt[r].test(e);if("any"===r){for(var o in nt)if(nt.hasOwnProperty(o)&&nt[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isPostalCode:function(e,r){if(t(e),r in ht)return ht[r].test(e);if("any"===r){for(var o in ht)if(ht.hasOwnProperty(o)&&ht[o].test(e))return!0;return!1}throw new Error("Invalid locale '"+r+"'")},isCurrency:function(e,r){return t(e),r=i(r,lt),p(r).test(e)},isISO8601:/* eslint-enable max-len */ +function(e){return t(e),at.test(e)},isBase64:function(e){t(e);var r=e.length;if(!r||r%4!=0||st.test(e))return!1;var o=e.indexOf("=");return-1===o||o===r-1||o===r-2&&"="===e[r-1]},isDataURI:// eslint-disable-line max-len +function(e){return t(e),ut.test(e)},isLatLong:function(e){if(t(e),!e.includes(","))return!1;var r=e.split(",");return dt.test(r[0])&&ct.test(r[1])},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,"\\").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,mt),!a(t))return!1;var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];if( // The domain is always lowercased, as it's case-insensitive per RFC 1035 n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if( // Address is GMail From 0612485a3c561d6de463665259af1420492131b5 Mon Sep 17 00:00:00 2001 From: Mika Nikolai Sundland Date: Thu, 7 Sep 2017 23:53:32 +0200 Subject: [PATCH 4/4] Add Swedish locale to isAlpha and isAlphanumeric --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb5d893ae..c23a37604 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,8 @@ validator | description ***contains(str, seed)*** | check if the string contains the seed. **equals(str, comparison)** | check if the string matches the comparison. **isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to now). -**isAlpha(str [, locale])** | check if the string contains only letters (a-zA-Z).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. -**isAlphanumeric(str [, locale])** | check if the string contains only letters and numbers.

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. +**isAlpha(str [, locale])** | check if the string contains only letters (a-zA-Z).

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. +**isAlphanumeric(str [, locale])** | check if the string contains only letters and numbers.

Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. **isAscii(str)** | check if the string contains ASCII chars only. **isBase64(str)** | check if a string is base64 encoded. **isBefore(str [, date])** | check if the string is a date that's before the specified date.