validator.js 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095
  1. /*!
  2. * Copyright (c) 2018 Chris O'Hara <cohara87@gmail.com>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. (function (global, factory) {
  24. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  25. typeof define === 'function' && define.amd ? define(factory) :
  26. (global.validator = factory());
  27. }(this, (function () { 'use strict';
  28. function _typeof(obj) {
  29. "@babel/helpers - typeof";
  30. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  31. _typeof = function (obj) {
  32. return typeof obj;
  33. };
  34. } else {
  35. _typeof = function (obj) {
  36. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  37. };
  38. }
  39. return _typeof(obj);
  40. }
  41. function _slicedToArray(arr, i) {
  42. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  43. }
  44. function _toConsumableArray(arr) {
  45. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  46. }
  47. function _arrayWithoutHoles(arr) {
  48. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  49. }
  50. function _arrayWithHoles(arr) {
  51. if (Array.isArray(arr)) return arr;
  52. }
  53. function _iterableToArray(iter) {
  54. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  55. }
  56. function _iterableToArrayLimit(arr, i) {
  57. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  58. var _arr = [];
  59. var _n = true;
  60. var _d = false;
  61. var _e = undefined;
  62. try {
  63. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  64. _arr.push(_s.value);
  65. if (i && _arr.length === i) break;
  66. }
  67. } catch (err) {
  68. _d = true;
  69. _e = err;
  70. } finally {
  71. try {
  72. if (!_n && _i["return"] != null) _i["return"]();
  73. } finally {
  74. if (_d) throw _e;
  75. }
  76. }
  77. return _arr;
  78. }
  79. function _unsupportedIterableToArray(o, minLen) {
  80. if (!o) return;
  81. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  82. var n = Object.prototype.toString.call(o).slice(8, -1);
  83. if (n === "Object" && o.constructor) n = o.constructor.name;
  84. if (n === "Map" || n === "Set") return Array.from(o);
  85. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  86. }
  87. function _arrayLikeToArray(arr, len) {
  88. if (len == null || len > arr.length) len = arr.length;
  89. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  90. return arr2;
  91. }
  92. function _nonIterableSpread() {
  93. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  94. }
  95. function _nonIterableRest() {
  96. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  97. }
  98. function _createForOfIteratorHelper(o, allowArrayLike) {
  99. var it;
  100. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  101. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  102. if (it) o = it;
  103. var i = 0;
  104. var F = function () {};
  105. return {
  106. s: F,
  107. n: function () {
  108. if (i >= o.length) return {
  109. done: true
  110. };
  111. return {
  112. done: false,
  113. value: o[i++]
  114. };
  115. },
  116. e: function (e) {
  117. throw e;
  118. },
  119. f: F
  120. };
  121. }
  122. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  123. }
  124. var normalCompletion = true,
  125. didErr = false,
  126. err;
  127. return {
  128. s: function () {
  129. it = o[Symbol.iterator]();
  130. },
  131. n: function () {
  132. var step = it.next();
  133. normalCompletion = step.done;
  134. return step;
  135. },
  136. e: function (e) {
  137. didErr = true;
  138. err = e;
  139. },
  140. f: function () {
  141. try {
  142. if (!normalCompletion && it.return != null) it.return();
  143. } finally {
  144. if (didErr) throw err;
  145. }
  146. }
  147. };
  148. }
  149. function assertString(input) {
  150. var isString = typeof input === 'string' || input instanceof String;
  151. if (!isString) {
  152. var invalidType = _typeof(input);
  153. if (input === null) invalidType = 'null';else if (invalidType === 'object') invalidType = input.constructor.name;
  154. throw new TypeError("Expected a string but received a ".concat(invalidType));
  155. }
  156. }
  157. function toDate(date) {
  158. assertString(date);
  159. date = Date.parse(date);
  160. return !isNaN(date) ? new Date(date) : null;
  161. }
  162. var alpha = {
  163. 'en-US': /^[A-Z]+$/i,
  164. 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
  165. 'bg-BG': /^[А-Я]+$/i,
  166. 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  167. 'da-DK': /^[A-ZÆØÅ]+$/i,
  168. 'de-DE': /^[A-ZÄÖÜß]+$/i,
  169. 'el-GR': /^[Α-ώ]+$/i,
  170. 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
  171. 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i,
  172. 'fi-FI': /^[A-ZÅÄÖ]+$/i,
  173. 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  174. 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
  175. 'nb-NO': /^[A-ZÆØÅ]+$/i,
  176. 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
  177. 'nn-NO': /^[A-ZÆØÅ]+$/i,
  178. 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  179. 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  180. 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  181. 'ru-RU': /^[А-ЯЁ]+$/i,
  182. 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
  183. 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  184. 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
  185. 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i,
  186. 'sv-SE': /^[A-ZÅÄÖ]+$/i,
  187. 'th-TH': /^[ก-๐\s]+$/i,
  188. 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
  189. 'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
  190. 'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  191. 'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  192. ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  193. he: /^[א-ת]+$/,
  194. fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
  195. 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i
  196. };
  197. var alphanumeric = {
  198. 'en-US': /^[0-9A-Z]+$/i,
  199. 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
  200. 'bg-BG': /^[0-9А-Я]+$/i,
  201. 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  202. 'da-DK': /^[0-9A-ZÆØÅ]+$/i,
  203. 'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
  204. 'el-GR': /^[0-9Α-ω]+$/i,
  205. 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
  206. 'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
  207. 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  208. 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
  209. 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  210. 'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
  211. 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
  212. 'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
  213. 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  214. 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  215. 'ru-RU': /^[0-9А-ЯЁ]+$/i,
  216. 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
  217. 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  218. 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
  219. 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
  220. 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
  221. 'th-TH': /^[ก-๙\s]+$/i,
  222. 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
  223. 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
  224. 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  225. 'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  226. ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  227. he: /^[0-9א-ת]+$/,
  228. fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
  229. 'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i
  230. };
  231. var decimal = {
  232. 'en-US': '.',
  233. ar: '٫'
  234. };
  235. var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
  236. for (var locale, i = 0; i < englishLocales.length; i++) {
  237. locale = "en-".concat(englishLocales[i]);
  238. alpha[locale] = alpha['en-US'];
  239. alphanumeric[locale] = alphanumeric['en-US'];
  240. decimal[locale] = decimal['en-US'];
  241. } // Source: http://www.localeplanet.com/java/
  242. var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
  243. for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
  244. _locale = "ar-".concat(arabicLocales[_i]);
  245. alpha[_locale] = alpha.ar;
  246. alphanumeric[_locale] = alphanumeric.ar;
  247. decimal[_locale] = decimal.ar;
  248. }
  249. var farsiLocales = ['IR', 'AF'];
  250. for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
  251. _locale2 = "fa-".concat(farsiLocales[_i2]);
  252. alphanumeric[_locale2] = alphanumeric.fa;
  253. decimal[_locale2] = decimal.ar;
  254. } // Source: https://en.wikipedia.org/wiki/Decimal_mark
  255. var dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
  256. var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN'];
  257. for (var _i3 = 0; _i3 < dotDecimal.length; _i3++) {
  258. decimal[dotDecimal[_i3]] = decimal['en-US'];
  259. }
  260. for (var _i4 = 0; _i4 < commaDecimal.length; _i4++) {
  261. decimal[commaDecimal[_i4]] = ',';
  262. }
  263. alpha['fr-CA'] = alpha['fr-FR'];
  264. alphanumeric['fr-CA'] = alphanumeric['fr-FR'];
  265. alpha['pt-BR'] = alpha['pt-PT'];
  266. alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
  267. decimal['pt-BR'] = decimal['pt-PT']; // see #862
  268. alpha['pl-Pl'] = alpha['pl-PL'];
  269. alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
  270. decimal['pl-Pl'] = decimal['pl-PL']; // see #1455
  271. alpha['fa-AF'] = alpha.fa;
  272. function isFloat(str, options) {
  273. assertString(str);
  274. options = options || {};
  275. var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
  276. if (str === '' || str === '.' || str === '-' || str === '+') {
  277. return false;
  278. }
  279. var value = parseFloat(str.replace(',', '.'));
  280. return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
  281. }
  282. var locales = Object.keys(decimal);
  283. function toFloat(str) {
  284. if (!isFloat(str)) return NaN;
  285. return parseFloat(str);
  286. }
  287. function toInt(str, radix) {
  288. assertString(str);
  289. return parseInt(str, radix || 10);
  290. }
  291. function toBoolean(str, strict) {
  292. assertString(str);
  293. if (strict) {
  294. return str === '1' || /^true$/i.test(str);
  295. }
  296. return str !== '0' && !/^false$/i.test(str) && str !== '';
  297. }
  298. function equals(str, comparison) {
  299. assertString(str);
  300. return str === comparison;
  301. }
  302. function toString$1(input) {
  303. if (_typeof(input) === 'object' && input !== null) {
  304. if (typeof input.toString === 'function') {
  305. input = input.toString();
  306. } else {
  307. input = '[object Object]';
  308. }
  309. } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
  310. input = '';
  311. }
  312. return String(input);
  313. }
  314. function merge() {
  315. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  316. var defaults = arguments.length > 1 ? arguments[1] : undefined;
  317. for (var key in defaults) {
  318. if (typeof obj[key] === 'undefined') {
  319. obj[key] = defaults[key];
  320. }
  321. }
  322. return obj;
  323. }
  324. var defaulContainsOptions = {
  325. ignoreCase: false,
  326. minOccurrences: 1
  327. };
  328. function contains(str, elem, options) {
  329. assertString(str);
  330. options = merge(options, defaulContainsOptions);
  331. if (options.ignoreCase) {
  332. return str.toLowerCase().split(toString$1(elem).toLowerCase()).length > options.minOccurrences;
  333. }
  334. return str.split(toString$1(elem)).length > options.minOccurrences;
  335. }
  336. function matches(str, pattern, modifiers) {
  337. assertString(str);
  338. if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
  339. pattern = new RegExp(pattern, modifiers);
  340. }
  341. return pattern.test(str);
  342. }
  343. /* eslint-disable prefer-rest-params */
  344. function isByteLength(str, options) {
  345. assertString(str);
  346. var min;
  347. var max;
  348. if (_typeof(options) === 'object') {
  349. min = options.min || 0;
  350. max = options.max;
  351. } else {
  352. // backwards compatibility: isByteLength(str, min [, max])
  353. min = arguments[1];
  354. max = arguments[2];
  355. }
  356. var len = encodeURI(str).split(/%..|./).length - 1;
  357. return len >= min && (typeof max === 'undefined' || len <= max);
  358. }
  359. var default_fqdn_options = {
  360. require_tld: true,
  361. allow_underscores: false,
  362. allow_trailing_dot: false,
  363. allow_numeric_tld: false,
  364. allow_wildcard: false
  365. };
  366. function isFQDN(str, options) {
  367. assertString(str);
  368. options = merge(options, default_fqdn_options);
  369. /* Remove the optional trailing dot before checking validity */
  370. if (options.allow_trailing_dot && str[str.length - 1] === '.') {
  371. str = str.substring(0, str.length - 1);
  372. }
  373. /* Remove the optional wildcard before checking validity */
  374. if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
  375. str = str.substring(2);
  376. }
  377. var parts = str.split('.');
  378. var tld = parts[parts.length - 1];
  379. if (options.require_tld) {
  380. // disallow fqdns without tld
  381. if (parts.length < 2) {
  382. return false;
  383. }
  384. if (!/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
  385. return false;
  386. } // disallow spaces
  387. if (/\s/.test(tld)) {
  388. return false;
  389. }
  390. } // reject numeric TLDs
  391. if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
  392. return false;
  393. }
  394. return parts.every(function (part) {
  395. if (part.length > 63) {
  396. return false;
  397. }
  398. if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
  399. return false;
  400. } // disallow full-width chars
  401. if (/[\uff01-\uff5e]/.test(part)) {
  402. return false;
  403. } // disallow parts starting or ending with hyphen
  404. if (/^-|-$/.test(part)) {
  405. return false;
  406. }
  407. if (!options.allow_underscores && /_/.test(part)) {
  408. return false;
  409. }
  410. return true;
  411. });
  412. }
  413. /**
  414. 11.3. Examples
  415. The following addresses
  416. fe80::1234 (on the 1st link of the node)
  417. ff02::5678 (on the 5th link of the node)
  418. ff08::9abc (on the 10th organization of the node)
  419. would be represented as follows:
  420. fe80::1234%1
  421. ff02::5678%5
  422. ff08::9abc%10
  423. (Here we assume a natural translation from a zone index to the
  424. <zone_id> part, where the Nth zone of any scope is translated into
  425. "N".)
  426. If we use interface names as <zone_id>, those addresses could also be
  427. represented as follows:
  428. fe80::1234%ne0
  429. ff02::5678%pvc1.3
  430. ff08::9abc%interface10
  431. where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
  432. to the 5th link, and "interface10" belongs to the 10th organization.
  433. * * */
  434. var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
  435. var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
  436. var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
  437. var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
  438. var IPv6AddressRegExp = new RegExp('^(' + "(?:".concat(IPv6SegmentFormat, ":){7}(?:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){6}(?:").concat(IPv4AddressFormat, "|:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){5}(?::").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,2}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){4}(?:(:").concat(IPv6SegmentFormat, "){0,1}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,3}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){3}(?:(:").concat(IPv6SegmentFormat, "){0,2}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,4}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){2}(?:(:").concat(IPv6SegmentFormat, "){0,3}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,5}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){1}(?:(:").concat(IPv6SegmentFormat, "){0,4}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,6}|:)|") + "(?::((?::".concat(IPv6SegmentFormat, "){0,5}:").concat(IPv4AddressFormat, "|(?::").concat(IPv6SegmentFormat, "){1,7}|:))") + ')(%[0-9a-zA-Z-.:]{1,})?$');
  439. function isIP(str) {
  440. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  441. assertString(str);
  442. version = String(version);
  443. if (!version) {
  444. return isIP(str, 4) || isIP(str, 6);
  445. }
  446. if (version === '4') {
  447. if (!IPv4AddressRegExp.test(str)) {
  448. return false;
  449. }
  450. var parts = str.split('.').sort(function (a, b) {
  451. return a - b;
  452. });
  453. return parts[3] <= 255;
  454. }
  455. if (version === '6') {
  456. return !!IPv6AddressRegExp.test(str);
  457. }
  458. return false;
  459. }
  460. var default_email_options = {
  461. allow_display_name: false,
  462. require_display_name: false,
  463. allow_utf8_local_part: true,
  464. require_tld: true,
  465. blacklisted_chars: '',
  466. ignore_max_length: false,
  467. host_blacklist: []
  468. };
  469. /* eslint-disable max-len */
  470. /* eslint-disable no-control-regex */
  471. var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
  472. var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
  473. var gmailUserPart = /^[a-z\d]+$/;
  474. var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
  475. var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
  476. var quotedEmailUserUtf8 = /^([\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;
  477. var defaultMaxEmailLength = 254;
  478. /* eslint-enable max-len */
  479. /* eslint-enable no-control-regex */
  480. /**
  481. * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
  482. * @param {String} display_name
  483. */
  484. function validateDisplayName(display_name) {
  485. var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1'); // display name with only spaces is not valid
  486. if (!display_name_without_quotes.trim()) {
  487. return false;
  488. } // check whether display name contains illegal character
  489. var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
  490. if (contains_illegal) {
  491. // if contains illegal characters,
  492. // must to be enclosed in double-quotes, otherwise it's not a valid display name
  493. if (display_name_without_quotes === display_name) {
  494. return false;
  495. } // the quotes in display name must start with character symbol \
  496. var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
  497. if (!all_start_with_back_slash) {
  498. return false;
  499. }
  500. }
  501. return true;
  502. }
  503. function isEmail(str, options) {
  504. assertString(str);
  505. options = merge(options, default_email_options);
  506. if (options.require_display_name || options.allow_display_name) {
  507. var display_email = str.match(splitNameAddress);
  508. if (display_email) {
  509. var display_name = display_email[1]; // Remove display name and angle brackets to get email address
  510. // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
  511. str = str.replace(display_name, '').replace(/(^<|>$)/g, ''); // sometimes need to trim the last space to get the display name
  512. // because there may be a space between display name and email address
  513. // eg. myname <address@gmail.com>
  514. // the display name is `myname` instead of `myname `, so need to trim the last space
  515. if (display_name.endsWith(' ')) {
  516. display_name = display_name.substr(0, display_name.length - 1);
  517. }
  518. if (!validateDisplayName(display_name)) {
  519. return false;
  520. }
  521. } else if (options.require_display_name) {
  522. return false;
  523. }
  524. }
  525. if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
  526. return false;
  527. }
  528. var parts = str.split('@');
  529. var domain = parts.pop();
  530. var lower_domain = domain.toLowerCase();
  531. if (options.host_blacklist.includes(lower_domain)) {
  532. return false;
  533. }
  534. var user = parts.join('@');
  535. if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
  536. /*
  537. Previously we removed dots for gmail addresses before validating.
  538. This was removed because it allows `multiple..dots@gmail.com`
  539. to be reported as valid, but it is not.
  540. Gmail only normalizes single dots, removing them from here is pointless,
  541. should be done in normalizeEmail
  542. */
  543. user = user.toLowerCase(); // Removing sub-address from username before gmail validation
  544. var username = user.split('+')[0]; // Dots are not included in gmail length restriction
  545. if (!isByteLength(username.replace(/\./g, ''), {
  546. min: 6,
  547. max: 30
  548. })) {
  549. return false;
  550. }
  551. var _user_parts = username.split('.');
  552. for (var i = 0; i < _user_parts.length; i++) {
  553. if (!gmailUserPart.test(_user_parts[i])) {
  554. return false;
  555. }
  556. }
  557. }
  558. if (options.ignore_max_length === false && (!isByteLength(user, {
  559. max: 64
  560. }) || !isByteLength(domain, {
  561. max: 254
  562. }))) {
  563. return false;
  564. }
  565. if (!isFQDN(domain, {
  566. require_tld: options.require_tld
  567. })) {
  568. if (!options.allow_ip_domain) {
  569. return false;
  570. }
  571. if (!isIP(domain)) {
  572. if (!domain.startsWith('[') || !domain.endsWith(']')) {
  573. return false;
  574. }
  575. var noBracketdomain = domain.substr(1, domain.length - 2);
  576. if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
  577. return false;
  578. }
  579. }
  580. }
  581. if (user[0] === '"') {
  582. user = user.slice(1, user.length - 1);
  583. return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
  584. }
  585. var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
  586. var user_parts = user.split('.');
  587. for (var _i = 0; _i < user_parts.length; _i++) {
  588. if (!pattern.test(user_parts[_i])) {
  589. return false;
  590. }
  591. }
  592. if (options.blacklisted_chars) {
  593. if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
  594. }
  595. return true;
  596. }
  597. /*
  598. options for isURL method
  599. require_protocol - if set as true isURL will return false if protocol is not present in the URL
  600. require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
  601. protocols - valid protocols can be modified with this option
  602. require_host - if set as false isURL will not check if host is present in the URL
  603. require_port - if set as true isURL will check if port is present in the URL
  604. allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
  605. validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
  606. */
  607. var default_url_options = {
  608. protocols: ['http', 'https', 'ftp'],
  609. require_tld: true,
  610. require_protocol: false,
  611. require_host: true,
  612. require_port: false,
  613. require_valid_protocol: true,
  614. allow_underscores: false,
  615. allow_trailing_dot: false,
  616. allow_protocol_relative_urls: false,
  617. allow_fragments: true,
  618. allow_query_components: true,
  619. validate_length: true
  620. };
  621. var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
  622. function isRegExp(obj) {
  623. return Object.prototype.toString.call(obj) === '[object RegExp]';
  624. }
  625. function checkHost(host, matches) {
  626. for (var i = 0; i < matches.length; i++) {
  627. var match = matches[i];
  628. if (host === match || isRegExp(match) && match.test(host)) {
  629. return true;
  630. }
  631. }
  632. return false;
  633. }
  634. function isURL(url, options) {
  635. assertString(url);
  636. if (!url || /[\s<>]/.test(url)) {
  637. return false;
  638. }
  639. if (url.indexOf('mailto:') === 0) {
  640. return false;
  641. }
  642. options = merge(options, default_url_options);
  643. if (options.validate_length && url.length >= 2083) {
  644. return false;
  645. }
  646. if (!options.allow_fragments && url.includes('#')) {
  647. return false;
  648. }
  649. if (!options.allow_query_components && (url.includes('?') || url.includes('&'))) {
  650. return false;
  651. }
  652. var protocol, auth, host, hostname, port, port_str, split, ipv6;
  653. split = url.split('#');
  654. url = split.shift();
  655. split = url.split('?');
  656. url = split.shift();
  657. split = url.split('://');
  658. if (split.length > 1) {
  659. protocol = split.shift().toLowerCase();
  660. if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
  661. return false;
  662. }
  663. } else if (options.require_protocol) {
  664. return false;
  665. } else if (url.substr(0, 2) === '//') {
  666. if (!options.allow_protocol_relative_urls) {
  667. return false;
  668. }
  669. split[0] = url.substr(2);
  670. }
  671. url = split.join('://');
  672. if (url === '') {
  673. return false;
  674. }
  675. split = url.split('/');
  676. url = split.shift();
  677. if (url === '' && !options.require_host) {
  678. return true;
  679. }
  680. split = url.split('@');
  681. if (split.length > 1) {
  682. if (options.disallow_auth) {
  683. return false;
  684. }
  685. if (split[0] === '') {
  686. return false;
  687. }
  688. auth = split.shift();
  689. if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
  690. return false;
  691. }
  692. var _auth$split = auth.split(':'),
  693. _auth$split2 = _slicedToArray(_auth$split, 2),
  694. user = _auth$split2[0],
  695. password = _auth$split2[1];
  696. if (user === '' && password === '') {
  697. return false;
  698. }
  699. }
  700. hostname = split.join('@');
  701. port_str = null;
  702. ipv6 = null;
  703. var ipv6_match = hostname.match(wrapped_ipv6);
  704. if (ipv6_match) {
  705. host = '';
  706. ipv6 = ipv6_match[1];
  707. port_str = ipv6_match[2] || null;
  708. } else {
  709. split = hostname.split(':');
  710. host = split.shift();
  711. if (split.length) {
  712. port_str = split.join(':');
  713. }
  714. }
  715. if (port_str !== null && port_str.length > 0) {
  716. port = parseInt(port_str, 10);
  717. if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
  718. return false;
  719. }
  720. } else if (options.require_port) {
  721. return false;
  722. }
  723. if (options.host_whitelist) {
  724. return checkHost(host, options.host_whitelist);
  725. }
  726. if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
  727. return false;
  728. }
  729. host = host || ipv6;
  730. if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
  731. return false;
  732. }
  733. return true;
  734. }
  735. var macAddress = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
  736. var macAddressNoSeparators = /^([0-9a-fA-F]){12}$/;
  737. var macAddressWithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;
  738. function isMACAddress(str, options) {
  739. assertString(str);
  740. /**
  741. * @deprecated `no_colons` TODO: remove it in the next major
  742. */
  743. if (options && (options.no_colons || options.no_separators)) {
  744. return macAddressNoSeparators.test(str);
  745. }
  746. return macAddress.test(str) || macAddressWithDots.test(str);
  747. }
  748. var subnetMaybe = /^\d{1,3}$/;
  749. var v4Subnet = 32;
  750. var v6Subnet = 128;
  751. function isIPRange(str) {
  752. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  753. assertString(str);
  754. var parts = str.split('/'); // parts[0] -> ip, parts[1] -> subnet
  755. if (parts.length !== 2) {
  756. return false;
  757. }
  758. if (!subnetMaybe.test(parts[1])) {
  759. return false;
  760. } // Disallow preceding 0 i.e. 01, 02, ...
  761. if (parts[1].length > 1 && parts[1].startsWith('0')) {
  762. return false;
  763. }
  764. var isValidIP = isIP(parts[0], version);
  765. if (!isValidIP) {
  766. return false;
  767. } // Define valid subnet according to IP's version
  768. var expectedSubnet = null;
  769. switch (String(version)) {
  770. case '4':
  771. expectedSubnet = v4Subnet;
  772. break;
  773. case '6':
  774. expectedSubnet = v6Subnet;
  775. break;
  776. default:
  777. expectedSubnet = isIP(parts[0], '6') ? v6Subnet : v4Subnet;
  778. }
  779. return parts[1] <= expectedSubnet && parts[1] >= 0;
  780. }
  781. var default_date_options = {
  782. format: 'YYYY/MM/DD',
  783. delimiters: ['/', '-'],
  784. strictMode: false
  785. };
  786. function isValidFormat(format) {
  787. return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
  788. }
  789. function zip(date, format) {
  790. var zippedArr = [],
  791. len = Math.min(date.length, format.length);
  792. for (var i = 0; i < len; i++) {
  793. zippedArr.push([date[i], format[i]]);
  794. }
  795. return zippedArr;
  796. }
  797. function isDate(input, options) {
  798. if (typeof options === 'string') {
  799. // Allow backward compatbility for old format isDate(input [, format])
  800. options = merge({
  801. format: options
  802. }, default_date_options);
  803. } else {
  804. options = merge(options, default_date_options);
  805. }
  806. if (typeof input === 'string' && isValidFormat(options.format)) {
  807. var formatDelimiter = options.delimiters.find(function (delimiter) {
  808. return options.format.indexOf(delimiter) !== -1;
  809. });
  810. var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
  811. return input.indexOf(delimiter) !== -1;
  812. });
  813. var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
  814. var dateObj = {};
  815. var _iterator = _createForOfIteratorHelper(dateAndFormat),
  816. _step;
  817. try {
  818. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  819. var _step$value = _slicedToArray(_step.value, 2),
  820. dateWord = _step$value[0],
  821. formatWord = _step$value[1];
  822. if (dateWord.length !== formatWord.length) {
  823. return false;
  824. }
  825. dateObj[formatWord.charAt(0)] = dateWord;
  826. }
  827. } catch (err) {
  828. _iterator.e(err);
  829. } finally {
  830. _iterator.f();
  831. }
  832. return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d;
  833. }
  834. if (!options.strictMode) {
  835. return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
  836. }
  837. return false;
  838. }
  839. var defaultOptions = {
  840. loose: false
  841. };
  842. var strictBooleans = ['true', 'false', '1', '0'];
  843. var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
  844. function isBoolean(str) {
  845. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
  846. assertString(str);
  847. if (options.loose) {
  848. return looseBooleans.includes(str.toLowerCase());
  849. }
  850. return strictBooleans.includes(str);
  851. }
  852. var localeReg = /^[A-Za-z]{2,4}([_-]([A-Za-z]{4}|[\d]{3}))?([_-]([A-Za-z]{2}|[\d]{3}))?$/;
  853. function isLocale(str) {
  854. assertString(str);
  855. if (str === 'en_US_POSIX' || str === 'ca_ES_VALENCIA') {
  856. return true;
  857. }
  858. return localeReg.test(str);
  859. }
  860. function isAlpha(_str) {
  861. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  862. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  863. assertString(_str);
  864. var str = _str;
  865. var ignore = options.ignore;
  866. if (ignore) {
  867. if (ignore instanceof RegExp) {
  868. str = str.replace(ignore, '');
  869. } else if (typeof ignore === 'string') {
  870. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  871. } else {
  872. throw new Error('ignore should be instance of a String or RegExp');
  873. }
  874. }
  875. if (locale in alpha) {
  876. return alpha[locale].test(str);
  877. }
  878. throw new Error("Invalid locale '".concat(locale, "'"));
  879. }
  880. var locales$1 = Object.keys(alpha);
  881. function isAlphanumeric(_str) {
  882. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  883. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  884. assertString(_str);
  885. var str = _str;
  886. var ignore = options.ignore;
  887. if (ignore) {
  888. if (ignore instanceof RegExp) {
  889. str = str.replace(ignore, '');
  890. } else if (typeof ignore === 'string') {
  891. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  892. } else {
  893. throw new Error('ignore should be instance of a String or RegExp');
  894. }
  895. }
  896. if (locale in alphanumeric) {
  897. return alphanumeric[locale].test(str);
  898. }
  899. throw new Error("Invalid locale '".concat(locale, "'"));
  900. }
  901. var locales$2 = Object.keys(alphanumeric);
  902. var numericNoSymbols = /^[0-9]+$/;
  903. function isNumeric(str, options) {
  904. assertString(str);
  905. if (options && options.no_symbols) {
  906. return numericNoSymbols.test(str);
  907. }
  908. return new RegExp("^[+-]?([0-9]*[".concat((options || {}).locale ? decimal[options.locale] : '.', "])?[0-9]+$")).test(str);
  909. }
  910. /**
  911. * Reference:
  912. * https://en.wikipedia.org/ -- Wikipedia
  913. * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
  914. * https://countrycode.org/ -- Country Codes
  915. */
  916. var passportRegexByCountryCode = {
  917. AM: /^[A-Z]{2}\d{7}$/,
  918. // ARMENIA
  919. AR: /^[A-Z]{3}\d{6}$/,
  920. // ARGENTINA
  921. AT: /^[A-Z]\d{7}$/,
  922. // AUSTRIA
  923. AU: /^[A-Z]\d{7}$/,
  924. // AUSTRALIA
  925. BE: /^[A-Z]{2}\d{6}$/,
  926. // BELGIUM
  927. BG: /^\d{9}$/,
  928. // BULGARIA
  929. BR: /^[A-Z]{2}\d{6}$/,
  930. // BRAZIL
  931. BY: /^[A-Z]{2}\d{7}$/,
  932. // BELARUS
  933. CA: /^[A-Z]{2}\d{6}$/,
  934. // CANADA
  935. CH: /^[A-Z]\d{7}$/,
  936. // SWITZERLAND
  937. CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
  938. // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
  939. CY: /^[A-Z](\d{6}|\d{8})$/,
  940. // CYPRUS
  941. CZ: /^\d{8}$/,
  942. // CZECH REPUBLIC
  943. DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
  944. // GERMANY
  945. DK: /^\d{9}$/,
  946. // DENMARK
  947. DZ: /^\d{9}$/,
  948. // ALGERIA
  949. EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
  950. // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
  951. ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
  952. // SPAIN
  953. FI: /^[A-Z]{2}\d{7}$/,
  954. // FINLAND
  955. FR: /^\d{2}[A-Z]{2}\d{5}$/,
  956. // FRANCE
  957. GB: /^\d{9}$/,
  958. // UNITED KINGDOM
  959. GR: /^[A-Z]{2}\d{7}$/,
  960. // GREECE
  961. HR: /^\d{9}$/,
  962. // CROATIA
  963. HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
  964. // HUNGARY
  965. IE: /^[A-Z0-9]{2}\d{7}$/,
  966. // IRELAND
  967. IN: /^[A-Z]{1}-?\d{7}$/,
  968. // INDIA
  969. ID: /^[A-C]\d{7}$/,
  970. // INDONESIA
  971. IR: /^[A-Z]\d{8}$/,
  972. // IRAN
  973. IS: /^(A)\d{7}$/,
  974. // ICELAND
  975. IT: /^[A-Z0-9]{2}\d{7}$/,
  976. // ITALY
  977. JP: /^[A-Z]{2}\d{7}$/,
  978. // JAPAN
  979. KR: /^[MS]\d{8}$/,
  980. // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
  981. LT: /^[A-Z0-9]{8}$/,
  982. // LITHUANIA
  983. LU: /^[A-Z0-9]{8}$/,
  984. // LUXEMBURG
  985. LV: /^[A-Z0-9]{2}\d{7}$/,
  986. // LATVIA
  987. LY: /^[A-Z0-9]{8}$/,
  988. // LIBYA
  989. MT: /^\d{7}$/,
  990. // MALTA
  991. MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
  992. // MOZAMBIQUE
  993. MY: /^[AHK]\d{8}$/,
  994. // MALAYSIA
  995. NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
  996. // NETHERLANDS
  997. PL: /^[A-Z]{2}\d{7}$/,
  998. // POLAND
  999. PT: /^[A-Z]\d{6}$/,
  1000. // PORTUGAL
  1001. RO: /^\d{8,9}$/,
  1002. // ROMANIA
  1003. RU: /^\d{9}$/,
  1004. // RUSSIAN FEDERATION
  1005. SE: /^\d{8}$/,
  1006. // SWEDEN
  1007. SL: /^(P)[A-Z]\d{7}$/,
  1008. // SLOVANIA
  1009. SK: /^[0-9A-Z]\d{7}$/,
  1010. // SLOVAKIA
  1011. TR: /^[A-Z]\d{8}$/,
  1012. // TURKEY
  1013. UA: /^[A-Z]{2}\d{6}$/,
  1014. // UKRAINE
  1015. US: /^\d{9}$/ // UNITED STATES
  1016. };
  1017. /**
  1018. * Check if str is a valid passport number
  1019. * relative to provided ISO Country Code.
  1020. *
  1021. * @param {string} str
  1022. * @param {string} countryCode
  1023. * @return {boolean}
  1024. */
  1025. function isPassportNumber(str, countryCode) {
  1026. assertString(str);
  1027. /** Remove All Whitespaces, Convert to UPPERCASE */
  1028. var normalizedStr = str.replace(/\s/g, '').toUpperCase();
  1029. return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
  1030. }
  1031. var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
  1032. var intLeadingZeroes = /^[-+]?[0-9]+$/;
  1033. function isInt(str, options) {
  1034. assertString(str);
  1035. options = options || {}; // Get the regex to use for testing, based on whether
  1036. // leading zeroes are allowed or not.
  1037. var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? _int : intLeadingZeroes; // Check min/max/lt/gt
  1038. var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min;
  1039. var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max;
  1040. var ltCheckPassed = !options.hasOwnProperty('lt') || str < options.lt;
  1041. var gtCheckPassed = !options.hasOwnProperty('gt') || str > options.gt;
  1042. return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
  1043. }
  1044. function isPort(str) {
  1045. return isInt(str, {
  1046. min: 0,
  1047. max: 65535
  1048. });
  1049. }
  1050. function isLowercase(str) {
  1051. assertString(str);
  1052. return str === str.toLowerCase();
  1053. }
  1054. function isUppercase(str) {
  1055. assertString(str);
  1056. return str === str.toUpperCase();
  1057. }
  1058. var imeiRegexWithoutHypens = /^[0-9]{15}$/;
  1059. var imeiRegexWithHypens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;
  1060. function isIMEI(str, options) {
  1061. assertString(str);
  1062. options = options || {}; // default regex for checking imei is the one without hyphens
  1063. var imeiRegex = imeiRegexWithoutHypens;
  1064. if (options.allow_hyphens) {
  1065. imeiRegex = imeiRegexWithHypens;
  1066. }
  1067. if (!imeiRegex.test(str)) {
  1068. return false;
  1069. }
  1070. str = str.replace(/-/g, '');
  1071. var sum = 0,
  1072. mul = 2,
  1073. l = 14;
  1074. for (var i = 0; i < l; i++) {
  1075. var digit = str.substring(l - i - 1, l - i);
  1076. var tp = parseInt(digit, 10) * mul;
  1077. if (tp >= 10) {
  1078. sum += tp % 10 + 1;
  1079. } else {
  1080. sum += tp;
  1081. }
  1082. if (mul === 1) {
  1083. mul += 1;
  1084. } else {
  1085. mul -= 1;
  1086. }
  1087. }
  1088. var chk = (10 - sum % 10) % 10;
  1089. if (chk !== parseInt(str.substring(14, 15), 10)) {
  1090. return false;
  1091. }
  1092. return true;
  1093. }
  1094. /* eslint-disable no-control-regex */
  1095. var ascii = /^[\x00-\x7F]+$/;
  1096. /* eslint-enable no-control-regex */
  1097. function isAscii(str) {
  1098. assertString(str);
  1099. return ascii.test(str);
  1100. }
  1101. var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  1102. function isFullWidth(str) {
  1103. assertString(str);
  1104. return fullWidth.test(str);
  1105. }
  1106. var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  1107. function isHalfWidth(str) {
  1108. assertString(str);
  1109. return halfWidth.test(str);
  1110. }
  1111. function isVariableWidth(str) {
  1112. assertString(str);
  1113. return fullWidth.test(str) && halfWidth.test(str);
  1114. }
  1115. /* eslint-disable no-control-regex */
  1116. var multibyte = /[^\x00-\x7F]/;
  1117. /* eslint-enable no-control-regex */
  1118. function isMultibyte(str) {
  1119. assertString(str);
  1120. return multibyte.test(str);
  1121. }
  1122. /**
  1123. * Build RegExp object from an array
  1124. * of multiple/multi-line regexp parts
  1125. *
  1126. * @param {string[]} parts
  1127. * @param {string} flags
  1128. * @return {object} - RegExp object
  1129. */
  1130. function multilineRegexp(parts, flags) {
  1131. var regexpAsStringLiteral = parts.join('');
  1132. return new RegExp(regexpAsStringLiteral, flags);
  1133. }
  1134. /**
  1135. * Regular Expression to match
  1136. * semantic versioning (SemVer)
  1137. * built from multi-line, multi-parts regexp
  1138. * Reference: https://semver.org/
  1139. */
  1140. var semanticVersioningRegex = multilineRegexp(['^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)', '(?:-((?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-z-][0-9a-z-]*))*))', '?(?:\\+([0-9a-z-]+(?:\\.[0-9a-z-]+)*))?$'], 'i');
  1141. function isSemVer(str) {
  1142. assertString(str);
  1143. return semanticVersioningRegex.test(str);
  1144. }
  1145. var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
  1146. function isSurrogatePair(str) {
  1147. assertString(str);
  1148. return surrogatePair.test(str);
  1149. }
  1150. var includes = function includes(arr, val) {
  1151. return arr.some(function (arrVal) {
  1152. return val === arrVal;
  1153. });
  1154. };
  1155. function decimalRegExp(options) {
  1156. var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
  1157. return regExp;
  1158. }
  1159. var default_decimal_options = {
  1160. force_decimal: false,
  1161. decimal_digits: '1,',
  1162. locale: 'en-US'
  1163. };
  1164. var blacklist = ['', '-', '+'];
  1165. function isDecimal(str, options) {
  1166. assertString(str);
  1167. options = merge(options, default_decimal_options);
  1168. if (options.locale in decimal) {
  1169. return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
  1170. }
  1171. throw new Error("Invalid locale '".concat(options.locale, "'"));
  1172. }
  1173. var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;
  1174. function isHexadecimal(str) {
  1175. assertString(str);
  1176. return hexadecimal.test(str);
  1177. }
  1178. var octal = /^(0o)?[0-7]+$/i;
  1179. function isOctal(str) {
  1180. assertString(str);
  1181. return octal.test(str);
  1182. }
  1183. function isDivisibleBy(str, num) {
  1184. assertString(str);
  1185. return toFloat(str) % parseInt(num, 10) === 0;
  1186. }
  1187. var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
  1188. function isHexColor(str) {
  1189. assertString(str);
  1190. return hexcolor.test(str);
  1191. }
  1192. var rgbColor = /^rgb\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\)$/;
  1193. var rgbaColor = /^rgba\((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)$/;
  1194. var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)/;
  1195. var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d|1(\.0)?|0(\.0)?)\)/;
  1196. function isRgbColor(str) {
  1197. var includePercentValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  1198. assertString(str);
  1199. if (!includePercentValues) {
  1200. return rgbColor.test(str) || rgbaColor.test(str);
  1201. }
  1202. return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str);
  1203. }
  1204. var hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i;
  1205. var hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i;
  1206. function isHSL(str) {
  1207. assertString(str); // Strip duplicate spaces before calling the validation regex (See #1598 for more info)
  1208. var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
  1209. if (strippedStr.indexOf(',') !== -1) {
  1210. return hslComma.test(strippedStr);
  1211. }
  1212. return hslSpace.test(strippedStr);
  1213. }
  1214. var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;
  1215. function isISRC(str) {
  1216. assertString(str);
  1217. return isrc.test(str);
  1218. }
  1219. /**
  1220. * List of country codes with
  1221. * corresponding IBAN regular expression
  1222. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  1223. */
  1224. var ibanRegexThroughCountryCode = {
  1225. AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
  1226. AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
  1227. AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  1228. AT: /^(AT[0-9]{2})\d{16}$/,
  1229. AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1230. BA: /^(BA[0-9]{2})\d{16}$/,
  1231. BE: /^(BE[0-9]{2})\d{12}$/,
  1232. BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
  1233. BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
  1234. BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,
  1235. BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1236. CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  1237. CR: /^(CR[0-9]{2})\d{18}$/,
  1238. CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  1239. CZ: /^(CZ[0-9]{2})\d{20}$/,
  1240. DE: /^(DE[0-9]{2})\d{18}$/,
  1241. DK: /^(DK[0-9]{2})\d{14}$/,
  1242. DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/,
  1243. EE: /^(EE[0-9]{2})\d{16}$/,
  1244. EG: /^(EG[0-9]{2})\d{25}$/,
  1245. ES: /^(ES[0-9]{2})\d{20}$/,
  1246. FI: /^(FI[0-9]{2})\d{14}$/,
  1247. FO: /^(FO[0-9]{2})\d{14}$/,
  1248. FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  1249. GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/,
  1250. GE: /^(GE[0-9]{2})[A-Z0-9]{2}\d{16}$/,
  1251. GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/,
  1252. GL: /^(GL[0-9]{2})\d{14}$/,
  1253. GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/,
  1254. GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
  1255. HR: /^(HR[0-9]{2})\d{17}$/,
  1256. HU: /^(HU[0-9]{2})\d{24}$/,
  1257. IE: /^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,
  1258. IL: /^(IL[0-9]{2})\d{19}$/,
  1259. IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
  1260. IR: /^(IR[0-9]{2})0\d{2}0\d{18}$/,
  1261. IS: /^(IS[0-9]{2})\d{22}$/,
  1262. IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  1263. JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/,
  1264. KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/,
  1265. KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  1266. LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/,
  1267. LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,
  1268. LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  1269. LT: /^(LT[0-9]{2})\d{16}$/,
  1270. LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  1271. LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
  1272. MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  1273. MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
  1274. ME: /^(ME[0-9]{2})\d{18}$/,
  1275. MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,
  1276. MR: /^(MR[0-9]{2})\d{23}$/,
  1277. MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,
  1278. MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,
  1279. MZ: /^(MZ[0-9]{2})\d{21}$/,
  1280. NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
  1281. NO: /^(NO[0-9]{2})\d{11}$/,
  1282. PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  1283. PL: /^(PL[0-9]{2})\d{24}$/,
  1284. PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{21}$/,
  1285. PT: /^(PT[0-9]{2})\d{21}$/,
  1286. QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
  1287. RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
  1288. RS: /^(RS[0-9]{2})\d{18}$/,
  1289. SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
  1290. SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
  1291. SE: /^(SE[0-9]{2})\d{20}$/,
  1292. SI: /^(SI[0-9]{2})\d{15}$/,
  1293. SK: /^(SK[0-9]{2})\d{20}$/,
  1294. SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  1295. SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1296. TL: /^(TL[0-9]{2})\d{19}$/,
  1297. TN: /^(TN[0-9]{2})\d{20}$/,
  1298. TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
  1299. UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
  1300. VA: /^(VA[0-9]{2})\d{18}$/,
  1301. VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  1302. XK: /^(XK[0-9]{2})\d{16}$/
  1303. };
  1304. /**
  1305. * Check whether string has correct universal IBAN format
  1306. * The IBAN consists of up to 34 alphanumeric characters, as follows:
  1307. * Country Code using ISO 3166-1 alpha-2, two letters
  1308. * check digits, two digits and
  1309. * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
  1310. * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
  1311. *
  1312. * @param {string} str - string under validation
  1313. * @return {boolean}
  1314. */
  1315. function hasValidIbanFormat(str) {
  1316. // Strip white spaces and hyphens
  1317. var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
  1318. var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
  1319. return isoCountryCode in ibanRegexThroughCountryCode && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
  1320. }
  1321. /**
  1322. * Check whether string has valid IBAN Checksum
  1323. * by performing basic mod-97 operation and
  1324. * the remainder should equal 1
  1325. * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
  1326. * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
  1327. * -- Interpret the string as a decimal integer and
  1328. * -- compute the remainder on division by 97 (mod 97)
  1329. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  1330. *
  1331. * @param {string} str
  1332. * @return {boolean}
  1333. */
  1334. function hasValidIbanChecksum(str) {
  1335. var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
  1336. var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
  1337. var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (_char) {
  1338. return _char.charCodeAt(0) - 55;
  1339. });
  1340. var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
  1341. return Number(acc + value) % 97;
  1342. }, '');
  1343. return remainder === 1;
  1344. }
  1345. function isIBAN(str) {
  1346. assertString(str);
  1347. return hasValidIbanFormat(str) && hasValidIbanChecksum(str);
  1348. }
  1349. var locales$3 = Object.keys(ibanRegexThroughCountryCode);
  1350. var validISO31661Alpha2CountriesCodes = new Set(['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']);
  1351. function isISO31661Alpha2(str) {
  1352. assertString(str);
  1353. return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
  1354. }
  1355. var CountryCodes = validISO31661Alpha2CountriesCodes;
  1356. var isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
  1357. function isBIC(str) {
  1358. assertString(str); // toUpperCase() should be removed when a new major version goes out that changes
  1359. // the regex to [A-Z] (per the spec).
  1360. if (!CountryCodes.has(str.slice(4, 6).toUpperCase())) {
  1361. return false;
  1362. }
  1363. return isBICReg.test(str);
  1364. }
  1365. var md5 = /^[a-f0-9]{32}$/;
  1366. function isMD5(str) {
  1367. assertString(str);
  1368. return md5.test(str);
  1369. }
  1370. var lengths = {
  1371. md5: 32,
  1372. md4: 32,
  1373. sha1: 40,
  1374. sha256: 64,
  1375. sha384: 96,
  1376. sha512: 128,
  1377. ripemd128: 32,
  1378. ripemd160: 40,
  1379. tiger128: 32,
  1380. tiger160: 40,
  1381. tiger192: 48,
  1382. crc32: 8,
  1383. crc32b: 8
  1384. };
  1385. function isHash(str, algorithm) {
  1386. assertString(str);
  1387. var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$"));
  1388. return hash.test(str);
  1389. }
  1390. var notBase64 = /[^A-Z0-9+\/=]/i;
  1391. var urlSafeBase64 = /^[A-Z0-9_\-]*$/i;
  1392. var defaultBase64Options = {
  1393. urlSafe: false
  1394. };
  1395. function isBase64(str, options) {
  1396. assertString(str);
  1397. options = merge(options, defaultBase64Options);
  1398. var len = str.length;
  1399. if (options.urlSafe) {
  1400. return urlSafeBase64.test(str);
  1401. }
  1402. if (len % 4 !== 0 || notBase64.test(str)) {
  1403. return false;
  1404. }
  1405. var firstPaddingChar = str.indexOf('=');
  1406. return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
  1407. }
  1408. function isJWT(str) {
  1409. assertString(str);
  1410. var dotSplit = str.split('.');
  1411. var len = dotSplit.length;
  1412. if (len > 3 || len < 2) {
  1413. return false;
  1414. }
  1415. return dotSplit.reduce(function (acc, currElem) {
  1416. return acc && isBase64(currElem, {
  1417. urlSafe: true
  1418. });
  1419. }, true);
  1420. }
  1421. var default_json_options = {
  1422. allow_primitives: false
  1423. };
  1424. function isJSON(str, options) {
  1425. assertString(str);
  1426. try {
  1427. options = merge(options, default_json_options);
  1428. var primitives = [];
  1429. if (options.allow_primitives) {
  1430. primitives = [null, false, true];
  1431. }
  1432. var obj = JSON.parse(str);
  1433. return primitives.includes(obj) || !!obj && _typeof(obj) === 'object';
  1434. } catch (e) {
  1435. /* ignore */
  1436. }
  1437. return false;
  1438. }
  1439. var default_is_empty_options = {
  1440. ignore_whitespace: false
  1441. };
  1442. function isEmpty(str, options) {
  1443. assertString(str);
  1444. options = merge(options, default_is_empty_options);
  1445. return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
  1446. }
  1447. /* eslint-disable prefer-rest-params */
  1448. function isLength(str, options) {
  1449. assertString(str);
  1450. var min;
  1451. var max;
  1452. if (_typeof(options) === 'object') {
  1453. min = options.min || 0;
  1454. max = options.max;
  1455. } else {
  1456. // backwards compatibility: isLength(str, min [, max])
  1457. min = arguments[1] || 0;
  1458. max = arguments[2];
  1459. }
  1460. var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
  1461. var len = str.length - surrogatePairs.length;
  1462. return len >= min && (typeof max === 'undefined' || len <= max);
  1463. }
  1464. var uuid = {
  1465. 1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  1466. 2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  1467. 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  1468. 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  1469. 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  1470. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  1471. };
  1472. function isUUID(str, version) {
  1473. assertString(str);
  1474. var pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
  1475. return !!pattern && pattern.test(str);
  1476. }
  1477. function isMongoId(str) {
  1478. assertString(str);
  1479. return isHexadecimal(str) && str.length === 24;
  1480. }
  1481. function isAfter(str) {
  1482. var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
  1483. assertString(str);
  1484. var comparison = toDate(date);
  1485. var original = toDate(str);
  1486. return !!(original && comparison && original > comparison);
  1487. }
  1488. function isBefore(str) {
  1489. var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
  1490. assertString(str);
  1491. var comparison = toDate(date);
  1492. var original = toDate(str);
  1493. return !!(original && comparison && original < comparison);
  1494. }
  1495. function isIn(str, options) {
  1496. assertString(str);
  1497. var i;
  1498. if (Object.prototype.toString.call(options) === '[object Array]') {
  1499. var array = [];
  1500. for (i in options) {
  1501. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  1502. // istanbul ignore else
  1503. if ({}.hasOwnProperty.call(options, i)) {
  1504. array[i] = toString$1(options[i]);
  1505. }
  1506. }
  1507. return array.indexOf(str) >= 0;
  1508. } else if (_typeof(options) === 'object') {
  1509. return options.hasOwnProperty(str);
  1510. } else if (options && typeof options.indexOf === 'function') {
  1511. return options.indexOf(str) >= 0;
  1512. }
  1513. return false;
  1514. }
  1515. /* eslint-disable max-len */
  1516. var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
  1517. /* eslint-enable max-len */
  1518. function isCreditCard(str) {
  1519. assertString(str);
  1520. var sanitized = str.replace(/[- ]+/g, '');
  1521. if (!creditCard.test(sanitized)) {
  1522. return false;
  1523. }
  1524. var sum = 0;
  1525. var digit;
  1526. var tmpNum;
  1527. var shouldDouble;
  1528. for (var i = sanitized.length - 1; i >= 0; i--) {
  1529. digit = sanitized.substring(i, i + 1);
  1530. tmpNum = parseInt(digit, 10);
  1531. if (shouldDouble) {
  1532. tmpNum *= 2;
  1533. if (tmpNum >= 10) {
  1534. sum += tmpNum % 10 + 1;
  1535. } else {
  1536. sum += tmpNum;
  1537. }
  1538. } else {
  1539. sum += tmpNum;
  1540. }
  1541. shouldDouble = !shouldDouble;
  1542. }
  1543. return !!(sum % 10 === 0 ? sanitized : false);
  1544. }
  1545. var validators = {
  1546. PL: function PL(str) {
  1547. assertString(str);
  1548. var weightOfDigits = {
  1549. 1: 1,
  1550. 2: 3,
  1551. 3: 7,
  1552. 4: 9,
  1553. 5: 1,
  1554. 6: 3,
  1555. 7: 7,
  1556. 8: 9,
  1557. 9: 1,
  1558. 10: 3,
  1559. 11: 0
  1560. };
  1561. if (str != null && str.length === 11 && isInt(str, {
  1562. allow_leading_zeroes: true
  1563. })) {
  1564. var digits = str.split('').slice(0, -1);
  1565. var sum = digits.reduce(function (acc, digit, index) {
  1566. return acc + Number(digit) * weightOfDigits[index + 1];
  1567. }, 0);
  1568. var modulo = sum % 10;
  1569. var lastDigit = Number(str.charAt(str.length - 1));
  1570. if (modulo === 0 && lastDigit === 0 || lastDigit === 10 - modulo) {
  1571. return true;
  1572. }
  1573. }
  1574. return false;
  1575. },
  1576. ES: function ES(str) {
  1577. assertString(str);
  1578. var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
  1579. var charsValue = {
  1580. X: 0,
  1581. Y: 1,
  1582. Z: 2
  1583. };
  1584. var controlDigits = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E']; // sanitize user input
  1585. var sanitized = str.trim().toUpperCase(); // validate the data structure
  1586. if (!DNI.test(sanitized)) {
  1587. return false;
  1588. } // validate the control digit
  1589. var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
  1590. return charsValue[_char];
  1591. });
  1592. return sanitized.endsWith(controlDigits[number % 23]);
  1593. },
  1594. FI: function FI(str) {
  1595. // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated
  1596. assertString(str);
  1597. if (str.length !== 11) {
  1598. return false;
  1599. }
  1600. if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) {
  1601. return false;
  1602. }
  1603. var checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY';
  1604. var idAsNumber = parseInt(str.slice(0, 6), 10) * 1000 + parseInt(str.slice(7, 10), 10);
  1605. var remainder = idAsNumber % 31;
  1606. var checkDigit = checkDigits[remainder];
  1607. return checkDigit === str.slice(10, 11);
  1608. },
  1609. IN: function IN(str) {
  1610. var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/; // multiplication table
  1611. var d = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]; // permutation table
  1612. var p = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]]; // sanitize user input
  1613. var sanitized = str.trim(); // validate the data structure
  1614. if (!DNI.test(sanitized)) {
  1615. return false;
  1616. }
  1617. var c = 0;
  1618. var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
  1619. invertedArray.forEach(function (val, i) {
  1620. c = d[c][p[i % 8][val]];
  1621. });
  1622. return c === 0;
  1623. },
  1624. IR: function IR(str) {
  1625. if (!str.match(/^\d{10}$/)) return false;
  1626. str = "0000".concat(str).substr(str.length - 6);
  1627. if (parseInt(str.substr(3, 6), 10) === 0) return false;
  1628. var lastNumber = parseInt(str.substr(9, 1), 10);
  1629. var sum = 0;
  1630. for (var i = 0; i < 9; i++) {
  1631. sum += parseInt(str.substr(i, 1), 10) * (10 - i);
  1632. }
  1633. sum %= 11;
  1634. return sum < 2 && lastNumber === sum || sum >= 2 && lastNumber === 11 - sum;
  1635. },
  1636. IT: function IT(str) {
  1637. if (str.length !== 9) return false;
  1638. if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
  1639. return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
  1640. },
  1641. NO: function NO(str) {
  1642. var sanitized = str.trim();
  1643. if (isNaN(Number(sanitized))) return false;
  1644. if (sanitized.length !== 11) return false;
  1645. if (sanitized === '00000000000') return false; // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
  1646. var f = sanitized.split('').map(Number);
  1647. var k1 = (11 - (3 * f[0] + 7 * f[1] + 6 * f[2] + 1 * f[3] + 8 * f[4] + 9 * f[5] + 4 * f[6] + 5 * f[7] + 2 * f[8]) % 11) % 11;
  1648. var k2 = (11 - (5 * f[0] + 4 * f[1] + 3 * f[2] + 2 * f[3] + 7 * f[4] + 6 * f[5] + 5 * f[6] + 4 * f[7] + 3 * f[8] + 2 * k1) % 11) % 11;
  1649. if (k1 !== f[9] || k2 !== f[10]) return false;
  1650. return true;
  1651. },
  1652. TH: function TH(str) {
  1653. if (!str.match(/^[1-8]\d{12}$/)) return false; // validate check digit
  1654. var sum = 0;
  1655. for (var i = 0; i < 12; i++) {
  1656. sum += parseInt(str[i], 10) * (13 - i);
  1657. }
  1658. return str[12] === ((11 - sum % 11) % 10).toString();
  1659. },
  1660. LK: function LK(str) {
  1661. var old_nic = /^[1-9]\d{8}[vx]$/i;
  1662. var new_nic = /^[1-9]\d{11}$/i;
  1663. if (str.length === 10 && old_nic.test(str)) return true;else if (str.length === 12 && new_nic.test(str)) return true;
  1664. return false;
  1665. },
  1666. 'he-IL': function heIL(str) {
  1667. var DNI = /^\d{9}$/; // sanitize user input
  1668. var sanitized = str.trim(); // validate the data structure
  1669. if (!DNI.test(sanitized)) {
  1670. return false;
  1671. }
  1672. var id = sanitized;
  1673. var sum = 0,
  1674. incNum;
  1675. for (var i = 0; i < id.length; i++) {
  1676. incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
  1677. sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
  1678. }
  1679. return sum % 10 === 0;
  1680. },
  1681. 'ar-LY': function arLY(str) {
  1682. // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
  1683. var NIN = /^(1|2)\d{11}$/; // sanitize user input
  1684. var sanitized = str.trim(); // validate the data structure
  1685. if (!NIN.test(sanitized)) {
  1686. return false;
  1687. }
  1688. return true;
  1689. },
  1690. 'ar-TN': function arTN(str) {
  1691. var DNI = /^\d{8}$/; // sanitize user input
  1692. var sanitized = str.trim(); // validate the data structure
  1693. if (!DNI.test(sanitized)) {
  1694. return false;
  1695. }
  1696. return true;
  1697. },
  1698. 'zh-CN': function zhCN(str) {
  1699. var provincesAndCities = ['11', // 北京
  1700. '12', // 天津
  1701. '13', // 河北
  1702. '14', // 山西
  1703. '15', // 内蒙古
  1704. '21', // 辽宁
  1705. '22', // 吉林
  1706. '23', // 黑龙江
  1707. '31', // 上海
  1708. '32', // 江苏
  1709. '33', // 浙江
  1710. '34', // 安徽
  1711. '35', // 福建
  1712. '36', // 江西
  1713. '37', // 山东
  1714. '41', // 河南
  1715. '42', // 湖北
  1716. '43', // 湖南
  1717. '44', // 广东
  1718. '45', // 广西
  1719. '46', // 海南
  1720. '50', // 重庆
  1721. '51', // 四川
  1722. '52', // 贵州
  1723. '53', // 云南
  1724. '54', // 西藏
  1725. '61', // 陕西
  1726. '62', // 甘肃
  1727. '63', // 青海
  1728. '64', // 宁夏
  1729. '65', // 新疆
  1730. '71', // 台湾
  1731. '81', // 香港
  1732. '82', // 澳门
  1733. '91' // 国外
  1734. ];
  1735. var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
  1736. var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
  1737. var checkAddressCode = function checkAddressCode(addressCode) {
  1738. return provincesAndCities.includes(addressCode);
  1739. };
  1740. var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
  1741. var yyyy = parseInt(birDayCode.substring(0, 4), 10);
  1742. var mm = parseInt(birDayCode.substring(4, 6), 10);
  1743. var dd = parseInt(birDayCode.substring(6), 10);
  1744. var xdata = new Date(yyyy, mm - 1, dd);
  1745. if (xdata > new Date()) {
  1746. return false; // eslint-disable-next-line max-len
  1747. } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
  1748. return true;
  1749. }
  1750. return false;
  1751. };
  1752. var getParityBit = function getParityBit(idCardNo) {
  1753. var id17 = idCardNo.substring(0, 17);
  1754. var power = 0;
  1755. for (var i = 0; i < 17; i++) {
  1756. power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
  1757. }
  1758. var mod = power % 11;
  1759. return parityBit[mod];
  1760. };
  1761. var checkParityBit = function checkParityBit(idCardNo) {
  1762. return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
  1763. };
  1764. var check15IdCardNo = function check15IdCardNo(idCardNo) {
  1765. var check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo);
  1766. if (!check) return false;
  1767. var addressCode = idCardNo.substring(0, 2);
  1768. check = checkAddressCode(addressCode);
  1769. if (!check) return false;
  1770. var birDayCode = "19".concat(idCardNo.substring(6, 12));
  1771. check = checkBirthDayCode(birDayCode);
  1772. if (!check) return false;
  1773. return true;
  1774. };
  1775. var check18IdCardNo = function check18IdCardNo(idCardNo) {
  1776. var check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo);
  1777. if (!check) return false;
  1778. var addressCode = idCardNo.substring(0, 2);
  1779. check = checkAddressCode(addressCode);
  1780. if (!check) return false;
  1781. var birDayCode = idCardNo.substring(6, 14);
  1782. check = checkBirthDayCode(birDayCode);
  1783. if (!check) return false;
  1784. return checkParityBit(idCardNo);
  1785. };
  1786. var checkIdCardNo = function checkIdCardNo(idCardNo) {
  1787. var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
  1788. if (!check) return false;
  1789. if (idCardNo.length === 15) {
  1790. return check15IdCardNo(idCardNo);
  1791. }
  1792. return check18IdCardNo(idCardNo);
  1793. };
  1794. return checkIdCardNo(str);
  1795. },
  1796. 'zh-TW': function zhTW(str) {
  1797. var ALPHABET_CODES = {
  1798. A: 10,
  1799. B: 11,
  1800. C: 12,
  1801. D: 13,
  1802. E: 14,
  1803. F: 15,
  1804. G: 16,
  1805. H: 17,
  1806. I: 34,
  1807. J: 18,
  1808. K: 19,
  1809. L: 20,
  1810. M: 21,
  1811. N: 22,
  1812. O: 35,
  1813. P: 23,
  1814. Q: 24,
  1815. R: 25,
  1816. S: 26,
  1817. T: 27,
  1818. U: 28,
  1819. V: 29,
  1820. W: 32,
  1821. X: 30,
  1822. Y: 31,
  1823. Z: 33
  1824. };
  1825. var sanitized = str.trim().toUpperCase();
  1826. if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
  1827. return Array.from(sanitized).reduce(function (sum, number, index) {
  1828. if (index === 0) {
  1829. var code = ALPHABET_CODES[number];
  1830. return code % 10 * 9 + Math.floor(code / 10);
  1831. }
  1832. if (index === 9) {
  1833. return (10 - sum % 10 - Number(number)) % 10 === 0;
  1834. }
  1835. return sum + Number(number) * (9 - index);
  1836. }, 0);
  1837. }
  1838. };
  1839. function isIdentityCard(str, locale) {
  1840. assertString(str);
  1841. if (locale in validators) {
  1842. return validators[locale](str);
  1843. } else if (locale === 'any') {
  1844. for (var key in validators) {
  1845. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  1846. // istanbul ignore else
  1847. if (validators.hasOwnProperty(key)) {
  1848. var validator = validators[key];
  1849. if (validator(str)) {
  1850. return true;
  1851. }
  1852. }
  1853. }
  1854. return false;
  1855. }
  1856. throw new Error("Invalid locale '".concat(locale, "'"));
  1857. }
  1858. /**
  1859. * The most commonly used EAN standard is
  1860. * the thirteen-digit EAN-13, while the
  1861. * less commonly used 8-digit EAN-8 barcode was
  1862. * introduced for use on small packages.
  1863. * Also EAN/UCC-14 is used for Grouping of individual
  1864. * trade items above unit level(Intermediate, Carton or Pallet).
  1865. * For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
  1866. * EAN consists of:
  1867. * GS1 prefix, manufacturer code, product code and check digit
  1868. * Reference: https://en.wikipedia.org/wiki/International_Article_Number
  1869. * Reference: https://www.gtin.info/
  1870. */
  1871. /**
  1872. * Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
  1873. * and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
  1874. * with exact numberic matching of 8 or 13 or 14 digits [0-9]
  1875. */
  1876. var LENGTH_EAN_8 = 8;
  1877. var LENGTH_EAN_14 = 14;
  1878. var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
  1879. /**
  1880. * Get position weight given:
  1881. * EAN length and digit index/position
  1882. *
  1883. * @param {number} length
  1884. * @param {number} index
  1885. * @return {number}
  1886. */
  1887. function getPositionWeightThroughLengthAndIndex(length, index) {
  1888. if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
  1889. return index % 2 === 0 ? 3 : 1;
  1890. }
  1891. return index % 2 === 0 ? 1 : 3;
  1892. }
  1893. /**
  1894. * Calculate EAN Check Digit
  1895. * Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
  1896. *
  1897. * @param {string} ean
  1898. * @return {number}
  1899. */
  1900. function calculateCheckDigit(ean) {
  1901. var checksum = ean.slice(0, -1).split('').map(function (_char, index) {
  1902. return Number(_char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
  1903. }).reduce(function (acc, partialSum) {
  1904. return acc + partialSum;
  1905. }, 0);
  1906. var remainder = 10 - checksum % 10;
  1907. return remainder < 10 ? remainder : 0;
  1908. }
  1909. /**
  1910. * Check if string is valid EAN:
  1911. * Matches EAN-8/EAN-13/EAN-14 regex
  1912. * Has valid check digit.
  1913. *
  1914. * @param {string} str
  1915. * @return {boolean}
  1916. */
  1917. function isEAN(str) {
  1918. assertString(str);
  1919. var actualCheckDigit = Number(str.slice(-1));
  1920. return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
  1921. }
  1922. var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/; // this link details how the check digit is calculated:
  1923. // https://www.isin.org/isin-format/. it is a little bit
  1924. // odd in that it works with digits, not numbers. in order
  1925. // to make only one pass through the ISIN characters, the
  1926. // each alpha character is handled as 2 characters within
  1927. // the loop.
  1928. function isISIN(str) {
  1929. assertString(str);
  1930. if (!isin.test(str)) {
  1931. return false;
  1932. }
  1933. var _double = true;
  1934. var sum = 0; // convert values
  1935. for (var i = str.length - 2; i >= 0; i--) {
  1936. if (str[i] >= 'A' && str[i] <= 'Z') {
  1937. var value = str[i].charCodeAt(0) - 55;
  1938. var lo = value % 10;
  1939. var hi = Math.trunc(value / 10); // letters have two digits, so handle the low order
  1940. // and high order digits separately.
  1941. for (var _i = 0, _arr = [lo, hi]; _i < _arr.length; _i++) {
  1942. var digit = _arr[_i];
  1943. if (_double) {
  1944. if (digit >= 5) {
  1945. sum += 1 + (digit - 5) * 2;
  1946. } else {
  1947. sum += digit * 2;
  1948. }
  1949. } else {
  1950. sum += digit;
  1951. }
  1952. _double = !_double;
  1953. }
  1954. } else {
  1955. var _digit = str[i].charCodeAt(0) - '0'.charCodeAt(0);
  1956. if (_double) {
  1957. if (_digit >= 5) {
  1958. sum += 1 + (_digit - 5) * 2;
  1959. } else {
  1960. sum += _digit * 2;
  1961. }
  1962. } else {
  1963. sum += _digit;
  1964. }
  1965. _double = !_double;
  1966. }
  1967. }
  1968. var check = Math.trunc((sum + 9) / 10) * 10 - sum;
  1969. return +str[str.length - 1] === check;
  1970. }
  1971. var isbn10Maybe = /^(?:[0-9]{9}X|[0-9]{10})$/;
  1972. var isbn13Maybe = /^(?:[0-9]{13})$/;
  1973. var factor = [1, 3];
  1974. function isISBN(str) {
  1975. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  1976. assertString(str);
  1977. version = String(version);
  1978. if (!version) {
  1979. return isISBN(str, 10) || isISBN(str, 13);
  1980. }
  1981. var sanitized = str.replace(/[\s-]+/g, '');
  1982. var checksum = 0;
  1983. var i;
  1984. if (version === '10') {
  1985. if (!isbn10Maybe.test(sanitized)) {
  1986. return false;
  1987. }
  1988. for (i = 0; i < 9; i++) {
  1989. checksum += (i + 1) * sanitized.charAt(i);
  1990. }
  1991. if (sanitized.charAt(9) === 'X') {
  1992. checksum += 10 * 10;
  1993. } else {
  1994. checksum += 10 * sanitized.charAt(9);
  1995. }
  1996. if (checksum % 11 === 0) {
  1997. return !!sanitized;
  1998. }
  1999. } else if (version === '13') {
  2000. if (!isbn13Maybe.test(sanitized)) {
  2001. return false;
  2002. }
  2003. for (i = 0; i < 12; i++) {
  2004. checksum += factor[i % 2] * sanitized.charAt(i);
  2005. }
  2006. if (sanitized.charAt(12) - (10 - checksum % 10) % 10 === 0) {
  2007. return !!sanitized;
  2008. }
  2009. }
  2010. return false;
  2011. }
  2012. var issn = '^\\d{4}-?\\d{3}[\\dX]$';
  2013. function isISSN(str) {
  2014. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2015. assertString(str);
  2016. var testIssn = issn;
  2017. testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn;
  2018. testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i');
  2019. if (!testIssn.test(str)) {
  2020. return false;
  2021. }
  2022. var digits = str.replace('-', '').toUpperCase();
  2023. var checksum = 0;
  2024. for (var i = 0; i < digits.length; i++) {
  2025. var digit = digits[i];
  2026. checksum += (digit === 'X' ? 10 : +digit) * (8 - i);
  2027. }
  2028. return checksum % 11 === 0;
  2029. }
  2030. /**
  2031. * Algorithmic validation functions
  2032. * May be used as is or implemented in the workflow of other validators.
  2033. */
  2034. /*
  2035. * ISO 7064 validation function
  2036. * Called with a string of numbers (incl. check digit)
  2037. * to validate according to ISO 7064 (MOD 11, 10).
  2038. */
  2039. function iso7064Check(str) {
  2040. var checkvalue = 10;
  2041. for (var i = 0; i < str.length - 1; i++) {
  2042. checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11;
  2043. }
  2044. checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue;
  2045. return checkvalue === parseInt(str[10], 10);
  2046. }
  2047. /*
  2048. * Luhn (mod 10) validation function
  2049. * Called with a string of numbers (incl. check digit)
  2050. * to validate according to the Luhn algorithm.
  2051. */
  2052. function luhnCheck(str) {
  2053. var checksum = 0;
  2054. var second = false;
  2055. for (var i = str.length - 1; i >= 0; i--) {
  2056. if (second) {
  2057. var product = parseInt(str[i], 10) * 2;
  2058. if (product > 9) {
  2059. // sum digits of product and add to checksum
  2060. checksum += product.toString().split('').map(function (a) {
  2061. return parseInt(a, 10);
  2062. }).reduce(function (a, b) {
  2063. return a + b;
  2064. }, 0);
  2065. } else {
  2066. checksum += product;
  2067. }
  2068. } else {
  2069. checksum += parseInt(str[i], 10);
  2070. }
  2071. second = !second;
  2072. }
  2073. return checksum % 10 === 0;
  2074. }
  2075. /*
  2076. * Reverse TIN multiplication and summation helper function
  2077. * Called with an array of single-digit integers and a base multiplier
  2078. * to calculate the sum of the digits multiplied in reverse.
  2079. * Normally used in variations of MOD 11 algorithmic checks.
  2080. */
  2081. function reverseMultiplyAndSum(digits, base) {
  2082. var total = 0;
  2083. for (var i = 0; i < digits.length; i++) {
  2084. total += digits[i] * (base - i);
  2085. }
  2086. return total;
  2087. }
  2088. /*
  2089. * Verhoeff validation helper function
  2090. * Called with a string of numbers
  2091. * to validate according to the Verhoeff algorithm.
  2092. */
  2093. function verhoeffCheck(str) {
  2094. var d_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
  2095. var p_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]]; // Copy (to prevent replacement) and reverse
  2096. var str_copy = str.split('').reverse().join('');
  2097. var checksum = 0;
  2098. for (var i = 0; i < str_copy.length; i++) {
  2099. checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]];
  2100. }
  2101. return checksum === 0;
  2102. }
  2103. /**
  2104. * TIN Validation
  2105. * Validates Tax Identification Numbers (TINs) from the US, EU member states and the United Kingdom.
  2106. *
  2107. * EU-UK:
  2108. * National TIN validity is calculated using public algorithms as made available by DG TAXUD.
  2109. *
  2110. * See `https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx` for more information.
  2111. *
  2112. * US:
  2113. * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number,
  2114. * is used to identify a business entity.
  2115. *
  2116. * NOTES:
  2117. * - Prefix 47 is being reserved for future use
  2118. * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus.
  2119. *
  2120. * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes`
  2121. * for more information.
  2122. */
  2123. // Locale functions
  2124. /*
  2125. * bg-BG validation function
  2126. * (Edinen graždanski nomer (EGN/ЕГН), persons only)
  2127. * Checks if birth date (first six digits) is valid and calculates check (last) digit
  2128. */
  2129. function bgBgCheck(tin) {
  2130. // Extract full year, normalize month and check birth date validity
  2131. var century_year = tin.slice(0, 2);
  2132. var month = parseInt(tin.slice(2, 4), 10);
  2133. if (month > 40) {
  2134. month -= 40;
  2135. century_year = "20".concat(century_year);
  2136. } else if (month > 20) {
  2137. month -= 20;
  2138. century_year = "18".concat(century_year);
  2139. } else {
  2140. century_year = "19".concat(century_year);
  2141. }
  2142. if (month < 10) {
  2143. month = "0".concat(month);
  2144. }
  2145. var date = "".concat(century_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2146. if (!isDate(date, 'YYYY/MM/DD')) {
  2147. return false;
  2148. } // split digits into an array for further processing
  2149. var digits = tin.split('').map(function (a) {
  2150. return parseInt(a, 10);
  2151. }); // Calculate checksum by multiplying digits with fixed values
  2152. var multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2153. var checksum = 0;
  2154. for (var i = 0; i < multip_lookup.length; i++) {
  2155. checksum += digits[i] * multip_lookup[i];
  2156. }
  2157. checksum = checksum % 11 === 10 ? 0 : checksum % 11;
  2158. return checksum === digits[9];
  2159. }
  2160. /*
  2161. * cs-CZ validation function
  2162. * (Rodné číslo (RČ), persons only)
  2163. * Checks if birth date (first six digits) is valid and divisibility by 11
  2164. * Material not in DG TAXUD document sourced from:
  2165. * -`https://lorenc.info/3MA381/overeni-spravnosti-rodneho-cisla.htm`
  2166. * -`https://www.mvcr.cz/clanek/rady-a-sluzby-dokumenty-rodne-cislo.aspx`
  2167. */
  2168. function csCzCheck(tin) {
  2169. tin = tin.replace(/\W/, ''); // Extract full year from TIN length
  2170. var full_year = parseInt(tin.slice(0, 2), 10);
  2171. if (tin.length === 10) {
  2172. if (full_year < 54) {
  2173. full_year = "20".concat(full_year);
  2174. } else {
  2175. full_year = "19".concat(full_year);
  2176. }
  2177. } else {
  2178. if (tin.slice(6) === '000') {
  2179. return false;
  2180. } // Three-zero serial not assigned before 1954
  2181. if (full_year < 54) {
  2182. full_year = "19".concat(full_year);
  2183. } else {
  2184. return false; // No 18XX years seen in any of the resources
  2185. }
  2186. } // Add missing zero if needed
  2187. if (full_year.length === 3) {
  2188. full_year = [full_year.slice(0, 2), '0', full_year.slice(2)].join('');
  2189. } // Extract month from TIN and normalize
  2190. var month = parseInt(tin.slice(2, 4), 10);
  2191. if (month > 50) {
  2192. month -= 50;
  2193. }
  2194. if (month > 20) {
  2195. // Month-plus-twenty was only introduced in 2004
  2196. if (parseInt(full_year, 10) < 2004) {
  2197. return false;
  2198. }
  2199. month -= 20;
  2200. }
  2201. if (month < 10) {
  2202. month = "0".concat(month);
  2203. } // Check date validity
  2204. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2205. if (!isDate(date, 'YYYY/MM/DD')) {
  2206. return false;
  2207. } // Verify divisibility by 11
  2208. if (tin.length === 10) {
  2209. if (parseInt(tin, 10) % 11 !== 0) {
  2210. // Some numbers up to and including 1985 are still valid if
  2211. // check (last) digit equals 0 and modulo of first 9 digits equals 10
  2212. var checkdigit = parseInt(tin.slice(0, 9), 10) % 11;
  2213. if (parseInt(full_year, 10) < 1986 && checkdigit === 10) {
  2214. if (parseInt(tin.slice(9), 10) !== 0) {
  2215. return false;
  2216. }
  2217. } else {
  2218. return false;
  2219. }
  2220. }
  2221. }
  2222. return true;
  2223. }
  2224. /*
  2225. * de-AT validation function
  2226. * (Abgabenkontonummer, persons/entities)
  2227. * Verify TIN validity by calling luhnCheck()
  2228. */
  2229. function deAtCheck(tin) {
  2230. return luhnCheck(tin);
  2231. }
  2232. /*
  2233. * de-DE validation function
  2234. * (Steueridentifikationsnummer (Steuer-IdNr.), persons only)
  2235. * Tests for single duplicate/triplicate value, then calculates ISO 7064 check (last) digit
  2236. * Partial implementation of spec (same result with both algorithms always)
  2237. */
  2238. function deDeCheck(tin) {
  2239. // Split digits into an array for further processing
  2240. var digits = tin.split('').map(function (a) {
  2241. return parseInt(a, 10);
  2242. }); // Fill array with strings of number positions
  2243. var occurences = [];
  2244. for (var i = 0; i < digits.length - 1; i++) {
  2245. occurences.push('');
  2246. for (var j = 0; j < digits.length - 1; j++) {
  2247. if (digits[i] === digits[j]) {
  2248. occurences[i] += j;
  2249. }
  2250. }
  2251. } // Remove digits with one occurence and test for only one duplicate/triplicate
  2252. occurences = occurences.filter(function (a) {
  2253. return a.length > 1;
  2254. });
  2255. if (occurences.length !== 2 && occurences.length !== 3) {
  2256. return false;
  2257. } // In case of triplicate value only two digits are allowed next to each other
  2258. if (occurences[0].length === 3) {
  2259. var trip_locations = occurences[0].split('').map(function (a) {
  2260. return parseInt(a, 10);
  2261. });
  2262. var recurrent = 0; // Amount of neighbour occurences
  2263. for (var _i = 0; _i < trip_locations.length - 1; _i++) {
  2264. if (trip_locations[_i] + 1 === trip_locations[_i + 1]) {
  2265. recurrent += 1;
  2266. }
  2267. }
  2268. if (recurrent === 2) {
  2269. return false;
  2270. }
  2271. }
  2272. return iso7064Check(tin);
  2273. }
  2274. /*
  2275. * dk-DK validation function
  2276. * (CPR-nummer (personnummer), persons only)
  2277. * Checks if birth date (first six digits) is valid and assigned to century (seventh) digit,
  2278. * and calculates check (last) digit
  2279. */
  2280. function dkDkCheck(tin) {
  2281. tin = tin.replace(/\W/, ''); // Extract year, check if valid for given century digit and add century
  2282. var year = parseInt(tin.slice(4, 6), 10);
  2283. var century_digit = tin.slice(6, 7);
  2284. switch (century_digit) {
  2285. case '0':
  2286. case '1':
  2287. case '2':
  2288. case '3':
  2289. year = "19".concat(year);
  2290. break;
  2291. case '4':
  2292. case '9':
  2293. if (year < 37) {
  2294. year = "20".concat(year);
  2295. } else {
  2296. year = "19".concat(year);
  2297. }
  2298. break;
  2299. default:
  2300. if (year < 37) {
  2301. year = "20".concat(year);
  2302. } else if (year > 58) {
  2303. year = "18".concat(year);
  2304. } else {
  2305. return false;
  2306. }
  2307. break;
  2308. } // Add missing zero if needed
  2309. if (year.length === 3) {
  2310. year = [year.slice(0, 2), '0', year.slice(2)].join('');
  2311. } // Check date validity
  2312. var date = "".concat(year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  2313. if (!isDate(date, 'YYYY/MM/DD')) {
  2314. return false;
  2315. } // Split digits into an array for further processing
  2316. var digits = tin.split('').map(function (a) {
  2317. return parseInt(a, 10);
  2318. });
  2319. var checksum = 0;
  2320. var weight = 4; // Multiply by weight and add to checksum
  2321. for (var i = 0; i < 9; i++) {
  2322. checksum += digits[i] * weight;
  2323. weight -= 1;
  2324. if (weight === 1) {
  2325. weight = 7;
  2326. }
  2327. }
  2328. checksum %= 11;
  2329. if (checksum === 1) {
  2330. return false;
  2331. }
  2332. return checksum === 0 ? digits[9] === 0 : digits[9] === 11 - checksum;
  2333. }
  2334. /*
  2335. * el-CY validation function
  2336. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons only)
  2337. * Verify TIN validity by calculating ASCII value of check (last) character
  2338. */
  2339. function elCyCheck(tin) {
  2340. // split digits into an array for further processing
  2341. var digits = tin.slice(0, 8).split('').map(function (a) {
  2342. return parseInt(a, 10);
  2343. });
  2344. var checksum = 0; // add digits in even places
  2345. for (var i = 1; i < digits.length; i += 2) {
  2346. checksum += digits[i];
  2347. } // add digits in odd places
  2348. for (var _i2 = 0; _i2 < digits.length; _i2 += 2) {
  2349. if (digits[_i2] < 2) {
  2350. checksum += 1 - digits[_i2];
  2351. } else {
  2352. checksum += 2 * (digits[_i2] - 2) + 5;
  2353. if (digits[_i2] > 4) {
  2354. checksum += 2;
  2355. }
  2356. }
  2357. }
  2358. return String.fromCharCode(checksum % 26 + 65) === tin.charAt(8);
  2359. }
  2360. /*
  2361. * el-GR validation function
  2362. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons/entities)
  2363. * Verify TIN validity by calculating check (last) digit
  2364. * Algorithm not in DG TAXUD document- sourced from:
  2365. * - `http://epixeirisi.gr/%CE%9A%CE%A1%CE%99%CE%A3%CE%99%CE%9C%CE%91-%CE%98%CE%95%CE%9C%CE%91%CE%A4%CE%91-%CE%A6%CE%9F%CE%A1%CE%9F%CE%9B%CE%9F%CE%93%CE%99%CE%91%CE%A3-%CE%9A%CE%91%CE%99-%CE%9B%CE%9F%CE%93%CE%99%CE%A3%CE%A4%CE%99%CE%9A%CE%97%CE%A3/23791/%CE%91%CF%81%CE%B9%CE%B8%CE%BC%CF%8C%CF%82-%CE%A6%CE%BF%CF%81%CE%BF%CE%BB%CE%BF%CE%B3%CE%B9%CE%BA%CE%BF%CF%8D-%CE%9C%CE%B7%CF%84%CF%81%CF%8E%CE%BF%CF%85`
  2366. */
  2367. function elGrCheck(tin) {
  2368. // split digits into an array for further processing
  2369. var digits = tin.split('').map(function (a) {
  2370. return parseInt(a, 10);
  2371. });
  2372. var checksum = 0;
  2373. for (var i = 0; i < 8; i++) {
  2374. checksum += digits[i] * Math.pow(2, 8 - i);
  2375. }
  2376. return checksum % 11 % 10 === digits[8];
  2377. }
  2378. /*
  2379. * en-GB validation function (should go here if needed)
  2380. * (National Insurance Number (NINO) or Unique Taxpayer Reference (UTR),
  2381. * persons/entities respectively)
  2382. */
  2383. /*
  2384. * en-IE validation function
  2385. * (Personal Public Service Number (PPS No), persons only)
  2386. * Verify TIN validity by calculating check (second to last) character
  2387. */
  2388. function enIeCheck(tin) {
  2389. var checksum = reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  2390. return parseInt(a, 10);
  2391. }), 8);
  2392. if (tin.length === 9 && tin[8] !== 'W') {
  2393. checksum += (tin[8].charCodeAt(0) - 64) * 9;
  2394. }
  2395. checksum %= 23;
  2396. if (checksum === 0) {
  2397. return tin[7].toUpperCase() === 'W';
  2398. }
  2399. return tin[7].toUpperCase() === String.fromCharCode(64 + checksum);
  2400. } // Valid US IRS campus prefixes
  2401. var enUsCampusPrefix = {
  2402. andover: ['10', '12'],
  2403. atlanta: ['60', '67'],
  2404. austin: ['50', '53'],
  2405. brookhaven: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
  2406. cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
  2407. fresno: ['15', '24'],
  2408. internet: ['20', '26', '27', '45', '46', '47'],
  2409. kansas: ['40', '44'],
  2410. memphis: ['94', '95'],
  2411. ogden: ['80', '90'],
  2412. philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
  2413. sba: ['31']
  2414. }; // Return an array of all US IRS campus prefixes
  2415. function enUsGetPrefixes() {
  2416. var prefixes = [];
  2417. for (var location in enUsCampusPrefix) {
  2418. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  2419. // istanbul ignore else
  2420. if (enUsCampusPrefix.hasOwnProperty(location)) {
  2421. prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location]));
  2422. }
  2423. }
  2424. return prefixes;
  2425. }
  2426. /*
  2427. * en-US validation function
  2428. * Verify that the TIN starts with a valid IRS campus prefix
  2429. */
  2430. function enUsCheck(tin) {
  2431. return enUsGetPrefixes().indexOf(tin.substr(0, 2)) !== -1;
  2432. }
  2433. /*
  2434. * es-ES validation function
  2435. * (Documento Nacional de Identidad (DNI)
  2436. * or Número de Identificación de Extranjero (NIE), persons only)
  2437. * Verify TIN validity by calculating check (last) character
  2438. */
  2439. function esEsCheck(tin) {
  2440. // Split characters into an array for further processing
  2441. var chars = tin.toUpperCase().split(''); // Replace initial letter if needed
  2442. if (isNaN(parseInt(chars[0], 10)) && chars.length > 1) {
  2443. var lead_replace = 0;
  2444. switch (chars[0]) {
  2445. case 'Y':
  2446. lead_replace = 1;
  2447. break;
  2448. case 'Z':
  2449. lead_replace = 2;
  2450. break;
  2451. default:
  2452. }
  2453. chars.splice(0, 1, lead_replace); // Fill with zeros if smaller than proper
  2454. } else {
  2455. while (chars.length < 9) {
  2456. chars.unshift(0);
  2457. }
  2458. } // Calculate checksum and check according to lookup
  2459. var lookup = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'];
  2460. chars = chars.join('');
  2461. var checksum = parseInt(chars.slice(0, 8), 10) % 23;
  2462. return chars[8] === lookup[checksum];
  2463. }
  2464. /*
  2465. * et-EE validation function
  2466. * (Isikukood (IK), persons only)
  2467. * Checks if birth date (century digit and six following) is valid and calculates check (last) digit
  2468. * Material not in DG TAXUD document sourced from:
  2469. * - `https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Estonia-TIN.pdf`
  2470. */
  2471. function etEeCheck(tin) {
  2472. // Extract year and add century
  2473. var full_year = tin.slice(1, 3);
  2474. var century_digit = tin.slice(0, 1);
  2475. switch (century_digit) {
  2476. case '1':
  2477. case '2':
  2478. full_year = "18".concat(full_year);
  2479. break;
  2480. case '3':
  2481. case '4':
  2482. full_year = "19".concat(full_year);
  2483. break;
  2484. default:
  2485. full_year = "20".concat(full_year);
  2486. break;
  2487. } // Check date validity
  2488. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  2489. if (!isDate(date, 'YYYY/MM/DD')) {
  2490. return false;
  2491. } // Split digits into an array for further processing
  2492. var digits = tin.split('').map(function (a) {
  2493. return parseInt(a, 10);
  2494. });
  2495. var checksum = 0;
  2496. var weight = 1; // Multiply by weight and add to checksum
  2497. for (var i = 0; i < 10; i++) {
  2498. checksum += digits[i] * weight;
  2499. weight += 1;
  2500. if (weight === 10) {
  2501. weight = 1;
  2502. }
  2503. } // Do again if modulo 11 of checksum is 10
  2504. if (checksum % 11 === 10) {
  2505. checksum = 0;
  2506. weight = 3;
  2507. for (var _i3 = 0; _i3 < 10; _i3++) {
  2508. checksum += digits[_i3] * weight;
  2509. weight += 1;
  2510. if (weight === 10) {
  2511. weight = 1;
  2512. }
  2513. }
  2514. if (checksum % 11 === 10) {
  2515. return digits[10] === 0;
  2516. }
  2517. }
  2518. return checksum % 11 === digits[10];
  2519. }
  2520. /*
  2521. * fi-FI validation function
  2522. * (Henkilötunnus (HETU), persons only)
  2523. * Checks if birth date (first six digits plus century symbol) is valid
  2524. * and calculates check (last) digit
  2525. */
  2526. function fiFiCheck(tin) {
  2527. // Extract year and add century
  2528. var full_year = tin.slice(4, 6);
  2529. var century_symbol = tin.slice(6, 7);
  2530. switch (century_symbol) {
  2531. case '+':
  2532. full_year = "18".concat(full_year);
  2533. break;
  2534. case '-':
  2535. full_year = "19".concat(full_year);
  2536. break;
  2537. default:
  2538. full_year = "20".concat(full_year);
  2539. break;
  2540. } // Check date validity
  2541. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  2542. if (!isDate(date, 'YYYY/MM/DD')) {
  2543. return false;
  2544. } // Calculate check character
  2545. var checksum = parseInt(tin.slice(0, 6) + tin.slice(7, 10), 10) % 31;
  2546. if (checksum < 10) {
  2547. return checksum === parseInt(tin.slice(10), 10);
  2548. }
  2549. checksum -= 10;
  2550. var letters_lookup = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'];
  2551. return letters_lookup[checksum] === tin.slice(10);
  2552. }
  2553. /*
  2554. * fr/nl-BE validation function
  2555. * (Numéro national (N.N.), persons only)
  2556. * Checks if birth date (first six digits) is valid and calculates check (last two) digits
  2557. */
  2558. function frBeCheck(tin) {
  2559. // Zero month/day value is acceptable
  2560. if (tin.slice(2, 4) !== '00' || tin.slice(4, 6) !== '00') {
  2561. // Extract date from first six digits of TIN
  2562. var date = "".concat(tin.slice(0, 2), "/").concat(tin.slice(2, 4), "/").concat(tin.slice(4, 6));
  2563. if (!isDate(date, 'YY/MM/DD')) {
  2564. return false;
  2565. }
  2566. }
  2567. var checksum = 97 - parseInt(tin.slice(0, 9), 10) % 97;
  2568. var checkdigits = parseInt(tin.slice(9, 11), 10);
  2569. if (checksum !== checkdigits) {
  2570. checksum = 97 - parseInt("2".concat(tin.slice(0, 9)), 10) % 97;
  2571. if (checksum !== checkdigits) {
  2572. return false;
  2573. }
  2574. }
  2575. return true;
  2576. }
  2577. /*
  2578. * fr-FR validation function
  2579. * (Numéro fiscal de référence (numéro SPI), persons only)
  2580. * Verify TIN validity by calculating check (last three) digits
  2581. */
  2582. function frFrCheck(tin) {
  2583. tin = tin.replace(/\s/g, '');
  2584. var checksum = parseInt(tin.slice(0, 10), 10) % 511;
  2585. var checkdigits = parseInt(tin.slice(10, 13), 10);
  2586. return checksum === checkdigits;
  2587. }
  2588. /*
  2589. * fr/lb-LU validation function
  2590. * (numéro d’identification personnelle, persons only)
  2591. * Verify birth date validity and run Luhn and Verhoeff checks
  2592. */
  2593. function frLuCheck(tin) {
  2594. // Extract date and check validity
  2595. var date = "".concat(tin.slice(0, 4), "/").concat(tin.slice(4, 6), "/").concat(tin.slice(6, 8));
  2596. if (!isDate(date, 'YYYY/MM/DD')) {
  2597. return false;
  2598. } // Run Luhn check
  2599. if (!luhnCheck(tin.slice(0, 12))) {
  2600. return false;
  2601. } // Remove Luhn check digit and run Verhoeff check
  2602. return verhoeffCheck("".concat(tin.slice(0, 11)).concat(tin[12]));
  2603. }
  2604. /*
  2605. * hr-HR validation function
  2606. * (Osobni identifikacijski broj (OIB), persons/entities)
  2607. * Verify TIN validity by calling iso7064Check(digits)
  2608. */
  2609. function hrHrCheck(tin) {
  2610. return iso7064Check(tin);
  2611. }
  2612. /*
  2613. * hu-HU validation function
  2614. * (Adóazonosító jel, persons only)
  2615. * Verify TIN validity by calculating check (last) digit
  2616. */
  2617. function huHuCheck(tin) {
  2618. // split digits into an array for further processing
  2619. var digits = tin.split('').map(function (a) {
  2620. return parseInt(a, 10);
  2621. });
  2622. var checksum = 8;
  2623. for (var i = 1; i < 9; i++) {
  2624. checksum += digits[i] * (i + 1);
  2625. }
  2626. return checksum % 11 === digits[9];
  2627. }
  2628. /*
  2629. * lt-LT validation function (should go here if needed)
  2630. * (Asmens kodas, persons/entities respectively)
  2631. * Current validation check is alias of etEeCheck- same format applies
  2632. */
  2633. /*
  2634. * it-IT first/last name validity check
  2635. * Accepts it-IT TIN-encoded names as a three-element character array and checks their validity
  2636. * Due to lack of clarity between resources ("Are only Italian consonants used?
  2637. * What happens if a person has X in their name?" etc.) only two test conditions
  2638. * have been implemented:
  2639. * Vowels may only be followed by other vowels or an X character
  2640. * and X characters after vowels may only be followed by other X characters.
  2641. */
  2642. function itItNameCheck(name) {
  2643. // true at the first occurence of a vowel
  2644. var vowelflag = false; // true at the first occurence of an X AFTER vowel
  2645. // (to properly handle last names with X as consonant)
  2646. var xflag = false;
  2647. for (var i = 0; i < 3; i++) {
  2648. if (!vowelflag && /[AEIOU]/.test(name[i])) {
  2649. vowelflag = true;
  2650. } else if (!xflag && vowelflag && name[i] === 'X') {
  2651. xflag = true;
  2652. } else if (i > 0) {
  2653. if (vowelflag && !xflag) {
  2654. if (!/[AEIOU]/.test(name[i])) {
  2655. return false;
  2656. }
  2657. }
  2658. if (xflag) {
  2659. if (!/X/.test(name[i])) {
  2660. return false;
  2661. }
  2662. }
  2663. }
  2664. }
  2665. return true;
  2666. }
  2667. /*
  2668. * it-IT validation function
  2669. * (Codice fiscale (TIN-IT), persons only)
  2670. * Verify name, birth date and codice catastale validity
  2671. * and calculate check character.
  2672. * Material not in DG-TAXUD document sourced from:
  2673. * `https://en.wikipedia.org/wiki/Italian_fiscal_code`
  2674. */
  2675. function itItCheck(tin) {
  2676. // Capitalize and split characters into an array for further processing
  2677. var chars = tin.toUpperCase().split(''); // Check first and last name validity calling itItNameCheck()
  2678. if (!itItNameCheck(chars.slice(0, 3))) {
  2679. return false;
  2680. }
  2681. if (!itItNameCheck(chars.slice(3, 6))) {
  2682. return false;
  2683. } // Convert letters in number spaces back to numbers if any
  2684. var number_locations = [6, 7, 9, 10, 12, 13, 14];
  2685. var number_replace = {
  2686. L: '0',
  2687. M: '1',
  2688. N: '2',
  2689. P: '3',
  2690. Q: '4',
  2691. R: '5',
  2692. S: '6',
  2693. T: '7',
  2694. U: '8',
  2695. V: '9'
  2696. };
  2697. for (var _i4 = 0, _number_locations = number_locations; _i4 < _number_locations.length; _i4++) {
  2698. var i = _number_locations[_i4];
  2699. if (chars[i] in number_replace) {
  2700. chars.splice(i, 1, number_replace[chars[i]]);
  2701. }
  2702. } // Extract month and day, and check date validity
  2703. var month_replace = {
  2704. A: '01',
  2705. B: '02',
  2706. C: '03',
  2707. D: '04',
  2708. E: '05',
  2709. H: '06',
  2710. L: '07',
  2711. M: '08',
  2712. P: '09',
  2713. R: '10',
  2714. S: '11',
  2715. T: '12'
  2716. };
  2717. var month = month_replace[chars[8]];
  2718. var day = parseInt(chars[9] + chars[10], 10);
  2719. if (day > 40) {
  2720. day -= 40;
  2721. }
  2722. if (day < 10) {
  2723. day = "0".concat(day);
  2724. }
  2725. var date = "".concat(chars[6]).concat(chars[7], "/").concat(month, "/").concat(day);
  2726. if (!isDate(date, 'YY/MM/DD')) {
  2727. return false;
  2728. } // Calculate check character by adding up even and odd characters as numbers
  2729. var checksum = 0;
  2730. for (var _i5 = 1; _i5 < chars.length - 1; _i5 += 2) {
  2731. var char_to_int = parseInt(chars[_i5], 10);
  2732. if (isNaN(char_to_int)) {
  2733. char_to_int = chars[_i5].charCodeAt(0) - 65;
  2734. }
  2735. checksum += char_to_int;
  2736. }
  2737. var odd_convert = {
  2738. // Maps of characters at odd places
  2739. A: 1,
  2740. B: 0,
  2741. C: 5,
  2742. D: 7,
  2743. E: 9,
  2744. F: 13,
  2745. G: 15,
  2746. H: 17,
  2747. I: 19,
  2748. J: 21,
  2749. K: 2,
  2750. L: 4,
  2751. M: 18,
  2752. N: 20,
  2753. O: 11,
  2754. P: 3,
  2755. Q: 6,
  2756. R: 8,
  2757. S: 12,
  2758. T: 14,
  2759. U: 16,
  2760. V: 10,
  2761. W: 22,
  2762. X: 25,
  2763. Y: 24,
  2764. Z: 23,
  2765. 0: 1,
  2766. 1: 0
  2767. };
  2768. for (var _i6 = 0; _i6 < chars.length - 1; _i6 += 2) {
  2769. var _char_to_int = 0;
  2770. if (chars[_i6] in odd_convert) {
  2771. _char_to_int = odd_convert[chars[_i6]];
  2772. } else {
  2773. var multiplier = parseInt(chars[_i6], 10);
  2774. _char_to_int = 2 * multiplier + 1;
  2775. if (multiplier > 4) {
  2776. _char_to_int += 2;
  2777. }
  2778. }
  2779. checksum += _char_to_int;
  2780. }
  2781. if (String.fromCharCode(65 + checksum % 26) !== chars[15]) {
  2782. return false;
  2783. }
  2784. return true;
  2785. }
  2786. /*
  2787. * lv-LV validation function
  2788. * (Personas kods (PK), persons only)
  2789. * Check validity of birth date and calculate check (last) digit
  2790. * Support only for old format numbers (not starting with '32', issued before 2017/07/01)
  2791. * Material not in DG TAXUD document sourced from:
  2792. * `https://boot.ritakafija.lv/forums/index.php?/topic/88314-personas-koda-algoritms-%C4%8Deksumma/`
  2793. */
  2794. function lvLvCheck(tin) {
  2795. tin = tin.replace(/\W/, ''); // Extract date from TIN
  2796. var day = tin.slice(0, 2);
  2797. if (day !== '32') {
  2798. // No date/checksum check if new format
  2799. var month = tin.slice(2, 4);
  2800. if (month !== '00') {
  2801. // No date check if unknown month
  2802. var full_year = tin.slice(4, 6);
  2803. switch (tin[6]) {
  2804. case '0':
  2805. full_year = "18".concat(full_year);
  2806. break;
  2807. case '1':
  2808. full_year = "19".concat(full_year);
  2809. break;
  2810. default:
  2811. full_year = "20".concat(full_year);
  2812. break;
  2813. } // Check date validity
  2814. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(day);
  2815. if (!isDate(date, 'YYYY/MM/DD')) {
  2816. return false;
  2817. }
  2818. } // Calculate check digit
  2819. var checksum = 1101;
  2820. var multip_lookup = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  2821. for (var i = 0; i < tin.length - 1; i++) {
  2822. checksum -= parseInt(tin[i], 10) * multip_lookup[i];
  2823. }
  2824. return parseInt(tin[10], 10) === checksum % 11;
  2825. }
  2826. return true;
  2827. }
  2828. /*
  2829. * mt-MT validation function
  2830. * (Identity Card Number or Unique Taxpayer Reference, persons/entities)
  2831. * Verify Identity Card Number structure (no other tests found)
  2832. */
  2833. function mtMtCheck(tin) {
  2834. if (tin.length !== 9) {
  2835. // No tests for UTR
  2836. var chars = tin.toUpperCase().split(''); // Fill with zeros if smaller than proper
  2837. while (chars.length < 8) {
  2838. chars.unshift(0);
  2839. } // Validate format according to last character
  2840. switch (tin[7]) {
  2841. case 'A':
  2842. case 'P':
  2843. if (parseInt(chars[6], 10) === 0) {
  2844. return false;
  2845. }
  2846. break;
  2847. default:
  2848. {
  2849. var first_part = parseInt(chars.join('').slice(0, 5), 10);
  2850. if (first_part > 32000) {
  2851. return false;
  2852. }
  2853. var second_part = parseInt(chars.join('').slice(5, 7), 10);
  2854. if (first_part === second_part) {
  2855. return false;
  2856. }
  2857. }
  2858. }
  2859. }
  2860. return true;
  2861. }
  2862. /*
  2863. * nl-NL validation function
  2864. * (Burgerservicenummer (BSN) or Rechtspersonen Samenwerkingsverbanden Informatie Nummer (RSIN),
  2865. * persons/entities respectively)
  2866. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  2867. */
  2868. function nlNlCheck(tin) {
  2869. return reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  2870. return parseInt(a, 10);
  2871. }), 9) % 11 === parseInt(tin[8], 10);
  2872. }
  2873. /*
  2874. * pl-PL validation function
  2875. * (Powszechny Elektroniczny System Ewidencji Ludności (PESEL)
  2876. * or Numer identyfikacji podatkowej (NIP), persons/entities)
  2877. * Verify TIN validity by validating birth date (PESEL) and calculating check (last) digit
  2878. */
  2879. function plPlCheck(tin) {
  2880. // NIP
  2881. if (tin.length === 10) {
  2882. // Calculate last digit by multiplying with lookup
  2883. var lookup = [6, 5, 7, 2, 3, 4, 5, 6, 7];
  2884. var _checksum = 0;
  2885. for (var i = 0; i < lookup.length; i++) {
  2886. _checksum += parseInt(tin[i], 10) * lookup[i];
  2887. }
  2888. _checksum %= 11;
  2889. if (_checksum === 10) {
  2890. return false;
  2891. }
  2892. return _checksum === parseInt(tin[9], 10);
  2893. } // PESEL
  2894. // Extract full year using month
  2895. var full_year = tin.slice(0, 2);
  2896. var month = parseInt(tin.slice(2, 4), 10);
  2897. if (month > 80) {
  2898. full_year = "18".concat(full_year);
  2899. month -= 80;
  2900. } else if (month > 60) {
  2901. full_year = "22".concat(full_year);
  2902. month -= 60;
  2903. } else if (month > 40) {
  2904. full_year = "21".concat(full_year);
  2905. month -= 40;
  2906. } else if (month > 20) {
  2907. full_year = "20".concat(full_year);
  2908. month -= 20;
  2909. } else {
  2910. full_year = "19".concat(full_year);
  2911. } // Add leading zero to month if needed
  2912. if (month < 10) {
  2913. month = "0".concat(month);
  2914. } // Check date validity
  2915. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2916. if (!isDate(date, 'YYYY/MM/DD')) {
  2917. return false;
  2918. } // Calculate last digit by mulitplying with odd one-digit numbers except 5
  2919. var checksum = 0;
  2920. var multiplier = 1;
  2921. for (var _i7 = 0; _i7 < tin.length - 1; _i7++) {
  2922. checksum += parseInt(tin[_i7], 10) * multiplier % 10;
  2923. multiplier += 2;
  2924. if (multiplier > 10) {
  2925. multiplier = 1;
  2926. } else if (multiplier === 5) {
  2927. multiplier += 2;
  2928. }
  2929. }
  2930. checksum = 10 - checksum % 10;
  2931. return checksum === parseInt(tin[10], 10);
  2932. }
  2933. /*
  2934. * pt-BR validation function
  2935. * (Cadastro de Pessoas Físicas (CPF, persons)
  2936. * Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
  2937. * Both inputs will be validated
  2938. */
  2939. function ptBrCheck(tin) {
  2940. if (tin.length === 11) {
  2941. var _sum;
  2942. var remainder;
  2943. _sum = 0;
  2944. if ( // Reject known invalid CPFs
  2945. tin === '11111111111' || tin === '22222222222' || tin === '33333333333' || tin === '44444444444' || tin === '55555555555' || tin === '66666666666' || tin === '77777777777' || tin === '88888888888' || tin === '99999999999' || tin === '00000000000') return false;
  2946. for (var i = 1; i <= 9; i++) {
  2947. _sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
  2948. }
  2949. remainder = _sum * 10 % 11;
  2950. if (remainder === 10) remainder = 0;
  2951. if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
  2952. _sum = 0;
  2953. for (var _i8 = 1; _i8 <= 10; _i8++) {
  2954. _sum += parseInt(tin.substring(_i8 - 1, _i8), 10) * (12 - _i8);
  2955. }
  2956. remainder = _sum * 10 % 11;
  2957. if (remainder === 10) remainder = 0;
  2958. if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;
  2959. return true;
  2960. }
  2961. if ( // Reject know invalid CNPJs
  2962. tin === '00000000000000' || tin === '11111111111111' || tin === '22222222222222' || tin === '33333333333333' || tin === '44444444444444' || tin === '55555555555555' || tin === '66666666666666' || tin === '77777777777777' || tin === '88888888888888' || tin === '99999999999999') {
  2963. return false;
  2964. }
  2965. var length = tin.length - 2;
  2966. var identifiers = tin.substring(0, length);
  2967. var verificators = tin.substring(length);
  2968. var sum = 0;
  2969. var pos = length - 7;
  2970. for (var _i9 = length; _i9 >= 1; _i9--) {
  2971. sum += identifiers.charAt(length - _i9) * pos;
  2972. pos -= 1;
  2973. if (pos < 2) {
  2974. pos = 9;
  2975. }
  2976. }
  2977. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  2978. if (result !== parseInt(verificators.charAt(0), 10)) {
  2979. return false;
  2980. }
  2981. length += 1;
  2982. identifiers = tin.substring(0, length);
  2983. sum = 0;
  2984. pos = length - 7;
  2985. for (var _i10 = length; _i10 >= 1; _i10--) {
  2986. sum += identifiers.charAt(length - _i10) * pos;
  2987. pos -= 1;
  2988. if (pos < 2) {
  2989. pos = 9;
  2990. }
  2991. }
  2992. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  2993. if (result !== parseInt(verificators.charAt(1), 10)) {
  2994. return false;
  2995. }
  2996. return true;
  2997. }
  2998. /*
  2999. * pt-PT validation function
  3000. * (Número de identificação fiscal (NIF), persons/entities)
  3001. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3002. */
  3003. function ptPtCheck(tin) {
  3004. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  3005. return parseInt(a, 10);
  3006. }), 9) % 11;
  3007. if (checksum > 9) {
  3008. return parseInt(tin[8], 10) === 0;
  3009. }
  3010. return checksum === parseInt(tin[8], 10);
  3011. }
  3012. /*
  3013. * ro-RO validation function
  3014. * (Cod Numeric Personal (CNP) or Cod de înregistrare fiscală (CIF),
  3015. * persons only)
  3016. * Verify CNP validity by calculating check (last) digit (test not found for CIF)
  3017. * Material not in DG TAXUD document sourced from:
  3018. * `https://en.wikipedia.org/wiki/National_identification_number#Romania`
  3019. */
  3020. function roRoCheck(tin) {
  3021. if (tin.slice(0, 4) !== '9000') {
  3022. // No test found for this format
  3023. // Extract full year using century digit if possible
  3024. var full_year = tin.slice(1, 3);
  3025. switch (tin[0]) {
  3026. case '1':
  3027. case '2':
  3028. full_year = "19".concat(full_year);
  3029. break;
  3030. case '3':
  3031. case '4':
  3032. full_year = "18".concat(full_year);
  3033. break;
  3034. case '5':
  3035. case '6':
  3036. full_year = "20".concat(full_year);
  3037. break;
  3038. default:
  3039. } // Check date validity
  3040. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  3041. if (date.length === 8) {
  3042. if (!isDate(date, 'YY/MM/DD')) {
  3043. return false;
  3044. }
  3045. } else if (!isDate(date, 'YYYY/MM/DD')) {
  3046. return false;
  3047. } // Calculate check digit
  3048. var digits = tin.split('').map(function (a) {
  3049. return parseInt(a, 10);
  3050. });
  3051. var multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
  3052. var checksum = 0;
  3053. for (var i = 0; i < multipliers.length; i++) {
  3054. checksum += digits[i] * multipliers[i];
  3055. }
  3056. if (checksum % 11 === 10) {
  3057. return digits[12] === 1;
  3058. }
  3059. return digits[12] === checksum % 11;
  3060. }
  3061. return true;
  3062. }
  3063. /*
  3064. * sk-SK validation function
  3065. * (Rodné číslo (RČ) or bezvýznamové identifikačné číslo (BIČ), persons only)
  3066. * Checks validity of pre-1954 birth numbers (rodné číslo) only
  3067. * Due to the introduction of the pseudo-random BIČ it is not possible to test
  3068. * post-1954 birth numbers without knowing whether they are BIČ or RČ beforehand
  3069. */
  3070. function skSkCheck(tin) {
  3071. if (tin.length === 9) {
  3072. tin = tin.replace(/\W/, '');
  3073. if (tin.slice(6) === '000') {
  3074. return false;
  3075. } // Three-zero serial not assigned before 1954
  3076. // Extract full year from TIN length
  3077. var full_year = parseInt(tin.slice(0, 2), 10);
  3078. if (full_year > 53) {
  3079. return false;
  3080. }
  3081. if (full_year < 10) {
  3082. full_year = "190".concat(full_year);
  3083. } else {
  3084. full_year = "19".concat(full_year);
  3085. } // Extract month from TIN and normalize
  3086. var month = parseInt(tin.slice(2, 4), 10);
  3087. if (month > 50) {
  3088. month -= 50;
  3089. }
  3090. if (month < 10) {
  3091. month = "0".concat(month);
  3092. } // Check date validity
  3093. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  3094. if (!isDate(date, 'YYYY/MM/DD')) {
  3095. return false;
  3096. }
  3097. }
  3098. return true;
  3099. }
  3100. /*
  3101. * sl-SI validation function
  3102. * (Davčna številka, persons/entities)
  3103. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3104. */
  3105. function slSiCheck(tin) {
  3106. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  3107. return parseInt(a, 10);
  3108. }), 8) % 11;
  3109. if (checksum === 10) {
  3110. return parseInt(tin[7], 10) === 0;
  3111. }
  3112. return checksum === parseInt(tin[7], 10);
  3113. }
  3114. /*
  3115. * sv-SE validation function
  3116. * (Personnummer or samordningsnummer, persons only)
  3117. * Checks validity of birth date and calls luhnCheck() to validate check (last) digit
  3118. */
  3119. function svSeCheck(tin) {
  3120. // Make copy of TIN and normalize to two-digit year form
  3121. var tin_copy = tin.slice(0);
  3122. if (tin.length > 11) {
  3123. tin_copy = tin_copy.slice(2);
  3124. } // Extract date of birth
  3125. var full_year = '';
  3126. var month = tin_copy.slice(2, 4);
  3127. var day = parseInt(tin_copy.slice(4, 6), 10);
  3128. if (tin.length > 11) {
  3129. full_year = tin.slice(0, 4);
  3130. } else {
  3131. full_year = tin.slice(0, 2);
  3132. if (tin.length === 11 && day < 60) {
  3133. // Extract full year from centenarian symbol
  3134. // Should work just fine until year 10000 or so
  3135. var current_year = new Date().getFullYear().toString();
  3136. var current_century = parseInt(current_year.slice(0, 2), 10);
  3137. current_year = parseInt(current_year, 10);
  3138. if (tin[6] === '-') {
  3139. if (parseInt("".concat(current_century).concat(full_year), 10) > current_year) {
  3140. full_year = "".concat(current_century - 1).concat(full_year);
  3141. } else {
  3142. full_year = "".concat(current_century).concat(full_year);
  3143. }
  3144. } else {
  3145. full_year = "".concat(current_century - 1).concat(full_year);
  3146. if (current_year - parseInt(full_year, 10) < 100) {
  3147. return false;
  3148. }
  3149. }
  3150. }
  3151. } // Normalize day and check date validity
  3152. if (day > 60) {
  3153. day -= 60;
  3154. }
  3155. if (day < 10) {
  3156. day = "0".concat(day);
  3157. }
  3158. var date = "".concat(full_year, "/").concat(month, "/").concat(day);
  3159. if (date.length === 8) {
  3160. if (!isDate(date, 'YY/MM/DD')) {
  3161. return false;
  3162. }
  3163. } else if (!isDate(date, 'YYYY/MM/DD')) {
  3164. return false;
  3165. }
  3166. return luhnCheck(tin.replace(/\W/, ''));
  3167. } // Locale lookup objects
  3168. /*
  3169. * Tax id regex formats for various locales
  3170. *
  3171. * Where not explicitly specified in DG-TAXUD document both
  3172. * uppercase and lowercase letters are acceptable.
  3173. */
  3174. var taxIdFormat = {
  3175. 'bg-BG': /^\d{10}$/,
  3176. 'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
  3177. 'de-AT': /^\d{9}$/,
  3178. 'de-DE': /^[1-9]\d{10}$/,
  3179. 'dk-DK': /^\d{6}-{0,1}\d{4}$/,
  3180. 'el-CY': /^[09]\d{7}[A-Z]$/,
  3181. 'el-GR': /^([0-4]|[7-9])\d{8}$/,
  3182. 'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
  3183. 'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
  3184. 'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
  3185. 'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i,
  3186. 'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/,
  3187. 'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i,
  3188. 'fr-BE': /^\d{11}$/,
  3189. 'fr-FR': /^[0-3]\d{12}$|^[0-3]\d\s\d{2}(\s\d{3}){3}$/,
  3190. // Conforms both to official spec and provided example
  3191. 'fr-LU': /^\d{13}$/,
  3192. 'hr-HR': /^\d{11}$/,
  3193. 'hu-HU': /^8\d{9}$/,
  3194. 'it-IT': /^[A-Z]{6}[L-NP-V0-9]{2}[A-EHLMPRST][L-NP-V0-9]{2}[A-ILMZ][L-NP-V0-9]{3}[A-Z]$/i,
  3195. 'lv-LV': /^\d{6}-{0,1}\d{5}$/,
  3196. // Conforms both to DG TAXUD spec and original research
  3197. 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
  3198. 'nl-NL': /^\d{9}$/,
  3199. 'pl-PL': /^\d{10,11}$/,
  3200. 'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
  3201. 'pt-PT': /^\d{9}$/,
  3202. 'ro-RO': /^\d{13}$/,
  3203. 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
  3204. 'sl-SI': /^[1-9]\d{7}$/,
  3205. 'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/
  3206. }; // taxIdFormat locale aliases
  3207. taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
  3208. taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
  3209. taxIdFormat['nl-BE'] = taxIdFormat['fr-BE']; // Algorithmic tax id check functions for various locales
  3210. var taxIdCheck = {
  3211. 'bg-BG': bgBgCheck,
  3212. 'cs-CZ': csCzCheck,
  3213. 'de-AT': deAtCheck,
  3214. 'de-DE': deDeCheck,
  3215. 'dk-DK': dkDkCheck,
  3216. 'el-CY': elCyCheck,
  3217. 'el-GR': elGrCheck,
  3218. 'en-IE': enIeCheck,
  3219. 'en-US': enUsCheck,
  3220. 'es-ES': esEsCheck,
  3221. 'et-EE': etEeCheck,
  3222. 'fi-FI': fiFiCheck,
  3223. 'fr-BE': frBeCheck,
  3224. 'fr-FR': frFrCheck,
  3225. 'fr-LU': frLuCheck,
  3226. 'hr-HR': hrHrCheck,
  3227. 'hu-HU': huHuCheck,
  3228. 'it-IT': itItCheck,
  3229. 'lv-LV': lvLvCheck,
  3230. 'mt-MT': mtMtCheck,
  3231. 'nl-NL': nlNlCheck,
  3232. 'pl-PL': plPlCheck,
  3233. 'pt-BR': ptBrCheck,
  3234. 'pt-PT': ptPtCheck,
  3235. 'ro-RO': roRoCheck,
  3236. 'sk-SK': skSkCheck,
  3237. 'sl-SI': slSiCheck,
  3238. 'sv-SE': svSeCheck
  3239. }; // taxIdCheck locale aliases
  3240. taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
  3241. taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
  3242. taxIdCheck['nl-BE'] = taxIdCheck['fr-BE']; // Regexes for locales where characters should be omitted before checking format
  3243. var allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;
  3244. var sanitizeRegexes = {
  3245. 'de-AT': allsymbols,
  3246. 'de-DE': /[\/\\]/g,
  3247. 'fr-BE': allsymbols
  3248. }; // sanitizeRegexes locale aliases
  3249. sanitizeRegexes['nl-BE'] = sanitizeRegexes['fr-BE'];
  3250. /*
  3251. * Validator function
  3252. * Return true if the passed string is a valid tax identification number
  3253. * for the specified locale.
  3254. * Throw an error exception if the locale is not supported.
  3255. */
  3256. function isTaxID(str) {
  3257. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  3258. assertString(str); // Copy TIN to avoid replacement if sanitized
  3259. var strcopy = str.slice(0);
  3260. if (locale in taxIdFormat) {
  3261. if (locale in sanitizeRegexes) {
  3262. strcopy = strcopy.replace(sanitizeRegexes[locale], '');
  3263. }
  3264. if (!taxIdFormat[locale].test(strcopy)) {
  3265. return false;
  3266. }
  3267. if (locale in taxIdCheck) {
  3268. return taxIdCheck[locale](strcopy);
  3269. } // Fallthrough; not all locales have algorithmic checks
  3270. return true;
  3271. }
  3272. throw new Error("Invalid locale '".concat(locale, "'"));
  3273. }
  3274. /* eslint-disable max-len */
  3275. var phones = {
  3276. 'am-AM': /^(\+?374|0)((10|[9|7][0-9])\d{6}$|[2-4]\d{7}$)/,
  3277. 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
  3278. 'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
  3279. 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
  3280. 'ar-LB': /^(\+?961)?((3|81)\d{6}|7\d{7})$/,
  3281. 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
  3282. 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
  3283. 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
  3284. 'ar-KW': /^(\+?965)[569]\d{7}$/,
  3285. 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
  3286. 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/,
  3287. 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/,
  3288. 'ar-PS': /^(\+?970|0)5[6|9](\d{7})$/,
  3289. 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
  3290. 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
  3291. 'ar-TN': /^(\+?216)?[2459]\d{7}$/,
  3292. 'az-AZ': /^(\+994|0)(5[015]|7[07]|99)\d{7}$/,
  3293. 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
  3294. 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
  3295. 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
  3296. 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
  3297. 'ca-AD': /^(\+376)?[346]\d{5}$/,
  3298. 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  3299. 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
  3300. 'de-DE': /^((\+49|0)[1|3])([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/,
  3301. 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
  3302. 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
  3303. 'de-LU': /^(\+352)?((6\d1)\d{6})$/,
  3304. 'dv-MV': /^(\+?960)?(7[2-9]|91|9[3-9])\d{7}$/,
  3305. 'el-GR': /^(\+?30|0)?(69\d{8})$/,
  3306. 'en-AU': /^(\+?61|0)4\d{8}$/,
  3307. 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}))/,
  3308. 'en-GB': /^(\+?44|0)7\d{9}$/,
  3309. 'en-GG': /^(\+?44|0)1481\d{6}$/,
  3310. 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/,
  3311. 'en-GY': /^(\+592|0)6\d{6}$/,
  3312. 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
  3313. 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
  3314. 'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
  3315. 'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
  3316. 'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
  3317. 'en-KI': /^((\+686|686)?)?( )?((6|7)(2|3|8)[0-9]{6})$/,
  3318. 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
  3319. 'en-MU': /^(\+?230|0)?\d{8}$/,
  3320. 'en-NA': /^(\+?264|0)(6|8)\d{7}$/,
  3321. 'en-NG': /^(\+?234|0)?[789]\d{9}$/,
  3322. 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
  3323. 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/,
  3324. 'en-PH': /^(09|\+639)\d{9}$/,
  3325. 'en-RW': /^(\+?250|0)?[7]\d{8}$/,
  3326. 'en-SG': /^(\+65)?[3689]\d{7}$/,
  3327. 'en-SL': /^(\+?232|0)\d{8}$/,
  3328. 'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
  3329. 'en-UG': /^(\+?256|0)?[7]\d{8}$/,
  3330. 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
  3331. 'en-ZA': /^(\+?27|0)\d{9}$/,
  3332. 'en-ZM': /^(\+?26)?09[567]\d{7}$/,
  3333. 'en-ZW': /^(\+263)[0-9]{9}$/,
  3334. 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/,
  3335. 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
  3336. 'es-BO': /^(\+?591)?(6|7)\d{7}$/,
  3337. 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/,
  3338. 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
  3339. 'es-CR': /^(\+506)?[2-8]\d{7}$/,
  3340. 'es-CU': /^(\+53|0053)?5\d{7}/,
  3341. 'es-DO': /^(\+?1)?8[024]9\d{7}$/,
  3342. 'es-HN': /^(\+?504)?[9|8]\d{7}$/,
  3343. 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
  3344. 'es-ES': /^(\+?34)?[6|7]\d{8}$/,
  3345. 'es-PE': /^(\+?51)?9\d{8}$/,
  3346. 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
  3347. 'es-PA': /^(\+?507)\d{7,8}$/,
  3348. 'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
  3349. 'es-SV': /^(\+?503)?[67]\d{7}$/,
  3350. 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
  3351. 'es-VE': /^(\+?58)?(2|4)\d{9}$/,
  3352. 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
  3353. 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
  3354. 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,
  3355. 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
  3356. 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  3357. 'fr-BF': /^(\+226|0)[67]\d{7}$/,
  3358. 'fr-CM': /^(\+?237)6[0-9]{8}$/,
  3359. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  3360. 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
  3361. 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
  3362. 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
  3363. 'fr-PF': /^(\+?689)?8[789]\d{6}$/,
  3364. 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
  3365. 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
  3366. 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/,
  3367. 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
  3368. 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
  3369. 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
  3370. 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
  3371. 'ka-GE': /^(\+?995)?(5|79)\d{7}$/,
  3372. 'kk-KZ': /^(\+?7|8)?7\d{9}$/,
  3373. 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  3374. 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
  3375. 'lt-LT': /^(\+370|8)\d{8}$/,
  3376. 'lv-LV': /^(\+?371)2\d{7}$/,
  3377. 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
  3378. 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/,
  3379. 'nb-NO': /^(\+?47)?[49]\d{7}$/,
  3380. 'ne-NP': /^(\+?977)?9[78]\d{8}$/,
  3381. 'nl-BE': /^(\+?32|0)4\d{8}$/,
  3382. 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
  3383. 'nn-NO': /^(\+?47)?[49]\d{7}$/,
  3384. 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
  3385. 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/,
  3386. 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
  3387. 'pt-AO': /^(\+244)\d{9}$/,
  3388. 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
  3389. 'ru-RU': /^(\+?7|8)?9\d{9}$/,
  3390. 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/,
  3391. 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
  3392. 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  3393. 'sq-AL': /^(\+355|0)6[789]\d{6}$/,
  3394. 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
  3395. 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
  3396. 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/,
  3397. 'th-TH': /^(\+66|66|0)\d{9}$/,
  3398. 'tr-TR': /^(\+?90|0)?5\d{9}$/,
  3399. 'tk-TM': /^(\+993|993|8)\d{8}$/,
  3400. 'uk-UA': /^(\+?38|8)?0\d{9}$/,
  3401. 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
  3402. 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
  3403. 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/,
  3404. 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
  3405. 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/
  3406. };
  3407. /* eslint-enable max-len */
  3408. // aliases
  3409. phones['en-CA'] = phones['en-US'];
  3410. phones['fr-CA'] = phones['en-CA'];
  3411. phones['fr-BE'] = phones['nl-BE'];
  3412. phones['zh-HK'] = phones['en-HK'];
  3413. phones['zh-MO'] = phones['en-MO'];
  3414. phones['ga-IE'] = phones['en-IE'];
  3415. phones['fr-CH'] = phones['de-CH'];
  3416. phones['it-CH'] = phones['fr-CH'];
  3417. function isMobilePhone(str, locale, options) {
  3418. assertString(str);
  3419. if (options && options.strictMode && !str.startsWith('+')) {
  3420. return false;
  3421. }
  3422. if (Array.isArray(locale)) {
  3423. return locale.some(function (key) {
  3424. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  3425. // istanbul ignore else
  3426. if (phones.hasOwnProperty(key)) {
  3427. var phone = phones[key];
  3428. if (phone.test(str)) {
  3429. return true;
  3430. }
  3431. }
  3432. return false;
  3433. });
  3434. } else if (locale in phones) {
  3435. return phones[locale].test(str); // alias falsey locale as 'any'
  3436. } else if (!locale || locale === 'any') {
  3437. for (var key in phones) {
  3438. // istanbul ignore else
  3439. if (phones.hasOwnProperty(key)) {
  3440. var phone = phones[key];
  3441. if (phone.test(str)) {
  3442. return true;
  3443. }
  3444. }
  3445. }
  3446. return false;
  3447. }
  3448. throw new Error("Invalid locale '".concat(locale, "'"));
  3449. }
  3450. var locales$4 = Object.keys(phones);
  3451. var eth = /^(0x)[0-9a-f]{40}$/i;
  3452. function isEthereumAddress(str) {
  3453. assertString(str);
  3454. return eth.test(str);
  3455. }
  3456. function currencyRegex(options) {
  3457. var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
  3458. options.digits_after_decimal.forEach(function (digit, index) {
  3459. if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
  3460. });
  3461. var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
  3462. return "\\".concat(m);
  3463. }), ")").concat(options.require_symbol ? '' : '?'),
  3464. negative = '-?',
  3465. whole_dollar_amount_without_sep = '[1-9]\\d*',
  3466. whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
  3467. valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
  3468. whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
  3469. decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
  3470. var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : ''); // default is negative sign before symbol, but there are two other options (besides parens)
  3471. if (options.allow_negatives && !options.parens_for_negatives) {
  3472. if (options.negative_sign_after_digits) {
  3473. pattern += negative;
  3474. } else if (options.negative_sign_before_digits) {
  3475. pattern = negative + pattern;
  3476. }
  3477. } // South African Rand, for example, uses R 123 (space) and R-123 (no space)
  3478. if (options.allow_negative_sign_placeholder) {
  3479. pattern = "( (?!\\-))?".concat(pattern);
  3480. } else if (options.allow_space_after_symbol) {
  3481. pattern = " ?".concat(pattern);
  3482. } else if (options.allow_space_after_digits) {
  3483. pattern += '( (?!$))?';
  3484. }
  3485. if (options.symbol_after_digits) {
  3486. pattern += symbol;
  3487. } else {
  3488. pattern = symbol + pattern;
  3489. }
  3490. if (options.allow_negatives) {
  3491. if (options.parens_for_negatives) {
  3492. pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
  3493. } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
  3494. pattern = negative + pattern;
  3495. }
  3496. } // ensure there's a dollar and/or decimal amount, and that
  3497. // it doesn't start with a space or a negative sign followed by a space
  3498. return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
  3499. }
  3500. var default_currency_options = {
  3501. symbol: '$',
  3502. require_symbol: false,
  3503. allow_space_after_symbol: false,
  3504. symbol_after_digits: false,
  3505. allow_negatives: true,
  3506. parens_for_negatives: false,
  3507. negative_sign_before_digits: false,
  3508. negative_sign_after_digits: false,
  3509. allow_negative_sign_placeholder: false,
  3510. thousands_separator: ',',
  3511. decimal_separator: '.',
  3512. allow_decimal: true,
  3513. require_decimal: false,
  3514. digits_after_decimal: [2],
  3515. allow_space_after_digits: false
  3516. };
  3517. function isCurrency(str, options) {
  3518. assertString(str);
  3519. options = merge(options, default_currency_options);
  3520. return currencyRegex(options).test(str);
  3521. }
  3522. var bech32 = /^(bc1)[a-z0-9]{25,39}$/;
  3523. var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
  3524. function isBtcAddress(str) {
  3525. assertString(str); // check for bech32
  3526. if (str.startsWith('bc1')) {
  3527. return bech32.test(str);
  3528. }
  3529. return base58.test(str);
  3530. }
  3531. /* eslint-disable max-len */
  3532. // from http://goo.gl/0ejHHW
  3533. var iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; // same as above, except with a strict 'T' separator between date and time
  3534. var iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
  3535. /* eslint-enable max-len */
  3536. var isValidDate = function isValidDate(str) {
  3537. // str must have passed the ISO8601 check
  3538. // this check is meant to catch invalid dates
  3539. // like 2009-02-31
  3540. // first check for ordinal dates
  3541. var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
  3542. if (ordinalMatch) {
  3543. var oYear = Number(ordinalMatch[1]);
  3544. var oDay = Number(ordinalMatch[2]); // if is leap year
  3545. if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
  3546. return oDay <= 365;
  3547. }
  3548. var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
  3549. var year = match[1];
  3550. var month = match[2];
  3551. var day = match[3];
  3552. var monthString = month ? "0".concat(month).slice(-2) : month;
  3553. var dayString = day ? "0".concat(day).slice(-2) : day; // create a date object and compare
  3554. var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
  3555. if (month && day) {
  3556. return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
  3557. }
  3558. return true;
  3559. };
  3560. function isISO8601(str) {
  3561. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  3562. assertString(str);
  3563. var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
  3564. if (check && options.strict) return isValidDate(str);
  3565. return check;
  3566. }
  3567. /* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
  3568. var dateFullYear = /[0-9]{4}/;
  3569. var dateMonth = /(0[1-9]|1[0-2])/;
  3570. var dateMDay = /([12]\d|0[1-9]|3[01])/;
  3571. var timeHour = /([01][0-9]|2[0-3])/;
  3572. var timeMinute = /[0-5][0-9]/;
  3573. var timeSecond = /([0-5][0-9]|60)/;
  3574. var timeSecFrac = /(\.[0-9]+)?/;
  3575. var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
  3576. var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
  3577. var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
  3578. var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
  3579. var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
  3580. var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
  3581. function isRFC3339(str) {
  3582. assertString(str);
  3583. return rfc3339.test(str);
  3584. }
  3585. var validISO31661Alpha3CountriesCodes = new Set(['AFG', 'ALA', 'ALB', 'DZA', 'ASM', 'AND', 'AGO', 'AIA', 'ATA', 'ATG', 'ARG', 'ARM', 'ABW', 'AUS', 'AUT', 'AZE', 'BHS', 'BHR', 'BGD', 'BRB', 'BLR', 'BEL', 'BLZ', 'BEN', 'BMU', 'BTN', 'BOL', 'BES', 'BIH', 'BWA', 'BVT', 'BRA', 'IOT', 'BRN', 'BGR', 'BFA', 'BDI', 'KHM', 'CMR', 'CAN', 'CPV', 'CYM', 'CAF', 'TCD', 'CHL', 'CHN', 'CXR', 'CCK', 'COL', 'COM', 'COG', 'COD', 'COK', 'CRI', 'CIV', 'HRV', 'CUB', 'CUW', 'CYP', 'CZE', 'DNK', 'DJI', 'DMA', 'DOM', 'ECU', 'EGY', 'SLV', 'GNQ', 'ERI', 'EST', 'ETH', 'FLK', 'FRO', 'FJI', 'FIN', 'FRA', 'GUF', 'PYF', 'ATF', 'GAB', 'GMB', 'GEO', 'DEU', 'GHA', 'GIB', 'GRC', 'GRL', 'GRD', 'GLP', 'GUM', 'GTM', 'GGY', 'GIN', 'GNB', 'GUY', 'HTI', 'HMD', 'VAT', 'HND', 'HKG', 'HUN', 'ISL', 'IND', 'IDN', 'IRN', 'IRQ', 'IRL', 'IMN', 'ISR', 'ITA', 'JAM', 'JPN', 'JEY', 'JOR', 'KAZ', 'KEN', 'KIR', 'PRK', 'KOR', 'KWT', 'KGZ', 'LAO', 'LVA', 'LBN', 'LSO', 'LBR', 'LBY', 'LIE', 'LTU', 'LUX', 'MAC', 'MKD', 'MDG', 'MWI', 'MYS', 'MDV', 'MLI', 'MLT', 'MHL', 'MTQ', 'MRT', 'MUS', 'MYT', 'MEX', 'FSM', 'MDA', 'MCO', 'MNG', 'MNE', 'MSR', 'MAR', 'MOZ', 'MMR', 'NAM', 'NRU', 'NPL', 'NLD', 'NCL', 'NZL', 'NIC', 'NER', 'NGA', 'NIU', 'NFK', 'MNP', 'NOR', 'OMN', 'PAK', 'PLW', 'PSE', 'PAN', 'PNG', 'PRY', 'PER', 'PHL', 'PCN', 'POL', 'PRT', 'PRI', 'QAT', 'REU', 'ROU', 'RUS', 'RWA', 'BLM', 'SHN', 'KNA', 'LCA', 'MAF', 'SPM', 'VCT', 'WSM', 'SMR', 'STP', 'SAU', 'SEN', 'SRB', 'SYC', 'SLE', 'SGP', 'SXM', 'SVK', 'SVN', 'SLB', 'SOM', 'ZAF', 'SGS', 'SSD', 'ESP', 'LKA', 'SDN', 'SUR', 'SJM', 'SWZ', 'SWE', 'CHE', 'SYR', 'TWN', 'TJK', 'TZA', 'THA', 'TLS', 'TGO', 'TKL', 'TON', 'TTO', 'TUN', 'TUR', 'TKM', 'TCA', 'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'UMI', 'URY', 'UZB', 'VUT', 'VEN', 'VNM', 'VGB', 'VIR', 'WLF', 'ESH', 'YEM', 'ZMB', 'ZWE']);
  3586. function isISO31661Alpha3(str) {
  3587. assertString(str);
  3588. return validISO31661Alpha3CountriesCodes.has(str.toUpperCase());
  3589. }
  3590. var validISO4217CurrencyCodes = new Set(['AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF', 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'UYI', 'UYU', 'UYW', 'UZS', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA', 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XOF', 'XPD', 'XPF', 'XPT', 'XSU', 'XTS', 'XUA', 'XXX', 'YER', 'ZAR', 'ZMW', 'ZWL']);
  3591. function isISO4217(str) {
  3592. assertString(str);
  3593. return validISO4217CurrencyCodes.has(str.toUpperCase());
  3594. }
  3595. var base32 = /^[A-Z2-7]+=*$/;
  3596. function isBase32(str) {
  3597. assertString(str);
  3598. var len = str.length;
  3599. if (len % 8 === 0 && base32.test(str)) {
  3600. return true;
  3601. }
  3602. return false;
  3603. }
  3604. var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
  3605. function isBase58(str) {
  3606. assertString(str);
  3607. if (base58Reg.test(str)) {
  3608. return true;
  3609. }
  3610. return false;
  3611. }
  3612. var validMediaType = /^[a-z]+\/[a-z0-9\-\+]+$/i;
  3613. var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
  3614. var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
  3615. function isDataURI(str) {
  3616. assertString(str);
  3617. var data = str.split(',');
  3618. if (data.length < 2) {
  3619. return false;
  3620. }
  3621. var attributes = data.shift().trim().split(';');
  3622. var schemeAndMediaType = attributes.shift();
  3623. if (schemeAndMediaType.substr(0, 5) !== 'data:') {
  3624. return false;
  3625. }
  3626. var mediaType = schemeAndMediaType.substr(5);
  3627. if (mediaType !== '' && !validMediaType.test(mediaType)) {
  3628. return false;
  3629. }
  3630. for (var i = 0; i < attributes.length; i++) {
  3631. if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
  3632. return false;
  3633. }
  3634. }
  3635. for (var _i = 0; _i < data.length; _i++) {
  3636. if (!validData.test(data[_i])) {
  3637. return false;
  3638. }
  3639. }
  3640. return true;
  3641. }
  3642. var magnetURI = /^magnet:\?xt(?:\.1)?=urn:(?:aich|bitprint|btih|ed2k|ed2khash|kzhash|md5|sha1|tree:tiger):[a-z0-9]{32}(?:[a-z0-9]{8})?($|&)/i;
  3643. function isMagnetURI(url) {
  3644. assertString(url);
  3645. return magnetURI.test(url.trim());
  3646. }
  3647. /*
  3648. Checks if the provided string matches to a correct Media type format (MIME type)
  3649. This function only checks is the string format follows the
  3650. etablished rules by the according RFC specifications.
  3651. This function supports 'charset' in textual media types
  3652. (https://tools.ietf.org/html/rfc6657).
  3653. This function does not check against all the media types listed
  3654. by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml)
  3655. because of lightness purposes : it would require to include
  3656. all these MIME types in this librairy, which would weigh it
  3657. significantly. This kind of effort maybe is not worth for the use that
  3658. this function has in this entire librairy.
  3659. More informations in the RFC specifications :
  3660. - https://tools.ietf.org/html/rfc2045
  3661. - https://tools.ietf.org/html/rfc2046
  3662. - https://tools.ietf.org/html/rfc7231#section-3.1.1.1
  3663. - https://tools.ietf.org/html/rfc7231#section-3.1.1.5
  3664. */
  3665. // Match simple MIME types
  3666. // NB :
  3667. // Subtype length must not exceed 100 characters.
  3668. // This rule does not comply to the RFC specs (what is the max length ?).
  3669. var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i; // eslint-disable-line max-len
  3670. // Handle "charset" in "text/*"
  3671. var mimeTypeText = /^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i; // eslint-disable-line max-len
  3672. // Handle "boundary" in "multipart/*"
  3673. var mimeTypeMultipart = /^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i; // eslint-disable-line max-len
  3674. function isMimeType(str) {
  3675. assertString(str);
  3676. return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str);
  3677. }
  3678. var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
  3679. var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
  3680. var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i;
  3681. var longDMS = /^\s*([1-7]?\d{1,2}\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|180\D+0\D+0)\D+[EWew]?$/i;
  3682. var defaultLatLongOptions = {
  3683. checkDMS: false
  3684. };
  3685. function isLatLong(str, options) {
  3686. assertString(str);
  3687. options = merge(options, defaultLatLongOptions);
  3688. if (!str.includes(',')) return false;
  3689. var pair = str.split(',');
  3690. if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
  3691. if (options.checkDMS) {
  3692. return latDMS.test(pair[0]) && longDMS.test(pair[1]);
  3693. }
  3694. return lat.test(pair[0]) && _long.test(pair[1]);
  3695. }
  3696. var threeDigit = /^\d{3}$/;
  3697. var fourDigit = /^\d{4}$/;
  3698. var fiveDigit = /^\d{5}$/;
  3699. var sixDigit = /^\d{6}$/;
  3700. var patterns = {
  3701. AD: /^AD\d{3}$/,
  3702. AT: fourDigit,
  3703. AU: fourDigit,
  3704. AZ: /^AZ\d{4}$/,
  3705. BE: fourDigit,
  3706. BG: fourDigit,
  3707. BR: /^\d{5}-\d{3}$/,
  3708. BY: /2[1-4]{1}\d{4}$/,
  3709. CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
  3710. CH: fourDigit,
  3711. CN: /^(0[1-7]|1[012356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[1-5]|8[1345]|9[09])\d{4}$/,
  3712. CZ: /^\d{3}\s?\d{2}$/,
  3713. DE: fiveDigit,
  3714. DK: fourDigit,
  3715. DO: fiveDigit,
  3716. DZ: fiveDigit,
  3717. EE: fiveDigit,
  3718. ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
  3719. FI: fiveDigit,
  3720. FR: /^\d{2}\s?\d{3}$/,
  3721. GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
  3722. GR: /^\d{3}\s?\d{2}$/,
  3723. HR: /^([1-5]\d{4}$)/,
  3724. HT: /^HT\d{4}$/,
  3725. HU: fourDigit,
  3726. ID: fiveDigit,
  3727. IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
  3728. IL: /^(\d{5}|\d{7})$/,
  3729. IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
  3730. IR: /\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b/,
  3731. IS: threeDigit,
  3732. IT: fiveDigit,
  3733. JP: /^\d{3}\-\d{4}$/,
  3734. KE: fiveDigit,
  3735. KR: /^(\d{5}|\d{6})$/,
  3736. LI: /^(948[5-9]|949[0-7])$/,
  3737. LT: /^LT\-\d{5}$/,
  3738. LU: fourDigit,
  3739. LV: /^LV\-\d{4}$/,
  3740. LK: fiveDigit,
  3741. MX: fiveDigit,
  3742. MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
  3743. MY: fiveDigit,
  3744. NL: /^\d{4}\s?[a-z]{2}$/i,
  3745. NO: fourDigit,
  3746. NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
  3747. NZ: fourDigit,
  3748. PL: /^\d{2}\-\d{3}$/,
  3749. PR: /^00[679]\d{2}([ -]\d{4})?$/,
  3750. PT: /^\d{4}\-\d{3}?$/,
  3751. RO: sixDigit,
  3752. RU: sixDigit,
  3753. SA: fiveDigit,
  3754. SE: /^[1-9]\d{2}\s?\d{2}$/,
  3755. SG: sixDigit,
  3756. SI: fourDigit,
  3757. SK: /^\d{3}\s?\d{2}$/,
  3758. TH: fiveDigit,
  3759. TN: fourDigit,
  3760. TW: /^\d{3}(\d{2})?$/,
  3761. UA: fiveDigit,
  3762. US: /^\d{5}(-\d{4})?$/,
  3763. ZA: fourDigit,
  3764. ZM: fiveDigit
  3765. };
  3766. var locales$5 = Object.keys(patterns);
  3767. function isPostalCode(str, locale) {
  3768. assertString(str);
  3769. if (locale in patterns) {
  3770. return patterns[locale].test(str);
  3771. } else if (locale === 'any') {
  3772. for (var key in patterns) {
  3773. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  3774. // istanbul ignore else
  3775. if (patterns.hasOwnProperty(key)) {
  3776. var pattern = patterns[key];
  3777. if (pattern.test(str)) {
  3778. return true;
  3779. }
  3780. }
  3781. }
  3782. return false;
  3783. }
  3784. throw new Error("Invalid locale '".concat(locale, "'"));
  3785. }
  3786. function ltrim(str, chars) {
  3787. assertString(str); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  3788. var pattern = chars ? new RegExp("^[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+"), 'g') : /^\s+/g;
  3789. return str.replace(pattern, '');
  3790. }
  3791. function rtrim(str, chars) {
  3792. assertString(str);
  3793. if (chars) {
  3794. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  3795. var pattern = new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g');
  3796. return str.replace(pattern, '');
  3797. } // Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript
  3798. var strIndex = str.length - 1;
  3799. while (/\s/.test(str.charAt(strIndex))) {
  3800. strIndex -= 1;
  3801. }
  3802. return str.slice(0, strIndex + 1);
  3803. }
  3804. function trim(str, chars) {
  3805. return rtrim(ltrim(str, chars), chars);
  3806. }
  3807. function escape(str) {
  3808. assertString(str);
  3809. return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
  3810. }
  3811. function unescape(str) {
  3812. assertString(str);
  3813. return str.replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&#x2F;/g, '/').replace(/&#x5C;/g, '\\').replace(/&#96;/g, '`').replace(/&amp;/g, '&'); // &amp; replacement has to be the last one to prevent
  3814. // bugs with intermediate strings containing escape sequences
  3815. // See: https://github.com/validatorjs/validator.js/issues/1827
  3816. }
  3817. function blacklist$1(str, chars) {
  3818. assertString(str);
  3819. return str.replace(new RegExp("[".concat(chars, "]+"), 'g'), '');
  3820. }
  3821. function stripLow(str, keep_new_lines) {
  3822. assertString(str);
  3823. var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
  3824. return blacklist$1(str, chars);
  3825. }
  3826. function whitelist(str, chars) {
  3827. assertString(str);
  3828. return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), '');
  3829. }
  3830. function isWhitelisted(str, chars) {
  3831. assertString(str);
  3832. for (var i = str.length - 1; i >= 0; i--) {
  3833. if (chars.indexOf(str[i]) === -1) {
  3834. return false;
  3835. }
  3836. }
  3837. return true;
  3838. }
  3839. var default_normalize_email_options = {
  3840. // The following options apply to all email addresses
  3841. // Lowercases the local part of the email address.
  3842. // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
  3843. // The domain is always lowercased, as per RFC 1035
  3844. all_lowercase: true,
  3845. // The following conversions are specific to GMail
  3846. // Lowercases the local part of the GMail address (known to be case-insensitive)
  3847. gmail_lowercase: true,
  3848. // Removes dots from the local part of the email address, as that's ignored by GMail
  3849. gmail_remove_dots: true,
  3850. // Removes the subaddress (e.g. "+foo") from the email address
  3851. gmail_remove_subaddress: true,
  3852. // Conversts the googlemail.com domain to gmail.com
  3853. gmail_convert_googlemaildotcom: true,
  3854. // The following conversions are specific to Outlook.com / Windows Live / Hotmail
  3855. // Lowercases the local part of the Outlook.com address (known to be case-insensitive)
  3856. outlookdotcom_lowercase: true,
  3857. // Removes the subaddress (e.g. "+foo") from the email address
  3858. outlookdotcom_remove_subaddress: true,
  3859. // The following conversions are specific to Yahoo
  3860. // Lowercases the local part of the Yahoo address (known to be case-insensitive)
  3861. yahoo_lowercase: true,
  3862. // Removes the subaddress (e.g. "-foo") from the email address
  3863. yahoo_remove_subaddress: true,
  3864. // The following conversions are specific to Yandex
  3865. // Lowercases the local part of the Yandex address (known to be case-insensitive)
  3866. yandex_lowercase: true,
  3867. // The following conversions are specific to iCloud
  3868. // Lowercases the local part of the iCloud address (known to be case-insensitive)
  3869. icloud_lowercase: true,
  3870. // Removes the subaddress (e.g. "+foo") from the email address
  3871. icloud_remove_subaddress: true
  3872. }; // List of domains used by iCloud
  3873. var icloud_domains = ['icloud.com', 'me.com']; // List of domains used by Outlook.com and its predecessors
  3874. // This list is likely incomplete.
  3875. // Partial reference:
  3876. // https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/
  3877. var outlookdotcom_domains = ['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']; // List of domains used by Yahoo Mail
  3878. // This list is likely incomplete
  3879. var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com']; // List of domains used by yandex.ru
  3880. var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru']; // replace single dots, but not multiple consecutive dots
  3881. function dotsReplacer(match) {
  3882. if (match.length > 1) {
  3883. return match;
  3884. }
  3885. return '';
  3886. }
  3887. function normalizeEmail(email, options) {
  3888. options = merge(options, default_normalize_email_options);
  3889. var raw_parts = email.split('@');
  3890. var domain = raw_parts.pop();
  3891. var user = raw_parts.join('@');
  3892. var parts = [user, domain]; // The domain is always lowercased, as it's case-insensitive per RFC 1035
  3893. parts[1] = parts[1].toLowerCase();
  3894. if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
  3895. // Address is GMail
  3896. if (options.gmail_remove_subaddress) {
  3897. parts[0] = parts[0].split('+')[0];
  3898. }
  3899. if (options.gmail_remove_dots) {
  3900. // this does not replace consecutive dots like example..email@gmail.com
  3901. parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
  3902. }
  3903. if (!parts[0].length) {
  3904. return false;
  3905. }
  3906. if (options.all_lowercase || options.gmail_lowercase) {
  3907. parts[0] = parts[0].toLowerCase();
  3908. }
  3909. parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
  3910. } else if (icloud_domains.indexOf(parts[1]) >= 0) {
  3911. // Address is iCloud
  3912. if (options.icloud_remove_subaddress) {
  3913. parts[0] = parts[0].split('+')[0];
  3914. }
  3915. if (!parts[0].length) {
  3916. return false;
  3917. }
  3918. if (options.all_lowercase || options.icloud_lowercase) {
  3919. parts[0] = parts[0].toLowerCase();
  3920. }
  3921. } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) {
  3922. // Address is Outlook.com
  3923. if (options.outlookdotcom_remove_subaddress) {
  3924. parts[0] = parts[0].split('+')[0];
  3925. }
  3926. if (!parts[0].length) {
  3927. return false;
  3928. }
  3929. if (options.all_lowercase || options.outlookdotcom_lowercase) {
  3930. parts[0] = parts[0].toLowerCase();
  3931. }
  3932. } else if (yahoo_domains.indexOf(parts[1]) >= 0) {
  3933. // Address is Yahoo
  3934. if (options.yahoo_remove_subaddress) {
  3935. var components = parts[0].split('-');
  3936. parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
  3937. }
  3938. if (!parts[0].length) {
  3939. return false;
  3940. }
  3941. if (options.all_lowercase || options.yahoo_lowercase) {
  3942. parts[0] = parts[0].toLowerCase();
  3943. }
  3944. } else if (yandex_domains.indexOf(parts[1]) >= 0) {
  3945. if (options.all_lowercase || options.yandex_lowercase) {
  3946. parts[0] = parts[0].toLowerCase();
  3947. }
  3948. parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preferred
  3949. } else if (options.all_lowercase) {
  3950. // Any other address
  3951. parts[0] = parts[0].toLowerCase();
  3952. }
  3953. return parts.join('@');
  3954. }
  3955. var charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;
  3956. function isSlug(str) {
  3957. assertString(str);
  3958. return charsetRegex.test(str);
  3959. }
  3960. var validators$1 = {
  3961. 'cs-CZ': function csCZ(str) {
  3962. return /^(([ABCDEFHKIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str);
  3963. },
  3964. 'de-DE': function deDE(str) {
  3965. return /^((AW|UL|AK|GA|AÖ|LF|AZ|AM|AS|ZE|AN|AB|A|KG|KH|BA|EW|BZ|HY|KM|BT|HP|B|BC|BI|BO|FN|TT|ÜB|BN|AH|BS|FR|HB|ZZ|BB|BK|BÖ|OC|OK|CW|CE|C|CO|LH|CB|KW|LC|LN|DA|DI|DE|DH|SY|NÖ|DO|DD|DU|DN|D|EI|EA|EE|FI|EM|EL|EN|PF|ED|EF|ER|AU|ZP|E|ES|NT|EU|FL|FO|FT|FF|F|FS|FD|FÜ|GE|G|GI|GF|GS|ZR|GG|GP|GR|NY|ZI|GÖ|GZ|GT|HA|HH|HM|HU|WL|HZ|WR|RN|HK|HD|HN|HS|GK|HE|HF|RZ|HI|HG|HO|HX|IK|IL|IN|J|JL|KL|KA|KS|KF|KE|KI|KT|KO|KN|KR|KC|KU|K|LD|LL|LA|L|OP|LM|LI|LB|LU|LÖ|HL|LG|MD|GN|MZ|MA|ML|MR|MY|AT|DM|MC|NZ|RM|RG|MM|ME|MB|MI|FG|DL|HC|MW|RL|MK|MG|MÜ|WS|MH|M|MS|NU|NB|ND|NM|NK|NW|NR|NI|NF|DZ|EB|OZ|TG|TO|N|OA|GM|OB|CA|EH|FW|OF|OL|OE|OG|BH|LR|OS|AA|GD|OH|KY|NP|WK|PB|PA|PE|PI|PS|P|PM|PR|RA|RV|RE|R|H|SB|WN|RS|RD|RT|BM|NE|GV|RP|SU|GL|RO|GÜ|RH|EG|RW|PN|SK|MQ|RU|SZ|RI|SL|SM|SC|HR|FZ|VS|SW|SN|CR|SE|SI|SO|LP|SG|NH|SP|IZ|ST|BF|TE|HV|OD|SR|S|AC|DW|ZW|TF|TS|TR|TÜ|UM|PZ|TP|UE|UN|UH|MN|KK|VB|V|AE|PL|RC|VG|GW|PW|VR|VK|KB|WA|WT|BE|WM|WE|AP|MO|WW|FB|WZ|WI|WB|JE|WF|WO|W|WÜ|BL|Z|GC)[- ]?[A-Z]{1,2}[- ]?\d{1,4}|(AIC|FDB|ABG|SLN|SAW|KLZ|BUL|ESB|NAB|SUL|WST|ABI|AZE|BTF|KÖT|DKB|FEU|ROT|ALZ|SMÜ|WER|AUR|NOR|DÜW|BRK|HAB|TÖL|WOR|BAD|BAR|BER|BIW|EBS|KEM|MÜB|PEG|BGL|BGD|REI|WIL|BKS|BIR|WAT|BOR|BOH|BOT|BRB|BLK|HHM|NEB|NMB|WSF|LEO|HDL|WMS|WZL|BÜS|CHA|KÖZ|ROD|WÜM|CLP|NEC|COC|ZEL|COE|CUX|DAH|LDS|DEG|DEL|RSL|DLG|DGF|LAN|HEI|MED|DON|KIB|ROK|JÜL|MON|SLE|EBE|EIC|HIG|WBS|BIT|PRÜ|LIB|EMD|WIT|ERH|HÖS|ERZ|ANA|ASZ|MAB|MEK|STL|SZB|FDS|HCH|HOR|WOL|FRG|GRA|WOS|FRI|FFB|GAP|GER|BRL|CLZ|GTH|NOH|HGW|GRZ|LÖB|NOL|WSW|DUD|HMÜ|OHA|KRU|HAL|HAM|HBS|QLB|HVL|NAU|HAS|EBN|GEO|HOH|HDH|ERK|HER|WAN|HEF|ROF|HBN|ALF|HSK|USI|NAI|REH|SAN|KÜN|ÖHR|HOL|WAR|ARN|BRG|GNT|HOG|WOH|KEH|MAI|PAR|RID|ROL|KLE|GEL|KUS|KYF|ART|SDH|LDK|DIL|MAL|VIB|LER|BNA|GHA|GRM|MTL|WUR|LEV|LIF|STE|WEL|LIP|VAI|LUP|HGN|LBZ|LWL|PCH|STB|DAN|MKK|SLÜ|MSP|TBB|MGH|MTK|BIN|MSH|EIL|HET|SGH|BID|MYK|MSE|MST|MÜR|WRN|MEI|GRH|RIE|MZG|MIL|OBB|BED|FLÖ|MOL|FRW|SEE|SRB|AIB|MOS|BCH|ILL|SOB|NMS|NEA|SEF|UFF|NEW|VOH|NDH|TDO|NWM|GDB|GVM|WIS|NOM|EIN|GAN|LAU|HEB|OHV|OSL|SFB|ERB|LOS|BSK|KEL|BSB|MEL|WTL|OAL|FÜS|MOD|OHZ|OPR|BÜR|PAF|PLÖ|CAS|GLA|REG|VIT|ECK|SIM|GOA|EMS|DIZ|GOH|RÜD|SWA|NES|KÖN|MET|LRO|BÜZ|DBR|ROS|TET|HRO|ROW|BRV|HIP|PAN|GRI|SHK|EIS|SRO|SOK|LBS|SCZ|MER|QFT|SLF|SLS|HOM|SLK|ASL|BBG|SBK|SFT|SHG|MGN|MEG|ZIG|SAD|NEN|OVI|SHA|BLB|SIG|SON|SPN|FOR|GUB|SPB|IGB|WND|STD|STA|SDL|OBG|HST|BOG|SHL|PIR|FTL|SEB|SÖM|SÜW|TIR|SAB|TUT|ANG|SDT|LÜN|LSZ|MHL|VEC|VER|VIE|OVL|ANK|OVP|SBG|UEM|UER|WLG|GMN|NVP|RDG|RÜG|DAU|FKB|WAF|WAK|SLZ|WEN|SOG|APD|WUG|GUN|ESW|WIZ|WES|DIN|BRA|BÜD|WHV|HWI|GHC|WTM|WOB|WUN|MAK|SEL|OCH|HOT|WDA)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str);
  3966. },
  3967. 'de-LI': function deLI(str) {
  3968. return /^FL[- ]?\d{1,5}[UZ]?$/.test(str);
  3969. },
  3970. 'fi-FI': function fiFI(str) {
  3971. return /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str);
  3972. },
  3973. 'pt-PT': function ptPT(str) {
  3974. return /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str);
  3975. },
  3976. 'sq-AL': function sqAL(str) {
  3977. return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str);
  3978. },
  3979. 'pt-BR': function ptBR(str) {
  3980. return /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str);
  3981. }
  3982. };
  3983. function isLicensePlate(str, locale) {
  3984. assertString(str);
  3985. if (locale in validators$1) {
  3986. return validators$1[locale](str);
  3987. } else if (locale === 'any') {
  3988. for (var key in validators$1) {
  3989. /* eslint guard-for-in: 0 */
  3990. var validator = validators$1[key];
  3991. if (validator(str)) {
  3992. return true;
  3993. }
  3994. }
  3995. return false;
  3996. }
  3997. throw new Error("Invalid locale '".concat(locale, "'"));
  3998. }
  3999. var upperCaseRegex = /^[A-Z]$/;
  4000. var lowerCaseRegex = /^[a-z]$/;
  4001. var numberRegex = /^[0-9]$/;
  4002. var symbolRegex = /^[-#!$@%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/;
  4003. var defaultOptions$1 = {
  4004. minLength: 8,
  4005. minLowercase: 1,
  4006. minUppercase: 1,
  4007. minNumbers: 1,
  4008. minSymbols: 1,
  4009. returnScore: false,
  4010. pointsPerUnique: 1,
  4011. pointsPerRepeat: 0.5,
  4012. pointsForContainingLower: 10,
  4013. pointsForContainingUpper: 10,
  4014. pointsForContainingNumber: 10,
  4015. pointsForContainingSymbol: 10
  4016. };
  4017. /* Counts number of occurrences of each char in a string
  4018. * could be moved to util/ ?
  4019. */
  4020. function countChars(str) {
  4021. var result = {};
  4022. Array.from(str).forEach(function (_char) {
  4023. var curVal = result[_char];
  4024. if (curVal) {
  4025. result[_char] += 1;
  4026. } else {
  4027. result[_char] = 1;
  4028. }
  4029. });
  4030. return result;
  4031. }
  4032. /* Return information about a password */
  4033. function analyzePassword(password) {
  4034. var charMap = countChars(password);
  4035. var analysis = {
  4036. length: password.length,
  4037. uniqueChars: Object.keys(charMap).length,
  4038. uppercaseCount: 0,
  4039. lowercaseCount: 0,
  4040. numberCount: 0,
  4041. symbolCount: 0
  4042. };
  4043. Object.keys(charMap).forEach(function (_char2) {
  4044. /* istanbul ignore else */
  4045. if (upperCaseRegex.test(_char2)) {
  4046. analysis.uppercaseCount += charMap[_char2];
  4047. } else if (lowerCaseRegex.test(_char2)) {
  4048. analysis.lowercaseCount += charMap[_char2];
  4049. } else if (numberRegex.test(_char2)) {
  4050. analysis.numberCount += charMap[_char2];
  4051. } else if (symbolRegex.test(_char2)) {
  4052. analysis.symbolCount += charMap[_char2];
  4053. }
  4054. });
  4055. return analysis;
  4056. }
  4057. function scorePassword(analysis, scoringOptions) {
  4058. var points = 0;
  4059. points += analysis.uniqueChars * scoringOptions.pointsPerUnique;
  4060. points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat;
  4061. if (analysis.lowercaseCount > 0) {
  4062. points += scoringOptions.pointsForContainingLower;
  4063. }
  4064. if (analysis.uppercaseCount > 0) {
  4065. points += scoringOptions.pointsForContainingUpper;
  4066. }
  4067. if (analysis.numberCount > 0) {
  4068. points += scoringOptions.pointsForContainingNumber;
  4069. }
  4070. if (analysis.symbolCount > 0) {
  4071. points += scoringOptions.pointsForContainingSymbol;
  4072. }
  4073. return points;
  4074. }
  4075. function isStrongPassword(str) {
  4076. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  4077. assertString(str);
  4078. var analysis = analyzePassword(str);
  4079. options = merge(options || {}, defaultOptions$1);
  4080. if (options.returnScore) {
  4081. return scorePassword(analysis, options);
  4082. }
  4083. return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols;
  4084. }
  4085. var vatMatchers = {
  4086. GB: /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/,
  4087. IT: /^(IT)?[0-9]{11}$/,
  4088. NL: /^(NL)?[0-9]{9}B[0-9]{2}$/
  4089. };
  4090. function isVAT(str, countryCode) {
  4091. assertString(str);
  4092. assertString(countryCode);
  4093. if (countryCode in vatMatchers) {
  4094. return vatMatchers[countryCode].test(str);
  4095. }
  4096. throw new Error("Invalid country code: '".concat(countryCode, "'"));
  4097. }
  4098. var version = '13.7.0';
  4099. var validator = {
  4100. version: version,
  4101. toDate: toDate,
  4102. toFloat: toFloat,
  4103. toInt: toInt,
  4104. toBoolean: toBoolean,
  4105. equals: equals,
  4106. contains: contains,
  4107. matches: matches,
  4108. isEmail: isEmail,
  4109. isURL: isURL,
  4110. isMACAddress: isMACAddress,
  4111. isIP: isIP,
  4112. isIPRange: isIPRange,
  4113. isFQDN: isFQDN,
  4114. isBoolean: isBoolean,
  4115. isIBAN: isIBAN,
  4116. isBIC: isBIC,
  4117. isAlpha: isAlpha,
  4118. isAlphaLocales: locales$1,
  4119. isAlphanumeric: isAlphanumeric,
  4120. isAlphanumericLocales: locales$2,
  4121. isNumeric: isNumeric,
  4122. isPassportNumber: isPassportNumber,
  4123. isPort: isPort,
  4124. isLowercase: isLowercase,
  4125. isUppercase: isUppercase,
  4126. isAscii: isAscii,
  4127. isFullWidth: isFullWidth,
  4128. isHalfWidth: isHalfWidth,
  4129. isVariableWidth: isVariableWidth,
  4130. isMultibyte: isMultibyte,
  4131. isSemVer: isSemVer,
  4132. isSurrogatePair: isSurrogatePair,
  4133. isInt: isInt,
  4134. isIMEI: isIMEI,
  4135. isFloat: isFloat,
  4136. isFloatLocales: locales,
  4137. isDecimal: isDecimal,
  4138. isHexadecimal: isHexadecimal,
  4139. isOctal: isOctal,
  4140. isDivisibleBy: isDivisibleBy,
  4141. isHexColor: isHexColor,
  4142. isRgbColor: isRgbColor,
  4143. isHSL: isHSL,
  4144. isISRC: isISRC,
  4145. isMD5: isMD5,
  4146. isHash: isHash,
  4147. isJWT: isJWT,
  4148. isJSON: isJSON,
  4149. isEmpty: isEmpty,
  4150. isLength: isLength,
  4151. isLocale: isLocale,
  4152. isByteLength: isByteLength,
  4153. isUUID: isUUID,
  4154. isMongoId: isMongoId,
  4155. isAfter: isAfter,
  4156. isBefore: isBefore,
  4157. isIn: isIn,
  4158. isCreditCard: isCreditCard,
  4159. isIdentityCard: isIdentityCard,
  4160. isEAN: isEAN,
  4161. isISIN: isISIN,
  4162. isISBN: isISBN,
  4163. isISSN: isISSN,
  4164. isMobilePhone: isMobilePhone,
  4165. isMobilePhoneLocales: locales$4,
  4166. isPostalCode: isPostalCode,
  4167. isPostalCodeLocales: locales$5,
  4168. isEthereumAddress: isEthereumAddress,
  4169. isCurrency: isCurrency,
  4170. isBtcAddress: isBtcAddress,
  4171. isISO8601: isISO8601,
  4172. isRFC3339: isRFC3339,
  4173. isISO31661Alpha2: isISO31661Alpha2,
  4174. isISO31661Alpha3: isISO31661Alpha3,
  4175. isISO4217: isISO4217,
  4176. isBase32: isBase32,
  4177. isBase58: isBase58,
  4178. isBase64: isBase64,
  4179. isDataURI: isDataURI,
  4180. isMagnetURI: isMagnetURI,
  4181. isMimeType: isMimeType,
  4182. isLatLong: isLatLong,
  4183. ltrim: ltrim,
  4184. rtrim: rtrim,
  4185. trim: trim,
  4186. escape: escape,
  4187. unescape: unescape,
  4188. stripLow: stripLow,
  4189. whitelist: whitelist,
  4190. blacklist: blacklist$1,
  4191. isWhitelisted: isWhitelisted,
  4192. normalizeEmail: normalizeEmail,
  4193. toString: toString,
  4194. isSlug: isSlug,
  4195. isStrongPassword: isStrongPassword,
  4196. isTaxID: isTaxID,
  4197. isDate: isDate,
  4198. isLicensePlate: isLicensePlate,
  4199. isVAT: isVAT,
  4200. ibanLocales: locales$3
  4201. };
  4202. return validator;
  4203. })));