validator.js 168 KB

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