validator.js 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774
  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 assertString(input) {
  29. if (input === undefined || input === null) throw new TypeError("Expected a string but received a ".concat(input));
  30. if (input.constructor.name !== 'String') throw new TypeError("Expected a string but received a ".concat(input.constructor.name));
  31. }
  32. function toDate(date) {
  33. assertString(date);
  34. date = Date.parse(date);
  35. return !isNaN(date) ? new Date(date) : null;
  36. }
  37. function isNullOrUndefined(value) {
  38. return value === null || value === undefined;
  39. }
  40. var alpha = {
  41. 'en-US': /^[A-Z]+$/i,
  42. 'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
  43. 'bg-BG': /^[А-Я]+$/i,
  44. 'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  45. 'da-DK': /^[A-ZÆØÅ]+$/i,
  46. 'de-DE': /^[A-ZÄÖÜß]+$/i,
  47. 'el-GR': /^[Α-ώ]+$/i,
  48. 'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i,
  49. 'fa-IR': /^[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+$/i,
  50. 'fi-FI': /^[A-ZÅÄÖ]+$/i,
  51. 'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  52. 'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i,
  53. 'ja-JP': /^[ぁ-んァ-ヶヲ-゚一-龠ー・。、]+$/i,
  54. 'nb-NO': /^[A-ZÆØÅ]+$/i,
  55. 'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i,
  56. 'nn-NO': /^[A-ZÆØÅ]+$/i,
  57. 'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  58. 'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  59. 'pt-PT': /^[A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  60. 'ru-RU': /^[А-ЯЁ]+$/i,
  61. 'kk-KZ': /^[А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
  62. 'sl-SI': /^[A-ZČĆĐŠŽ]+$/i,
  63. 'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  64. 'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i,
  65. 'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i,
  66. 'sv-SE': /^[A-ZÅÄÖ]+$/i,
  67. 'th-TH': /^[ก-๐\s]+$/i,
  68. 'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i,
  69. 'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i,
  70. 'vi-VN': /^[A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  71. 'ko-KR': /^[ㄱ-ㅎㅏ-ㅣ가-힣]*$/,
  72. 'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  73. ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  74. he: /^[א-ת]+$/,
  75. fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i,
  76. bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣৰৱ৲৳৴৵৶৷৸৹৺৻']+$/,
  77. eo: /^[ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i,
  78. 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i,
  79. 'si-LK': /^[\u0D80-\u0DFF]+$/,
  80. 'ta-IN': /^[\u0B80-\u0BFF]+$/i,
  81. 'te-IN': /^[\u0C00-\u0C7F]+$/i,
  82. 'kn-IN': /^[\u0C80-\u0CFF]+$/i,
  83. 'ml-IN': /^[\u0D00-\u0D7F]+$/i,
  84. 'gu-IN': /^[\u0A80-\u0AFF]+$/i,
  85. 'pa-IN': /^[\u0A00-\u0A7F]+$/i,
  86. 'or-IN': /^[\u0B00-\u0B7F]+$/i
  87. };
  88. var alphanumeric = {
  89. 'en-US': /^[0-9A-Z]+$/i,
  90. 'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
  91. 'bg-BG': /^[0-9А-Я]+$/i,
  92. 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
  93. 'da-DK': /^[0-9A-ZÆØÅ]+$/i,
  94. 'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
  95. 'el-GR': /^[0-9Α-ω]+$/i,
  96. 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
  97. 'fi-FI': /^[0-9A-ZÅÄÖ]+$/i,
  98. 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
  99. 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
  100. 'ja-JP': /^[0-90-9ぁ-んァ-ヶヲ-゚一-龠ー・。、]+$/i,
  101. 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
  102. 'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
  103. 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
  104. 'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
  105. 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
  106. 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
  107. 'ru-RU': /^[0-9А-ЯЁ]+$/i,
  108. 'kk-KZ': /^[0-9А-ЯЁ\u04D8\u04B0\u0406\u04A2\u0492\u04AE\u049A\u04E8\u04BA]+$/i,
  109. 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
  110. 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
  111. 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
  112. 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
  113. 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
  114. 'th-TH': /^[ก-๙\s]+$/i,
  115. 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
  116. 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
  117. 'ko-KR': /^[0-9ㄱ-ㅎㅏ-ㅣ가-힣]*$/,
  118. 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
  119. 'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
  120. ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
  121. he: /^[0-9א-ת]+$/,
  122. fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i,
  123. bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ০১২৩৪৫৬৭৮৯ৰৱ৲৳৴৵৶৷৸৹৺৻']+$/,
  124. eo: /^[0-9ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i,
  125. 'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i,
  126. 'si-LK': /^[0-9\u0D80-\u0DFF]+$/,
  127. 'ta-IN': /^[0-9\u0B80-\u0BFF.]+$/i,
  128. 'te-IN': /^[0-9\u0C00-\u0C7F.]+$/i,
  129. 'kn-IN': /^[0-9\u0C80-\u0CFF.]+$/i,
  130. 'ml-IN': /^[0-9\u0D00-\u0D7F.]+$/i,
  131. 'gu-IN': /^[0-9\u0A80-\u0AFF.]+$/i,
  132. 'pa-IN': /^[0-9\u0A00-\u0A7F.]+$/i,
  133. 'or-IN': /^[0-9\u0B00-\u0B7F.]+$/i
  134. };
  135. var decimal = {
  136. 'en-US': '.',
  137. ar: '٫'
  138. };
  139. var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
  140. for (var locale, i = 0; i < englishLocales.length; i++) {
  141. locale = "en-".concat(englishLocales[i]);
  142. alpha[locale] = alpha['en-US'];
  143. alphanumeric[locale] = alphanumeric['en-US'];
  144. decimal[locale] = decimal['en-US'];
  145. }
  146. // Source: http://www.localeplanet.com/java/
  147. var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
  148. for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
  149. _locale = "ar-".concat(arabicLocales[_i]);
  150. alpha[_locale] = alpha.ar;
  151. alphanumeric[_locale] = alphanumeric.ar;
  152. decimal[_locale] = decimal.ar;
  153. }
  154. var farsiLocales = ['IR', 'AF'];
  155. for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
  156. _locale2 = "fa-".concat(farsiLocales[_i2]);
  157. alphanumeric[_locale2] = alphanumeric.fa;
  158. decimal[_locale2] = decimal.ar;
  159. }
  160. var bengaliLocales = ['BD', 'IN'];
  161. for (var _locale3, _i3 = 0; _i3 < bengaliLocales.length; _i3++) {
  162. _locale3 = "bn-".concat(bengaliLocales[_i3]);
  163. alpha[_locale3] = alpha.bn;
  164. alphanumeric[_locale3] = alphanumeric.bn;
  165. decimal[_locale3] = decimal['en-US'];
  166. }
  167. // Source: https://en.wikipedia.org/wiki/Decimal_mark
  168. var dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY'];
  169. var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'eo', 'es-ES', 'fr-CA', 'fr-FR', 'gu-IN', 'hi-IN', 'hu-HU', 'id-ID', 'it-IT', 'kk-KZ', 'kn-IN', 'ku-IQ', 'ml-IN', 'nb-NO', 'nl-NL', 'nn-NO', 'or-IN', 'pa-IN', 'pl-PL', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'ta-IN', 'te-IN', 'tr-TR', 'uk-UA', 'vi-VN'];
  170. for (var _i4 = 0; _i4 < dotDecimal.length; _i4++) {
  171. decimal[dotDecimal[_i4]] = decimal['en-US'];
  172. }
  173. for (var _i5 = 0; _i5 < commaDecimal.length; _i5++) {
  174. decimal[commaDecimal[_i5]] = ',';
  175. }
  176. alpha['fr-CA'] = alpha['fr-FR'];
  177. alphanumeric['fr-CA'] = alphanumeric['fr-FR'];
  178. alpha['pt-BR'] = alpha['pt-PT'];
  179. alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
  180. decimal['pt-BR'] = decimal['pt-PT'];
  181. // see #862
  182. alpha['pl-Pl'] = alpha['pl-PL'];
  183. alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
  184. decimal['pl-Pl'] = decimal['pl-PL'];
  185. // see #1455
  186. alpha['fa-AF'] = alpha.fa;
  187. function isFloat(str, options) {
  188. assertString(str);
  189. options = options || {};
  190. var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
  191. if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
  192. return false;
  193. }
  194. var value = parseFloat(str.replace(',', '.'));
  195. return _float.test(str) && (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || value >= options.min) && (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || value <= options.max) && (!options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || value < options.lt) && (!options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || value > options.gt);
  196. }
  197. var locales = Object.keys(decimal);
  198. function toFloat(str) {
  199. if (!isFloat(str)) return NaN;
  200. return parseFloat(str);
  201. }
  202. function toInt(str, radix) {
  203. assertString(str);
  204. return parseInt(str, radix || 10);
  205. }
  206. function toBoolean(str, strict) {
  207. assertString(str);
  208. if (strict) {
  209. return str === '1' || /^true$/i.test(str);
  210. }
  211. return str !== '0' && !/^false$/i.test(str) && str !== '';
  212. }
  213. function equals(str, comparison) {
  214. assertString(str);
  215. return str === comparison;
  216. }
  217. function _arrayLikeToArray(r, a) {
  218. (null == a || a > r.length) && (a = r.length);
  219. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  220. return n;
  221. }
  222. function _arrayWithHoles(r) {
  223. if (Array.isArray(r)) return r;
  224. }
  225. function _arrayWithoutHoles(r) {
  226. if (Array.isArray(r)) return _arrayLikeToArray(r);
  227. }
  228. function _createForOfIteratorHelper(r, e) {
  229. var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  230. if (!t) {
  231. if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
  232. t && (r = t);
  233. var n = 0,
  234. F = function () {};
  235. return {
  236. s: F,
  237. n: function () {
  238. return n >= r.length ? {
  239. done: !0
  240. } : {
  241. done: !1,
  242. value: r[n++]
  243. };
  244. },
  245. e: function (r) {
  246. throw r;
  247. },
  248. f: F
  249. };
  250. }
  251. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  252. }
  253. var o,
  254. a = !0,
  255. u = !1;
  256. return {
  257. s: function () {
  258. t = t.call(r);
  259. },
  260. n: function () {
  261. var r = t.next();
  262. return a = r.done, r;
  263. },
  264. e: function (r) {
  265. u = !0, o = r;
  266. },
  267. f: function () {
  268. try {
  269. a || null == t.return || t.return();
  270. } finally {
  271. if (u) throw o;
  272. }
  273. }
  274. };
  275. }
  276. function _iterableToArray(r) {
  277. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  278. }
  279. function _iterableToArrayLimit(r, l) {
  280. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  281. if (null != t) {
  282. var e,
  283. n,
  284. i,
  285. u,
  286. a = [],
  287. f = !0,
  288. o = !1;
  289. try {
  290. if (i = (t = t.call(r)).next, 0 === l) {
  291. if (Object(t) !== t) return;
  292. f = !1;
  293. } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  294. } catch (r) {
  295. o = !0, n = r;
  296. } finally {
  297. try {
  298. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  299. } finally {
  300. if (o) throw n;
  301. }
  302. }
  303. return a;
  304. }
  305. }
  306. function _nonIterableRest() {
  307. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  308. }
  309. function _nonIterableSpread() {
  310. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  311. }
  312. function _setFunctionName(e, t, n) {
  313. "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
  314. try {
  315. Object.defineProperty(e, "name", {
  316. configurable: !0,
  317. value: n ? n + " " + t : t
  318. });
  319. } catch (e) {}
  320. return e;
  321. }
  322. function _slicedToArray(r, e) {
  323. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  324. }
  325. function _toConsumableArray(r) {
  326. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  327. }
  328. function _toPrimitive(t, r) {
  329. if ("object" != typeof t || !t) return t;
  330. var e = t[Symbol.toPrimitive];
  331. if (void 0 !== e) {
  332. var i = e.call(t, r || "default");
  333. if ("object" != typeof i) return i;
  334. throw new TypeError("@@toPrimitive must return a primitive value.");
  335. }
  336. return ("string" === r ? String : Number)(t);
  337. }
  338. function _toPropertyKey(t) {
  339. var i = _toPrimitive(t, "string");
  340. return "symbol" == typeof i ? i : i + "";
  341. }
  342. function _typeof(o) {
  343. "@babel/helpers - typeof";
  344. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  345. return typeof o;
  346. } : function (o) {
  347. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  348. }, _typeof(o);
  349. }
  350. function _unsupportedIterableToArray(r, a) {
  351. if (r) {
  352. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  353. var t = {}.toString.call(r).slice(8, -1);
  354. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  355. }
  356. }
  357. function old_createMetadataMethodsForProperty(e, t, a, r) {
  358. return {
  359. getMetadata: function (o) {
  360. old_assertNotFinished(r, "getMetadata"), old_assertMetadataKey(o);
  361. var i = e[o];
  362. if (void 0 !== i) if (1 === t) {
  363. var n = i.public;
  364. if (void 0 !== n) return n[a];
  365. } else if (2 === t) {
  366. var l = i.private;
  367. if (void 0 !== l) return l.get(a);
  368. } else if (Object.hasOwnProperty.call(i, "constructor")) return i.constructor;
  369. },
  370. setMetadata: function (o, i) {
  371. old_assertNotFinished(r, "setMetadata"), old_assertMetadataKey(o);
  372. var n = e[o];
  373. if (void 0 === n && (n = e[o] = {}), 1 === t) {
  374. var l = n.public;
  375. void 0 === l && (l = n.public = {}), l[a] = i;
  376. } else if (2 === t) {
  377. var s = n.priv;
  378. void 0 === s && (s = n.private = new Map()), s.set(a, i);
  379. } else n.constructor = i;
  380. }
  381. };
  382. }
  383. function old_createAddInitializerMethod(e, t) {
  384. return function (a) {
  385. old_assertNotFinished(t, "addInitializer"), old_assertCallable(a, "An initializer"), e.push(a);
  386. };
  387. }
  388. function old_memberDec(e, t, a, r, o, i, n, l, s) {
  389. var c;
  390. switch (i) {
  391. case 1:
  392. c = "accessor";
  393. break;
  394. case 2:
  395. c = "method";
  396. break;
  397. case 3:
  398. c = "getter";
  399. break;
  400. case 4:
  401. c = "setter";
  402. break;
  403. default:
  404. c = "field";
  405. }
  406. var d,
  407. u,
  408. f = {
  409. kind: c,
  410. name: l ? "#" + t : _toPropertyKey(t),
  411. isStatic: n,
  412. isPrivate: l
  413. },
  414. p = {
  415. v: !1
  416. };
  417. if (0 !== i && (f.addInitializer = old_createAddInitializerMethod(o, p)), l) {
  418. d = 2, u = Symbol(t);
  419. var v = {};
  420. 0 === i ? (v.get = a.get, v.set = a.set) : 2 === i ? v.get = function () {
  421. return a.value;
  422. } : (1 !== i && 3 !== i || (v.get = function () {
  423. return a.get.call(this);
  424. }), 1 !== i && 4 !== i || (v.set = function (e) {
  425. a.set.call(this, e);
  426. })), f.access = v;
  427. } else d = 1, u = t;
  428. try {
  429. return e(s, Object.assign(f, old_createMetadataMethodsForProperty(r, d, u, p)));
  430. } finally {
  431. p.v = !0;
  432. }
  433. }
  434. function old_assertNotFinished(e, t) {
  435. if (e.v) throw Error("attempted to call " + t + " after decoration was finished");
  436. }
  437. function old_assertMetadataKey(e) {
  438. if ("symbol" != typeof e) throw new TypeError("Metadata keys must be symbols, received: " + e);
  439. }
  440. function old_assertCallable(e, t) {
  441. if ("function" != typeof e) throw new TypeError(t + " must be a function");
  442. }
  443. function old_assertValidReturnValue(e, t) {
  444. var a = typeof t;
  445. if (1 === e) {
  446. if ("object" !== a || null === t) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
  447. void 0 !== t.get && old_assertCallable(t.get, "accessor.get"), void 0 !== t.set && old_assertCallable(t.set, "accessor.set"), void 0 !== t.init && old_assertCallable(t.init, "accessor.init"), void 0 !== t.initializer && old_assertCallable(t.initializer, "accessor.initializer");
  448. } else if ("function" !== a) throw new TypeError((0 === e ? "field" : 10 === e ? "class" : "method") + " decorators must return a function or void 0");
  449. }
  450. function old_getInit(e) {
  451. var t;
  452. return null == (t = e.init) && (t = e.initializer) && void 0 !== console && console.warn(".initializer has been renamed to .init as of March 2022"), t;
  453. }
  454. function toString$1(input) {
  455. if (_typeof(input) === 'object' && input !== null) {
  456. if (typeof input.toString === 'function') {
  457. input = input.toString();
  458. } else {
  459. input = '[object Object]';
  460. }
  461. } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
  462. input = '';
  463. }
  464. return String(input);
  465. }
  466. function merge() {
  467. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  468. var defaults = arguments.length > 1 ? arguments[1] : undefined;
  469. for (var key in defaults) {
  470. if (typeof obj[key] === 'undefined') {
  471. obj[key] = defaults[key];
  472. }
  473. }
  474. return obj;
  475. }
  476. var defaultContainsOptions = {
  477. ignoreCase: false,
  478. minOccurrences: 1
  479. };
  480. function contains(str, elem, options) {
  481. assertString(str);
  482. options = merge(options, defaultContainsOptions);
  483. if (options.ignoreCase) {
  484. return str.toLowerCase().split(toString$1(elem).toLowerCase()).length > options.minOccurrences;
  485. }
  486. return str.split(toString$1(elem)).length > options.minOccurrences;
  487. }
  488. function matches(str, pattern, modifiers) {
  489. assertString(str);
  490. if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
  491. pattern = new RegExp(pattern, modifiers);
  492. }
  493. return !!str.match(pattern);
  494. }
  495. function isRegExp(obj) {
  496. return Object.prototype.toString.call(obj) === '[object RegExp]';
  497. }
  498. function checkHost(host, matches) {
  499. for (var i = 0; i < matches.length; i++) {
  500. var match = matches[i];
  501. if (host === match || isRegExp(match) && match.test(host)) {
  502. return true;
  503. }
  504. }
  505. return false;
  506. }
  507. /* eslint-disable prefer-rest-params */
  508. function isByteLength(str, options) {
  509. assertString(str);
  510. var min;
  511. var max;
  512. if (_typeof(options) === 'object') {
  513. min = options.min || 0;
  514. max = options.max;
  515. } else {
  516. // backwards compatibility: isByteLength(str, min [, max])
  517. min = arguments[1];
  518. max = arguments[2];
  519. }
  520. var len = encodeURI(str).split(/%..|./).length - 1;
  521. return len >= min && (typeof max === 'undefined' || len <= max);
  522. }
  523. var default_fqdn_options = {
  524. require_tld: true,
  525. allow_underscores: false,
  526. allow_trailing_dot: false,
  527. allow_numeric_tld: false,
  528. allow_wildcard: false,
  529. ignore_max_length: false
  530. };
  531. function isFQDN(str, options) {
  532. assertString(str);
  533. options = merge(options, default_fqdn_options);
  534. /* Remove the optional trailing dot before checking validity */
  535. if (options.allow_trailing_dot && str[str.length - 1] === '.') {
  536. str = str.substring(0, str.length - 1);
  537. }
  538. /* Remove the optional wildcard before checking validity */
  539. if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
  540. str = str.substring(2);
  541. }
  542. var parts = str.split('.');
  543. var tld = parts[parts.length - 1];
  544. if (options.require_tld) {
  545. // disallow fqdns without tld
  546. if (parts.length < 2) {
  547. return false;
  548. }
  549. if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
  550. return false;
  551. }
  552. // disallow spaces
  553. if (/\s/.test(tld)) {
  554. return false;
  555. }
  556. }
  557. // reject numeric TLDs
  558. if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
  559. return false;
  560. }
  561. return parts.every(function (part) {
  562. if (part.length > 63 && !options.ignore_max_length) {
  563. return false;
  564. }
  565. if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
  566. return false;
  567. }
  568. // disallow full-width chars
  569. if (/[\uff01-\uff5e]/.test(part)) {
  570. return false;
  571. }
  572. // disallow parts starting or ending with hyphen
  573. if (/^-|-$/.test(part)) {
  574. return false;
  575. }
  576. if (!options.allow_underscores && /_/.test(part)) {
  577. return false;
  578. }
  579. return true;
  580. });
  581. }
  582. /**
  583. 11.3. Examples
  584. The following addresses
  585. fe80::1234 (on the 1st link of the node)
  586. ff02::5678 (on the 5th link of the node)
  587. ff08::9abc (on the 10th organization of the node)
  588. would be represented as follows:
  589. fe80::1234%1
  590. ff02::5678%5
  591. ff08::9abc%10
  592. (Here we assume a natural translation from a zone index to the
  593. <zone_id> part, where the Nth zone of any scope is translated into
  594. "N".)
  595. If we use interface names as <zone_id>, those addresses could also be
  596. represented as follows:
  597. fe80::1234%ne0
  598. ff02::5678%pvc1.3
  599. ff08::9abc%interface10
  600. where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
  601. to the 5th link, and "interface10" belongs to the 10th organization.
  602. * * */
  603. var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
  604. var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
  605. var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
  606. var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
  607. 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,})?$');
  608. function isIP(ipAddress) {
  609. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  610. assertString(ipAddress);
  611. // accessing 'arguments' for backwards compatibility: isIP(ipAddress [, version])
  612. // eslint-disable-next-line prefer-rest-params
  613. var version = (_typeof(options) === 'object' ? options.version : arguments[1]) || '';
  614. if (!version) {
  615. return isIP(ipAddress, {
  616. version: 4
  617. }) || isIP(ipAddress, {
  618. version: 6
  619. });
  620. }
  621. if (version.toString() === '4') {
  622. return IPv4AddressRegExp.test(ipAddress);
  623. }
  624. if (version.toString() === '6') {
  625. return IPv6AddressRegExp.test(ipAddress);
  626. }
  627. return false;
  628. }
  629. var default_email_options = {
  630. allow_display_name: false,
  631. allow_underscores: false,
  632. require_display_name: false,
  633. allow_utf8_local_part: true,
  634. require_tld: true,
  635. blacklisted_chars: '',
  636. ignore_max_length: false,
  637. host_blacklist: [],
  638. host_whitelist: []
  639. };
  640. /* eslint-disable max-len */
  641. /* eslint-disable no-control-regex */
  642. var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
  643. var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
  644. var gmailUserPart = /^[a-z\d]+$/;
  645. var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
  646. var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
  647. 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;
  648. var defaultMaxEmailLength = 254;
  649. /* eslint-enable max-len */
  650. /* eslint-enable no-control-regex */
  651. /**
  652. * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
  653. * @param {String} display_name
  654. */
  655. function validateDisplayName(display_name) {
  656. var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
  657. // display name with only spaces is not valid
  658. if (!display_name_without_quotes.trim()) {
  659. return false;
  660. }
  661. // check whether display name contains illegal character
  662. var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
  663. if (contains_illegal) {
  664. // if contains illegal characters,
  665. // must to be enclosed in double-quotes, otherwise it's not a valid display name
  666. if (display_name_without_quotes === display_name) {
  667. return false;
  668. }
  669. // the quotes in display name must start with character symbol \
  670. var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
  671. if (!all_start_with_back_slash) {
  672. return false;
  673. }
  674. }
  675. return true;
  676. }
  677. function isEmail(str, options) {
  678. assertString(str);
  679. options = merge(options, default_email_options);
  680. if (options.require_display_name || options.allow_display_name) {
  681. var display_email = str.match(splitNameAddress);
  682. if (display_email) {
  683. var display_name = display_email[1];
  684. // Remove display name and angle brackets to get email address
  685. // Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
  686. str = str.replace(display_name, '').replace(/(^<|>$)/g, '');
  687. // sometimes need to trim the last space to get the display name
  688. // because there may be a space between display name and email address
  689. // eg. myname <address@gmail.com>
  690. // the display name is `myname` instead of `myname `, so need to trim the last space
  691. if (display_name.endsWith(' ')) {
  692. display_name = display_name.slice(0, -1);
  693. }
  694. if (!validateDisplayName(display_name)) {
  695. return false;
  696. }
  697. } else if (options.require_display_name) {
  698. return false;
  699. }
  700. }
  701. if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
  702. return false;
  703. }
  704. var parts = str.split('@');
  705. var domain = parts.pop();
  706. var lower_domain = domain.toLowerCase();
  707. if (options.host_blacklist.length > 0 && checkHost(lower_domain, options.host_blacklist)) {
  708. return false;
  709. }
  710. if (options.host_whitelist.length > 0 && !checkHost(lower_domain, options.host_whitelist)) {
  711. return false;
  712. }
  713. var user = parts.join('@');
  714. if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
  715. /*
  716. Previously we removed dots for gmail addresses before validating.
  717. This was removed because it allows `multiple..dots@gmail.com`
  718. to be reported as valid, but it is not.
  719. Gmail only normalizes single dots, removing them from here is pointless,
  720. should be done in normalizeEmail
  721. */
  722. user = user.toLowerCase();
  723. // Removing sub-address from username before gmail validation
  724. var username = user.split('+')[0];
  725. // Dots are not included in gmail length restriction
  726. if (!isByteLength(username.replace(/\./g, ''), {
  727. min: 6,
  728. max: 30
  729. })) {
  730. return false;
  731. }
  732. var _user_parts = username.split('.');
  733. for (var i = 0; i < _user_parts.length; i++) {
  734. if (!gmailUserPart.test(_user_parts[i])) {
  735. return false;
  736. }
  737. }
  738. }
  739. if (options.ignore_max_length === false && (!isByteLength(user, {
  740. max: 64
  741. }) || !isByteLength(domain, {
  742. max: 254
  743. }))) {
  744. return false;
  745. }
  746. if (!isFQDN(domain, {
  747. require_tld: options.require_tld,
  748. ignore_max_length: options.ignore_max_length,
  749. allow_underscores: options.allow_underscores
  750. })) {
  751. if (!options.allow_ip_domain) {
  752. return false;
  753. }
  754. if (!isIP(domain)) {
  755. if (!domain.startsWith('[') || !domain.endsWith(']')) {
  756. return false;
  757. }
  758. var noBracketdomain = domain.slice(1, -1);
  759. if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
  760. return false;
  761. }
  762. }
  763. }
  764. if (options.blacklisted_chars) {
  765. if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
  766. }
  767. if (user[0] === '"' && user[user.length - 1] === '"') {
  768. user = user.slice(1, user.length - 1);
  769. return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
  770. }
  771. var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
  772. var user_parts = user.split('.');
  773. for (var _i = 0; _i < user_parts.length; _i++) {
  774. if (!pattern.test(user_parts[_i])) {
  775. return false;
  776. }
  777. }
  778. return true;
  779. }
  780. var includes = function includes(str, val) {
  781. return str.indexOf(val) !== -1;
  782. };
  783. /*
  784. options for isURL method
  785. protocols - valid protocols can be modified with this option.
  786. require_tld - If set to false isURL will not check if the URL's host includes a top-level domain.
  787. require_protocol - if set to true isURL will return false if protocol is not present in the URL.
  788. require_host - if set to false isURL will not check if host is present in the URL.
  789. require_port - if set to true isURL will check if port is present in the URL.
  790. require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
  791. allow_underscores - if set to true, the validator will allow underscores in the URL.
  792. host_whitelist - if set to an array of strings or regexp, and the domain matches none of the strings
  793. defined in it, the validation fails.
  794. host_blacklist - if set to an array of strings or regexp, and the domain matches any of the strings
  795. defined in it, the validation fails.
  796. allow_trailing_dot - if set to true, the validator will allow the domain to end with
  797. a `.` character.
  798. allow_protocol_relative_urls - if set to true protocol relative URLs will be allowed.
  799. allow_fragments - if set to false isURL will return false if fragments are present.
  800. allow_query_components - if set to false isURL will return false if query components are present.
  801. disallow_auth - if set to true, the validator will fail if the URL contains an authentication
  802. component, e.g. `http://username:password@example.com`
  803. validate_length - if set to false isURL will skip string length validation. `max_allowed_length`
  804. will be ignored if this is set as `false`.
  805. max_allowed_length - if set, isURL will not allow URLs longer than the specified value (default is
  806. 2084 that IE maximum URL length).
  807. */
  808. var default_url_options = {
  809. protocols: ['http', 'https', 'ftp'],
  810. require_tld: true,
  811. require_protocol: false,
  812. require_host: true,
  813. require_port: false,
  814. require_valid_protocol: true,
  815. allow_underscores: false,
  816. allow_trailing_dot: false,
  817. allow_protocol_relative_urls: false,
  818. allow_fragments: true,
  819. allow_query_components: true,
  820. validate_length: true,
  821. max_allowed_length: 2084
  822. };
  823. var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
  824. function isURL(url, options) {
  825. assertString(url);
  826. if (!url || /[\s<>]/.test(url)) {
  827. return false;
  828. }
  829. if (url.indexOf('mailto:') === 0) {
  830. return false;
  831. }
  832. options = merge(options, default_url_options);
  833. if (options.validate_length && url.length > options.max_allowed_length) {
  834. return false;
  835. }
  836. if (!options.allow_fragments && includes(url, '#')) {
  837. return false;
  838. }
  839. if (!options.allow_query_components && (includes(url, '?') || includes(url, '&'))) {
  840. return false;
  841. }
  842. var protocol, auth, host, hostname, port, port_str, split, ipv6;
  843. split = url.split('#');
  844. url = split.shift();
  845. split = url.split('?');
  846. url = split.shift();
  847. // Replaced the 'split("://")' logic with a regex to match the protocol.
  848. // This correctly identifies schemes like `javascript:` which don't use `//`.
  849. // However, we need to be careful not to confuse authentication credentials (user:password@host)
  850. // with protocols. A colon before an @ symbol might be part of auth, not a protocol separator.
  851. var protocol_match = url.match(/^([a-z][a-z0-9+\-.]*):/i);
  852. var had_explicit_protocol = false;
  853. var cleanUpProtocol = function cleanUpProtocol(potential_protocol) {
  854. had_explicit_protocol = true;
  855. protocol = potential_protocol.toLowerCase();
  856. if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
  857. // The identified protocol is not in the allowed list.
  858. return false;
  859. }
  860. // Remove the protocol from the URL string.
  861. return url.substring(protocol_match[0].length);
  862. };
  863. if (protocol_match) {
  864. var potential_protocol = protocol_match[1];
  865. var after_colon = url.substring(protocol_match[0].length);
  866. // Check if what follows looks like authentication credentials (user:password@host)
  867. // rather than a protocol. This happens when:
  868. // 1. There's no `//` after the colon (protocols like `http://` have this)
  869. // 2. There's an `@` symbol before any `/`
  870. // 3. The part before `@` contains only valid auth characters (alphanumeric, -, _, ., %, :)
  871. var starts_with_slashes = after_colon.slice(0, 2) === '//';
  872. if (!starts_with_slashes) {
  873. var first_slash_position = after_colon.indexOf('/');
  874. var before_slash = first_slash_position === -1 ? after_colon : after_colon.substring(0, first_slash_position);
  875. var at_position = before_slash.indexOf('@');
  876. if (at_position !== -1) {
  877. var before_at = before_slash.substring(0, at_position);
  878. var valid_auth_regex = /^[a-zA-Z0-9\-_.%:]*$/;
  879. var is_valid_auth = valid_auth_regex.test(before_at);
  880. // Check if this contains URL-encoded content that could be malicious
  881. // For example: javascript:%61%6c%65%72%74%28%31%29@example.com
  882. // The encoded part decodes to: alert(1)
  883. var has_encoded_content = /%[0-9a-fA-F]{2}/.test(before_at);
  884. if (is_valid_auth && !has_encoded_content) {
  885. // This looks like authentication (e.g., user:password@host), not a protocol
  886. if (options.require_protocol) {
  887. return false;
  888. }
  889. // Don't consume the colon; let the auth parsing handle it later
  890. } else {
  891. // This looks like a malicious protocol (e.g., javascript:alert();@host)
  892. // or URL-encoded protocol handler (e.g., javascript:%61%6c%65%72%74%28%31%29@host)
  893. url = cleanUpProtocol(potential_protocol);
  894. if (url === false) {
  895. return false;
  896. }
  897. }
  898. } else {
  899. // No @ symbol found. Check if this could be a port number instead of a protocol.
  900. // If what's after the colon is numeric (or starts with a digit and contains only
  901. // valid port characters until a path separator), it's likely hostname:port, not a protocol.
  902. var looks_like_port = /^[0-9]/.test(after_colon);
  903. if (looks_like_port) {
  904. // This looks like hostname:port, not a protocol
  905. if (options.require_protocol) {
  906. return false;
  907. }
  908. // Don't consume anything; let it be parsed as hostname:port
  909. } else {
  910. // This is definitely a protocol
  911. url = cleanUpProtocol(potential_protocol);
  912. if (url === false) {
  913. return false;
  914. }
  915. }
  916. }
  917. } else {
  918. // Starts with '//', this is definitely a protocol like http://
  919. url = cleanUpProtocol(potential_protocol);
  920. if (url === false) {
  921. return false;
  922. }
  923. }
  924. } else if (options.require_protocol) {
  925. return false;
  926. }
  927. // Handle leading '//' only as protocol-relative when there was NO explicit protocol.
  928. // If there was an explicit protocol, '//' is the normal separator
  929. // and should be stripped unconditionally.
  930. if (url.slice(0, 2) === '//') {
  931. if (!had_explicit_protocol && !options.allow_protocol_relative_urls) {
  932. return false;
  933. }
  934. url = url.slice(2);
  935. }
  936. if (url === '') {
  937. return false;
  938. }
  939. split = url.split('/');
  940. url = split.shift();
  941. if (url === '' && !options.require_host) {
  942. return true;
  943. }
  944. split = url.split('@');
  945. if (split.length > 1) {
  946. if (options.disallow_auth) {
  947. return false;
  948. }
  949. if (split[0] === '') {
  950. return false;
  951. }
  952. auth = split.shift();
  953. if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
  954. return false;
  955. }
  956. var _auth$split = auth.split(':'),
  957. _auth$split2 = _slicedToArray(_auth$split, 2),
  958. user = _auth$split2[0],
  959. password = _auth$split2[1];
  960. if (user === '' && password === '') {
  961. return false;
  962. }
  963. }
  964. hostname = split.join('@');
  965. port_str = null;
  966. ipv6 = null;
  967. var ipv6_match = hostname.match(wrapped_ipv6);
  968. if (ipv6_match) {
  969. host = '';
  970. ipv6 = ipv6_match[1];
  971. port_str = ipv6_match[2] || null;
  972. } else {
  973. split = hostname.split(':');
  974. host = split.shift();
  975. if (split.length) {
  976. port_str = split.join(':');
  977. }
  978. }
  979. if (port_str !== null && port_str.length > 0) {
  980. port = parseInt(port_str, 10);
  981. if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
  982. return false;
  983. }
  984. } else if (options.require_port) {
  985. return false;
  986. }
  987. if (options.host_whitelist) {
  988. return checkHost(host, options.host_whitelist);
  989. }
  990. if (host === '' && !options.require_host) {
  991. return true;
  992. }
  993. if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
  994. return false;
  995. }
  996. host = host || ipv6;
  997. if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
  998. return false;
  999. }
  1000. return true;
  1001. }
  1002. var macAddress48 = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
  1003. var macAddress48NoSeparators = /^([0-9a-fA-F]){12}$/;
  1004. var macAddress48WithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;
  1005. var macAddress64 = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){6}([0-9a-fA-F]{2})$/;
  1006. var macAddress64NoSeparators = /^([0-9a-fA-F]){16}$/;
  1007. var macAddress64WithDots = /^([0-9a-fA-F]{4}\.){3}([0-9a-fA-F]{4})$/;
  1008. function isMACAddress(str, options) {
  1009. assertString(str);
  1010. if (options !== null && options !== void 0 && options.eui) {
  1011. options.eui = String(options.eui);
  1012. }
  1013. /**
  1014. * @deprecated `no_colons` TODO: remove it in the next major
  1015. */
  1016. if (options !== null && options !== void 0 && options.no_colons || options !== null && options !== void 0 && options.no_separators) {
  1017. if (options.eui === '48') {
  1018. return macAddress48NoSeparators.test(str);
  1019. }
  1020. if (options.eui === '64') {
  1021. return macAddress64NoSeparators.test(str);
  1022. }
  1023. return macAddress48NoSeparators.test(str) || macAddress64NoSeparators.test(str);
  1024. }
  1025. if ((options === null || options === void 0 ? void 0 : options.eui) === '48') {
  1026. return macAddress48.test(str) || macAddress48WithDots.test(str);
  1027. }
  1028. if ((options === null || options === void 0 ? void 0 : options.eui) === '64') {
  1029. return macAddress64.test(str) || macAddress64WithDots.test(str);
  1030. }
  1031. return isMACAddress(str, {
  1032. eui: '48'
  1033. }) || isMACAddress(str, {
  1034. eui: '64'
  1035. });
  1036. }
  1037. var subnetMaybe = /^\d{1,3}$/;
  1038. var v4Subnet = 32;
  1039. var v6Subnet = 128;
  1040. function isIPRange(str) {
  1041. var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  1042. assertString(str);
  1043. var parts = str.split('/');
  1044. // parts[0] -> ip, parts[1] -> subnet
  1045. if (parts.length !== 2) {
  1046. return false;
  1047. }
  1048. if (!subnetMaybe.test(parts[1])) {
  1049. return false;
  1050. }
  1051. // Disallow preceding 0 i.e. 01, 02, ...
  1052. if (parts[1].length > 1 && parts[1].startsWith('0')) {
  1053. return false;
  1054. }
  1055. var isValidIP = isIP(parts[0], version);
  1056. if (!isValidIP) {
  1057. return false;
  1058. }
  1059. // Define valid subnet according to IP's version
  1060. var expectedSubnet = null;
  1061. switch (String(version)) {
  1062. case '4':
  1063. expectedSubnet = v4Subnet;
  1064. break;
  1065. case '6':
  1066. expectedSubnet = v6Subnet;
  1067. break;
  1068. default:
  1069. expectedSubnet = isIP(parts[0], '6') ? v6Subnet : v4Subnet;
  1070. }
  1071. return parts[1] <= expectedSubnet && parts[1] >= 0;
  1072. }
  1073. var default_date_options = {
  1074. format: 'YYYY/MM/DD',
  1075. delimiters: ['/', '-'],
  1076. strictMode: false
  1077. };
  1078. function isValidFormat(format) {
  1079. 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);
  1080. }
  1081. function zip(date, format) {
  1082. var zippedArr = [],
  1083. len = Math.max(date.length, format.length);
  1084. for (var i = 0; i < len; i++) {
  1085. zippedArr.push([date[i], format[i]]);
  1086. }
  1087. return zippedArr;
  1088. }
  1089. function isDate(input, options) {
  1090. if (typeof options === 'string') {
  1091. // Allow backward compatibility for old format isDate(input [, format])
  1092. options = merge({
  1093. format: options
  1094. }, default_date_options);
  1095. } else {
  1096. options = merge(options, default_date_options);
  1097. }
  1098. if (typeof input === 'string' && isValidFormat(options.format)) {
  1099. if (options.strictMode && input.length !== options.format.length) return false;
  1100. var formatDelimiter = options.delimiters.find(function (delimiter) {
  1101. return options.format.indexOf(delimiter) !== -1;
  1102. });
  1103. var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
  1104. return input.indexOf(delimiter) !== -1;
  1105. });
  1106. var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
  1107. var dateObj = {};
  1108. var _iterator = _createForOfIteratorHelper(dateAndFormat),
  1109. _step;
  1110. try {
  1111. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  1112. var _step$value = _slicedToArray(_step.value, 2),
  1113. dateWord = _step$value[0],
  1114. formatWord = _step$value[1];
  1115. if (!dateWord || !formatWord || dateWord.length !== formatWord.length) {
  1116. return false;
  1117. }
  1118. dateObj[formatWord.charAt(0)] = dateWord;
  1119. }
  1120. } catch (err) {
  1121. _iterator.e(err);
  1122. } finally {
  1123. _iterator.f();
  1124. }
  1125. var fullYear = dateObj.y;
  1126. // Check if the year starts with a hyphen
  1127. if (fullYear.startsWith('-')) {
  1128. return false; // Hyphen before year is not allowed
  1129. }
  1130. if (dateObj.y.length === 2) {
  1131. var parsedYear = parseInt(dateObj.y, 10);
  1132. if (isNaN(parsedYear)) {
  1133. return false;
  1134. }
  1135. var currentYearLastTwoDigits = new Date().getFullYear() % 100;
  1136. if (parsedYear < currentYearLastTwoDigits) {
  1137. fullYear = "20".concat(dateObj.y);
  1138. } else {
  1139. fullYear = "19".concat(dateObj.y);
  1140. }
  1141. }
  1142. var month = dateObj.m;
  1143. if (dateObj.m.length === 1) {
  1144. month = "0".concat(dateObj.m);
  1145. }
  1146. var day = dateObj.d;
  1147. if (dateObj.d.length === 1) {
  1148. day = "0".concat(dateObj.d);
  1149. }
  1150. return new Date("".concat(fullYear, "-").concat(month, "-").concat(day, "T00:00:00.000Z")).getUTCDate() === +dateObj.d;
  1151. }
  1152. if (!options.strictMode) {
  1153. return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
  1154. }
  1155. return false;
  1156. }
  1157. var default_time_options = {
  1158. hourFormat: 'hour24',
  1159. mode: 'default'
  1160. };
  1161. var formats = {
  1162. hour24: {
  1163. "default": /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/,
  1164. withSeconds: /^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/,
  1165. withOptionalSeconds: /^([01]?[0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9]))?$/
  1166. },
  1167. hour12: {
  1168. "default": /^(0?[1-9]|1[0-2]):([0-5][0-9]) (A|P)M$/,
  1169. withSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9]):([0-5][0-9]) (A|P)M$/,
  1170. withOptionalSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9])(?::([0-5][0-9]))? (A|P)M$/
  1171. }
  1172. };
  1173. function isTime(input, options) {
  1174. options = merge(options, default_time_options);
  1175. if (typeof input !== 'string') return false;
  1176. return formats[options.hourFormat][options.mode].test(input);
  1177. }
  1178. var includes$2 = function includes(arr, val) {
  1179. return arr.some(function (arrVal) {
  1180. return val === arrVal;
  1181. });
  1182. };
  1183. var defaultOptions = {
  1184. loose: false
  1185. };
  1186. var strictBooleans = ['true', 'false', '1', '0'];
  1187. var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
  1188. function isBoolean(str) {
  1189. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
  1190. assertString(str);
  1191. if (options.loose) {
  1192. return includes$2(looseBooleans, str.toLowerCase());
  1193. }
  1194. return includes$2(strictBooleans, str);
  1195. }
  1196. /*
  1197. = 3ALPHA ; selected ISO 639 codes
  1198. *2("-" 3ALPHA) ; permanently reserved
  1199. */
  1200. var extlang = '([A-Za-z]{3}(-[A-Za-z]{3}){0,2})';
  1201. /*
  1202. = 2*3ALPHA ; shortest ISO 639 code
  1203. ["-" extlang] ; sometimes followed by
  1204. ; extended language subtags
  1205. / 4ALPHA ; or reserved for future use
  1206. / 5*8ALPHA ; or registered language subtag
  1207. */
  1208. var language = "(([a-zA-Z]{2,3}(-".concat(extlang, ")?)|([a-zA-Z]{5,8}))");
  1209. /*
  1210. = 4ALPHA ; ISO 15924 code
  1211. */
  1212. var script = '([A-Za-z]{4})';
  1213. /*
  1214. = 2ALPHA ; ISO 3166-1 code
  1215. / 3DIGIT ; UN M.49 code
  1216. */
  1217. var region = '([A-Za-z]{2}|\\d{3})';
  1218. /*
  1219. = 5*8alphanum ; registered variants
  1220. / (DIGIT 3alphanum)
  1221. */
  1222. var variant = '([A-Za-z0-9]{5,8}|(\\d[A-Z-a-z0-9]{3}))';
  1223. /*
  1224. = DIGIT ; 0 - 9
  1225. / %x41-57 ; A - W
  1226. / %x59-5A ; Y - Z
  1227. / %x61-77 ; a - w
  1228. / %x79-7A ; y - z
  1229. */
  1230. var singleton = '(\\d|[A-W]|[Y-Z]|[a-w]|[y-z])';
  1231. /*
  1232. = singleton 1*("-" (2*8alphanum))
  1233. ; Single alphanumerics
  1234. ; "x" reserved for private use
  1235. */
  1236. var extension = "(".concat(singleton, "(-[A-Za-z0-9]{2,8})+)");
  1237. /*
  1238. = "x" 1*("-" (1*8alphanum))
  1239. */
  1240. var privateuse = '(x(-[A-Za-z0-9]{1,8})+)';
  1241. // irregular tags do not match the 'langtag' production and would not
  1242. // otherwise be considered 'well-formed'. These tags are all valid, but
  1243. // most are deprecated in favor of more modern subtags or subtag combination
  1244. var irregular = '((en-GB-oed)|(i-ami)|(i-bnn)|(i-default)|(i-enochian)|' + '(i-hak)|(i-klingon)|(i-lux)|(i-mingo)|(i-navajo)|(i-pwn)|(i-tao)|' + '(i-tay)|(i-tsu)|(sgn-BE-FR)|(sgn-BE-NL)|(sgn-CH-DE))';
  1245. // regular tags match the 'langtag' production, but their subtags are not
  1246. // extended language or variant subtags: their meaning is defined by
  1247. // their registration and all of these are deprecated in favor of a more
  1248. // modern subtag or sequence of subtags
  1249. var regular = '((art-lojban)|(cel-gaulish)|(no-bok)|(no-nyn)|(zh-guoyu)|' + '(zh-hakka)|(zh-min)|(zh-min-nan)|(zh-xiang))';
  1250. /*
  1251. = irregular ; non-redundant tags registered
  1252. / regular ; during the RFC 3066 era
  1253. */
  1254. var grandfathered = "(".concat(irregular, "|").concat(regular, ")");
  1255. /*
  1256. RFC 5646 defines delimitation of subtags via a hyphen:
  1257. "Subtag" refers to a specific section of a tag, delimited by a
  1258. hyphen, such as the subtags 'zh', 'Hant', and 'CN' in the tag "zh-
  1259. Hant-CN". Examples of subtags in this document are enclosed in
  1260. single quotes ('Hant')
  1261. However, we need to add "_" to maintain the existing behaviour.
  1262. */
  1263. var delimiter = '(-|_)';
  1264. /*
  1265. = language
  1266. ["-" script]
  1267. ["-" region]
  1268. *("-" variant)
  1269. *("-" extension)
  1270. ["-" privateuse]
  1271. */
  1272. var langtag = "".concat(language, "(").concat(delimiter).concat(script, ")?(").concat(delimiter).concat(region, ")?(").concat(delimiter).concat(variant, ")*(").concat(delimiter).concat(extension, ")*(").concat(delimiter).concat(privateuse, ")?");
  1273. /*
  1274. Regex implementation based on BCP RFC 5646
  1275. Tags for Identifying Languages
  1276. https://www.rfc-editor.org/rfc/rfc5646.html
  1277. */
  1278. var languageTagRegex = new RegExp("(^".concat(privateuse, "$)|(^").concat(grandfathered, "$)|(^").concat(langtag, "$)"));
  1279. function isLocale(str) {
  1280. assertString(str);
  1281. return languageTagRegex.test(str);
  1282. }
  1283. // http://www.brainjar.com/js/validation/
  1284. // https://www.aba.com/news-research/research-analysis/routing-number-policy-procedures
  1285. // series reserved for future use are excluded
  1286. var isRoutingReg = /^(?!(1[3-9])|(20)|(3[3-9])|(4[0-9])|(5[0-9])|(60)|(7[3-9])|(8[1-9])|(9[0-2])|(9[3-9]))[0-9]{9}$/;
  1287. function isAbaRouting(str) {
  1288. assertString(str);
  1289. if (!isRoutingReg.test(str)) return false;
  1290. var checkSumVal = 0;
  1291. for (var i = 0; i < str.length; i++) {
  1292. if (i % 3 === 0) checkSumVal += str[i] * 3;else if (i % 3 === 1) checkSumVal += str[i] * 7;else checkSumVal += str[i] * 1;
  1293. }
  1294. return checkSumVal % 10 === 0;
  1295. }
  1296. function isAlpha(_str) {
  1297. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  1298. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1299. assertString(_str);
  1300. var str = _str;
  1301. var ignore = options.ignore;
  1302. if (ignore) {
  1303. if (ignore instanceof RegExp) {
  1304. str = str.replace(ignore, '');
  1305. } else if (typeof ignore === 'string') {
  1306. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  1307. } else {
  1308. throw new Error('ignore should be instance of a String or RegExp');
  1309. }
  1310. }
  1311. if (locale in alpha) {
  1312. return alpha[locale].test(str);
  1313. }
  1314. throw new Error("Invalid locale '".concat(locale, "'"));
  1315. }
  1316. var locales$1 = Object.keys(alpha);
  1317. function isAlphanumeric(_str) {
  1318. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  1319. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  1320. assertString(_str);
  1321. var str = _str;
  1322. var ignore = options.ignore;
  1323. if (ignore) {
  1324. if (ignore instanceof RegExp) {
  1325. str = str.replace(ignore, '');
  1326. } else if (typeof ignore === 'string') {
  1327. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  1328. } else {
  1329. throw new Error('ignore should be instance of a String or RegExp');
  1330. }
  1331. }
  1332. if (locale in alphanumeric) {
  1333. return alphanumeric[locale].test(str);
  1334. }
  1335. throw new Error("Invalid locale '".concat(locale, "'"));
  1336. }
  1337. var locales$2 = Object.keys(alphanumeric);
  1338. var numericNoSymbols = /^[0-9]+$/;
  1339. function isNumeric(str, options) {
  1340. assertString(str);
  1341. if (options && options.no_symbols) {
  1342. return numericNoSymbols.test(str);
  1343. }
  1344. return new RegExp("^[+-]?([0-9]*[".concat((options || {}).locale ? decimal[options.locale] : '.', "])?[0-9]+$")).test(str);
  1345. }
  1346. /**
  1347. * Reference:
  1348. * https://en.wikipedia.org/ -- Wikipedia
  1349. * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
  1350. * https://countrycode.org/ -- Country Codes
  1351. */
  1352. var passportRegexByCountryCode = {
  1353. AM: /^[A-Z]{2}\d{7}$/,
  1354. // ARMENIA
  1355. AR: /^[A-Z]{3}\d{6}$/,
  1356. // ARGENTINA
  1357. AT: /^[A-Z]\d{7}$/,
  1358. // AUSTRIA
  1359. AU: /^[A-Z]\d{7}$/,
  1360. // AUSTRALIA
  1361. AZ: /^[A-Z]{1}\d{8}$/,
  1362. // AZERBAIJAN
  1363. BE: /^[A-Z]{2}\d{6}$/,
  1364. // BELGIUM
  1365. BG: /^\d{9}$/,
  1366. // BULGARIA
  1367. BR: /^[A-Z]{2}\d{6}$/,
  1368. // BRAZIL
  1369. BY: /^[A-Z]{2}\d{7}$/,
  1370. // BELARUS
  1371. CA: /^[A-Z]{2}\d{6}$|^[A-Z]\d{6}[A-Z]{2}$/,
  1372. // CANADA
  1373. CH: /^[A-Z]\d{7}$/,
  1374. // SWITZERLAND
  1375. CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
  1376. // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
  1377. CY: /^[A-Z](\d{6}|\d{8})$/,
  1378. // CYPRUS
  1379. CZ: /^\d{8}$/,
  1380. // CZECH REPUBLIC
  1381. DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
  1382. // GERMANY
  1383. DK: /^\d{9}$/,
  1384. // DENMARK
  1385. DZ: /^\d{9}$/,
  1386. // ALGERIA
  1387. EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
  1388. // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
  1389. ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
  1390. // SPAIN
  1391. FI: /^[A-Z]{2}\d{7}$/,
  1392. // FINLAND
  1393. FR: /^\d{2}[A-Z]{2}\d{5}$/,
  1394. // FRANCE
  1395. GB: /^\d{9}$/,
  1396. // UNITED KINGDOM
  1397. GR: /^[A-Z]{2}\d{7}$/,
  1398. // GREECE
  1399. HR: /^\d{9}$/,
  1400. // CROATIA
  1401. HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
  1402. // HUNGARY
  1403. IE: /^[A-Z0-9]{2}\d{7}$/,
  1404. // IRELAND
  1405. IN: /^[A-Z]{1}-?\d{7}$/,
  1406. // INDIA
  1407. ID: /^[A-C]\d{7}$/,
  1408. // INDONESIA
  1409. IR: /^[A-Z]\d{8}$/,
  1410. // IRAN
  1411. IS: /^(A)\d{7}$/,
  1412. // ICELAND
  1413. IT: /^[A-Z0-9]{2}\d{7}$/,
  1414. // ITALY
  1415. JM: /^[Aa]\d{7}$/,
  1416. // JAMAICA
  1417. JP: /^[A-Z]{2}\d{7}$/,
  1418. // JAPAN
  1419. KR: /^[MS]\d{8}$/,
  1420. // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
  1421. KZ: /^[a-zA-Z]\d{7}$/,
  1422. // KAZAKHSTAN
  1423. LI: /^[a-zA-Z]\d{5}$/,
  1424. // LIECHTENSTEIN
  1425. LT: /^[A-Z0-9]{8}$/,
  1426. // LITHUANIA
  1427. LU: /^[A-Z0-9]{8}$/,
  1428. // LUXEMBURG
  1429. LV: /^[A-Z0-9]{2}\d{7}$/,
  1430. // LATVIA
  1431. LY: /^[A-Z0-9]{8}$/,
  1432. // LIBYA
  1433. MT: /^\d{7}$/,
  1434. // MALTA
  1435. MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
  1436. // MOZAMBIQUE
  1437. MY: /^[AHK]\d{8}$/,
  1438. // MALAYSIA
  1439. MX: /^\d{10,11}$/,
  1440. // MEXICO
  1441. NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
  1442. // NETHERLANDS
  1443. NZ: /^([Ll]([Aa]|[Dd]|[Ff]|[Hh])|[Ee]([Aa]|[Pp])|[Nn])\d{6}$/,
  1444. // NEW ZEALAND
  1445. PH: /^([A-Z](\d{6}|\d{7}[A-Z]))|([A-Z]{2}(\d{6}|\d{7}))$/,
  1446. // PHILIPPINES
  1447. PK: /^[A-Z]{2}\d{7}$/,
  1448. // PAKISTAN
  1449. PL: /^[A-Z]{2}\d{7}$/,
  1450. // POLAND
  1451. PT: /^[A-Z]\d{6}$/,
  1452. // PORTUGAL
  1453. RO: /^\d{8,9}$/,
  1454. // ROMANIA
  1455. RU: /^\d{9}$/,
  1456. // RUSSIAN FEDERATION
  1457. SE: /^\d{8}$/,
  1458. // SWEDEN
  1459. SL: /^(P)[A-Z]\d{7}$/,
  1460. // SLOVENIA
  1461. SK: /^[0-9A-Z]\d{7}$/,
  1462. // SLOVAKIA
  1463. TH: /^[A-Z]{1,2}\d{6,7}$/,
  1464. // THAILAND
  1465. TR: /^[A-Z]\d{8}$/,
  1466. // TURKEY
  1467. UA: /^[A-Z]{2}\d{6}$/,
  1468. // UKRAINE
  1469. US: /^\d{9}$|^[A-Z]\d{8}$/,
  1470. // UNITED STATES
  1471. ZA: /^[TAMD]\d{8}$/ // SOUTH AFRICA
  1472. };
  1473. var locales$3 = Object.keys(passportRegexByCountryCode);
  1474. /**
  1475. * Check if str is a valid passport number
  1476. * relative to provided ISO Country Code.
  1477. *
  1478. * @param {string} str
  1479. * @param {string} countryCode
  1480. * @return {boolean}
  1481. */
  1482. function isPassportNumber(str, countryCode) {
  1483. assertString(str);
  1484. /** Remove All Whitespaces, Convert to UPPERCASE */
  1485. var normalizedStr = str.replace(/\s/g, '').toUpperCase();
  1486. return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
  1487. }
  1488. var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
  1489. var intLeadingZeroes = /^[-+]?[0-9]+$/;
  1490. function isInt(str, options) {
  1491. assertString(str);
  1492. options = options || {};
  1493. // Get the regex to use for testing, based on whether
  1494. // leading zeroes are allowed or not.
  1495. var regex = options.allow_leading_zeroes === false ? _int : intLeadingZeroes;
  1496. // Check min/max/lt/gt
  1497. var minCheckPassed = !options.hasOwnProperty('min') || isNullOrUndefined(options.min) || str >= options.min;
  1498. var maxCheckPassed = !options.hasOwnProperty('max') || isNullOrUndefined(options.max) || str <= options.max;
  1499. var ltCheckPassed = !options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || str < options.lt;
  1500. var gtCheckPassed = !options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || str > options.gt;
  1501. return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
  1502. }
  1503. function isPort(str) {
  1504. return isInt(str, {
  1505. allow_leading_zeroes: false,
  1506. min: 0,
  1507. max: 65535
  1508. });
  1509. }
  1510. function isLowercase(str) {
  1511. assertString(str);
  1512. return str === str.toLowerCase();
  1513. }
  1514. function isUppercase(str) {
  1515. assertString(str);
  1516. return str === str.toUpperCase();
  1517. }
  1518. var imeiRegexWithoutHyphens = /^[0-9]{15}$/;
  1519. var imeiRegexWithHyphens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;
  1520. function isIMEI(str, options) {
  1521. assertString(str);
  1522. options = options || {};
  1523. // default regex for checking imei is the one without hyphens
  1524. var imeiRegex = imeiRegexWithoutHyphens;
  1525. if (options.allow_hyphens) {
  1526. imeiRegex = imeiRegexWithHyphens;
  1527. }
  1528. if (!imeiRegex.test(str)) {
  1529. return false;
  1530. }
  1531. str = str.replace(/-/g, '');
  1532. var sum = 0,
  1533. mul = 2,
  1534. l = 14;
  1535. for (var i = 0; i < l; i++) {
  1536. var digit = str.substring(l - i - 1, l - i);
  1537. var tp = parseInt(digit, 10) * mul;
  1538. if (tp >= 10) {
  1539. sum += tp % 10 + 1;
  1540. } else {
  1541. sum += tp;
  1542. }
  1543. if (mul === 1) {
  1544. mul += 1;
  1545. } else {
  1546. mul -= 1;
  1547. }
  1548. }
  1549. var chk = (10 - sum % 10) % 10;
  1550. if (chk !== parseInt(str.substring(14, 15), 10)) {
  1551. return false;
  1552. }
  1553. return true;
  1554. }
  1555. /* eslint-disable no-control-regex */
  1556. var ascii = /^[\x00-\x7F]+$/;
  1557. /* eslint-enable no-control-regex */
  1558. function isAscii(str) {
  1559. assertString(str);
  1560. return ascii.test(str);
  1561. }
  1562. var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  1563. function isFullWidth(str) {
  1564. assertString(str);
  1565. return fullWidth.test(str);
  1566. }
  1567. var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
  1568. function isHalfWidth(str) {
  1569. assertString(str);
  1570. return halfWidth.test(str);
  1571. }
  1572. function isVariableWidth(str) {
  1573. assertString(str);
  1574. return fullWidth.test(str) && halfWidth.test(str);
  1575. }
  1576. /* eslint-disable no-control-regex */
  1577. var multibyte = /[^\x00-\x7F]/;
  1578. /* eslint-enable no-control-regex */
  1579. function isMultibyte(str) {
  1580. assertString(str);
  1581. return multibyte.test(str);
  1582. }
  1583. /**
  1584. * Build RegExp object from an array
  1585. * of multiple/multi-line regexp parts
  1586. *
  1587. * @param {string[]} parts
  1588. * @param {string} flags
  1589. * @return {object} - RegExp object
  1590. */
  1591. function multilineRegexp(parts, flags) {
  1592. var regexpAsStringLiteral = parts.join('');
  1593. return new RegExp(regexpAsStringLiteral, flags);
  1594. }
  1595. /**
  1596. * Regular Expression to match
  1597. * semantic versioning (SemVer)
  1598. * built from multi-line, multi-parts regexp
  1599. * Reference: https://semver.org/
  1600. */
  1601. 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');
  1602. function isSemVer(str) {
  1603. assertString(str);
  1604. return semanticVersioningRegex.test(str);
  1605. }
  1606. var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
  1607. function isSurrogatePair(str) {
  1608. assertString(str);
  1609. return surrogatePair.test(str);
  1610. }
  1611. function decimalRegExp(options) {
  1612. var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
  1613. return regExp;
  1614. }
  1615. var default_decimal_options = {
  1616. force_decimal: false,
  1617. decimal_digits: '1,',
  1618. locale: 'en-US'
  1619. };
  1620. var blacklist = ['', '-', '+'];
  1621. function isDecimal(str, options) {
  1622. assertString(str);
  1623. options = merge(options, default_decimal_options);
  1624. if (options.locale in decimal) {
  1625. return !includes$2(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
  1626. }
  1627. throw new Error("Invalid locale '".concat(options.locale, "'"));
  1628. }
  1629. var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;
  1630. function isHexadecimal(str) {
  1631. assertString(str);
  1632. return hexadecimal.test(str);
  1633. }
  1634. var octal = /^(0o)?[0-7]+$/i;
  1635. function isOctal(str) {
  1636. assertString(str);
  1637. return octal.test(str);
  1638. }
  1639. function isDivisibleBy(str, num) {
  1640. assertString(str);
  1641. return toFloat(str) % parseInt(num, 10) === 0;
  1642. }
  1643. var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
  1644. var hexcolor_with_prefix = /^#([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
  1645. var default_is_hexcolor_options = {
  1646. require_hashtag: false
  1647. };
  1648. function isHexColor(str, options) {
  1649. assertString(str);
  1650. options = merge(options, default_is_hexcolor_options);
  1651. var hexcolor_regex = options.require_hashtag ? hexcolor_with_prefix : hexcolor;
  1652. return hexcolor_regex.test(str);
  1653. }
  1654. /* eslint-disable prefer-rest-params */
  1655. 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])\)$/;
  1656. 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\d?|1(\.0)?|0(\.0)?)\)$/;
  1657. var rgbColorPercent = /^rgb\((([0-9]%|[1-9][0-9]%|100%),){2}([0-9]%|[1-9][0-9]%|100%)\)$/;
  1658. var rgbaColorPercent = /^rgba\((([0-9]%|[1-9][0-9]%|100%),){3}(0?\.\d\d?|1(\.0)?|0(\.0)?)\)$/;
  1659. var startsWithRgb = /^rgba?/;
  1660. function isRgbColor(str, options) {
  1661. assertString(str);
  1662. // default options to true for percent and false for spaces
  1663. var allowSpaces = false;
  1664. var includePercentValues = true;
  1665. if (_typeof(options) !== 'object') {
  1666. if (arguments.length >= 2) {
  1667. includePercentValues = arguments[1];
  1668. }
  1669. } else {
  1670. allowSpaces = options.allowSpaces !== undefined ? options.allowSpaces : allowSpaces;
  1671. includePercentValues = options.includePercentValues !== undefined ? options.includePercentValues : includePercentValues;
  1672. }
  1673. if (allowSpaces) {
  1674. // make sure it starts with continous rgba? without spaces before stripping
  1675. if (!startsWithRgb.test(str)) {
  1676. return false;
  1677. }
  1678. // strip all whitespace
  1679. str = str.replace(/\s/g, '');
  1680. }
  1681. if (!includePercentValues) {
  1682. return rgbColor.test(str) || rgbaColor.test(str);
  1683. }
  1684. return rgbColor.test(str) || rgbaColor.test(str) || rgbColorPercent.test(str) || rgbaColorPercent.test(str);
  1685. }
  1686. 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;
  1687. 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;
  1688. function isHSL(str) {
  1689. assertString(str);
  1690. // Strip duplicate spaces before calling the validation regex (See #1598 for more info)
  1691. var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
  1692. if (strippedStr.indexOf(',') !== -1) {
  1693. return hslComma.test(strippedStr);
  1694. }
  1695. return hslSpace.test(strippedStr);
  1696. }
  1697. // see http://isrc.ifpi.org/en/isrc-standard/code-syntax
  1698. var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;
  1699. function isISRC(str) {
  1700. assertString(str);
  1701. return isrc.test(str);
  1702. }
  1703. /**
  1704. * List of country codes with
  1705. * corresponding IBAN regular expression
  1706. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  1707. */
  1708. var ibanRegexThroughCountryCode = {
  1709. AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
  1710. AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
  1711. AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  1712. AT: /^(AT[0-9]{2})\d{16}$/,
  1713. AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1714. BA: /^(BA[0-9]{2})\d{16}$/,
  1715. BE: /^(BE[0-9]{2})\d{12}$/,
  1716. BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
  1717. BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
  1718. BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,
  1719. BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1720. CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  1721. CR: /^(CR[0-9]{2})\d{18}$/,
  1722. CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/,
  1723. CZ: /^(CZ[0-9]{2})\d{20}$/,
  1724. DE: /^(DE[0-9]{2})\d{18}$/,
  1725. DK: /^(DK[0-9]{2})\d{14}$/,
  1726. DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/,
  1727. DZ: /^(DZ\d{24})$/,
  1728. EE: /^(EE[0-9]{2})\d{16}$/,
  1729. EG: /^(EG[0-9]{2})\d{25}$/,
  1730. ES: /^(ES[0-9]{2})\d{20}$/,
  1731. FI: /^(FI[0-9]{2})\d{14}$/,
  1732. FO: /^(FO[0-9]{2})\d{14}$/,
  1733. FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  1734. GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/,
  1735. GE: /^(GE[0-9]{2})[A-Z0-9]{2}\d{16}$/,
  1736. GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/,
  1737. GL: /^(GL[0-9]{2})\d{14}$/,
  1738. GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/,
  1739. GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
  1740. HR: /^(HR[0-9]{2})\d{17}$/,
  1741. HU: /^(HU[0-9]{2})\d{24}$/,
  1742. IE: /^(IE[0-9]{2})[A-Z]{4}\d{14}$/,
  1743. IL: /^(IL[0-9]{2})\d{19}$/,
  1744. IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
  1745. IR: /^(IR[0-9]{2})\d{22}$/,
  1746. IS: /^(IS[0-9]{2})\d{22}$/,
  1747. IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  1748. JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/,
  1749. KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/,
  1750. KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  1751. LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/,
  1752. LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,
  1753. LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/,
  1754. LT: /^(LT[0-9]{2})\d{16}$/,
  1755. LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
  1756. LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
  1757. MA: /^(MA[0-9]{26})$/,
  1758. MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
  1759. MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
  1760. ME: /^(ME[0-9]{2})\d{18}$/,
  1761. MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,
  1762. MR: /^(MR[0-9]{2})\d{23}$/,
  1763. MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,
  1764. MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,
  1765. MZ: /^(MZ[0-9]{2})\d{21}$/,
  1766. NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
  1767. NO: /^(NO[0-9]{2})\d{11}$/,
  1768. PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
  1769. PL: /^(PL[0-9]{2})\d{24}$/,
  1770. PS: /^(PS[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
  1771. PT: /^(PT[0-9]{2})\d{21}$/,
  1772. QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
  1773. RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
  1774. RS: /^(RS[0-9]{2})\d{18}$/,
  1775. SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
  1776. SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
  1777. SE: /^(SE[0-9]{2})\d{20}$/,
  1778. SI: /^(SI[0-9]{2})\d{15}$/,
  1779. SK: /^(SK[0-9]{2})\d{20}$/,
  1780. SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
  1781. SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
  1782. TL: /^(TL[0-9]{2})\d{19}$/,
  1783. TN: /^(TN[0-9]{2})\d{20}$/,
  1784. TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
  1785. UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
  1786. VA: /^(VA[0-9]{2})\d{18}$/,
  1787. VG: /^(VG[0-9]{2})[A-Z]{4}\d{16}$/,
  1788. XK: /^(XK[0-9]{2})\d{16}$/
  1789. };
  1790. /**
  1791. * Check if the country codes passed are valid using the
  1792. * ibanRegexThroughCountryCode as a reference
  1793. *
  1794. * @param {array} countryCodeArray
  1795. * @return {boolean}
  1796. */
  1797. function hasOnlyValidCountryCodes(countryCodeArray) {
  1798. var countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray.filter(function (countryCode) {
  1799. return !(countryCode in ibanRegexThroughCountryCode);
  1800. });
  1801. if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) {
  1802. return false;
  1803. }
  1804. return true;
  1805. }
  1806. /**
  1807. * Check whether string has correct universal IBAN format
  1808. * The IBAN consists of up to 34 alphanumeric characters, as follows:
  1809. * Country Code using ISO 3166-1 alpha-2, two letters
  1810. * check digits, two digits and
  1811. * Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
  1812. * NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
  1813. *
  1814. * @param {string} str - string under validation
  1815. * @param {object} options - object to pass the countries to be either whitelisted or blacklisted
  1816. * @return {boolean}
  1817. */
  1818. function hasValidIbanFormat(str, options) {
  1819. // Strip white spaces and hyphens
  1820. var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
  1821. var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
  1822. var isoCountryCodeInIbanRegexCodeObject = isoCountryCode in ibanRegexThroughCountryCode;
  1823. if (options.whitelist) {
  1824. if (!hasOnlyValidCountryCodes(options.whitelist)) {
  1825. return false;
  1826. }
  1827. var isoCountryCodeInWhiteList = includes$2(options.whitelist, isoCountryCode);
  1828. if (!isoCountryCodeInWhiteList) {
  1829. return false;
  1830. }
  1831. }
  1832. if (options.blacklist) {
  1833. var isoCountryCodeInBlackList = includes$2(options.blacklist, isoCountryCode);
  1834. if (isoCountryCodeInBlackList) {
  1835. return false;
  1836. }
  1837. }
  1838. return isoCountryCodeInIbanRegexCodeObject && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
  1839. }
  1840. /**
  1841. * Check whether string has valid IBAN Checksum
  1842. * by performing basic mod-97 operation and
  1843. * the remainder should equal 1
  1844. * -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
  1845. * -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
  1846. * -- Interpret the string as a decimal integer and
  1847. * -- compute the remainder on division by 97 (mod 97)
  1848. * Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
  1849. *
  1850. * @param {string} str
  1851. * @return {boolean}
  1852. */
  1853. function hasValidIbanChecksum(str) {
  1854. var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
  1855. var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
  1856. var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (_char) {
  1857. return _char.charCodeAt(0) - 55;
  1858. });
  1859. var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
  1860. return Number(acc + value) % 97;
  1861. }, '');
  1862. return remainder === 1;
  1863. }
  1864. function isIBAN(str) {
  1865. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1866. assertString(str);
  1867. return hasValidIbanFormat(str, options) && hasValidIbanChecksum(str);
  1868. }
  1869. var locales$4 = Object.keys(ibanRegexThroughCountryCode);
  1870. // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
  1871. 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']);
  1872. function isISO31661Alpha2(str) {
  1873. assertString(str);
  1874. return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
  1875. }
  1876. var CountryCodes = validISO31661Alpha2CountriesCodes;
  1877. // https://en.wikipedia.org/wiki/ISO_9362
  1878. var isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
  1879. function isBIC(str) {
  1880. assertString(str);
  1881. // toUpperCase() should be removed when a new major version goes out that changes
  1882. // the regex to [A-Z] (per the spec).
  1883. var countryCode = str.slice(4, 6).toUpperCase();
  1884. if (!CountryCodes.has(countryCode) && countryCode !== 'XK') {
  1885. return false;
  1886. }
  1887. return isBICReg.test(str);
  1888. }
  1889. var md5 = /^[a-f0-9]{32}$/;
  1890. function isMD5(str) {
  1891. assertString(str);
  1892. return md5.test(str);
  1893. }
  1894. var lengths = {
  1895. md5: 32,
  1896. md4: 32,
  1897. sha1: 40,
  1898. sha256: 64,
  1899. sha384: 96,
  1900. sha512: 128,
  1901. ripemd128: 32,
  1902. ripemd160: 40,
  1903. tiger128: 32,
  1904. tiger160: 40,
  1905. tiger192: 48,
  1906. crc32: 8,
  1907. crc32b: 8
  1908. };
  1909. function isHash(str, algorithm) {
  1910. assertString(str);
  1911. var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$"));
  1912. return hash.test(str);
  1913. }
  1914. var base64WithPadding = /^[A-Za-z0-9+/]+={0,2}$/;
  1915. var base64WithoutPadding = /^[A-Za-z0-9+/]+$/;
  1916. var base64UrlWithPadding = /^[A-Za-z0-9_-]+={0,2}$/;
  1917. var base64UrlWithoutPadding = /^[A-Za-z0-9_-]+$/;
  1918. function isBase64(str, options) {
  1919. var _options;
  1920. assertString(str);
  1921. options = merge(options, {
  1922. urlSafe: false,
  1923. padding: !((_options = options) !== null && _options !== void 0 && _options.urlSafe)
  1924. });
  1925. if (str === '') return true;
  1926. if (options.padding && str.length % 4 !== 0) return false;
  1927. var regex;
  1928. if (options.urlSafe) {
  1929. regex = options.padding ? base64UrlWithPadding : base64UrlWithoutPadding;
  1930. } else {
  1931. regex = options.padding ? base64WithPadding : base64WithoutPadding;
  1932. }
  1933. return (!options.padding || str.length % 4 === 0) && regex.test(str);
  1934. }
  1935. function isJWT(str) {
  1936. assertString(str);
  1937. var dotSplit = str.split('.');
  1938. var len = dotSplit.length;
  1939. if (len !== 3) {
  1940. return false;
  1941. }
  1942. return dotSplit.reduce(function (acc, currElem) {
  1943. return acc && isBase64(currElem, {
  1944. urlSafe: true
  1945. });
  1946. }, true);
  1947. }
  1948. var default_json_options = {
  1949. allow_primitives: false
  1950. };
  1951. function isJSON(str, options) {
  1952. assertString(str);
  1953. try {
  1954. options = merge(options, default_json_options);
  1955. var primitives = [];
  1956. if (options.allow_primitives) {
  1957. primitives = [null, false, true];
  1958. }
  1959. var obj = JSON.parse(str);
  1960. return includes$2(primitives, obj) || !!obj && _typeof(obj) === 'object';
  1961. } catch (e) {/* ignore */}
  1962. return false;
  1963. }
  1964. var default_is_empty_options = {
  1965. ignore_whitespace: false
  1966. };
  1967. function isEmpty(str, options) {
  1968. assertString(str);
  1969. options = merge(options, default_is_empty_options);
  1970. return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
  1971. }
  1972. /* eslint-disable prefer-rest-params */
  1973. function isLength(str, options) {
  1974. assertString(str);
  1975. var min;
  1976. var max;
  1977. if (_typeof(options) === 'object') {
  1978. min = options.min || 0;
  1979. max = options.max;
  1980. } else {
  1981. // backwards compatibility: isLength(str, min [, max])
  1982. min = arguments[1] || 0;
  1983. max = arguments[2];
  1984. }
  1985. var presentationSequences = str.match(/[^\uFE0F\uFE0E][\uFE0F\uFE0E]/g) || [];
  1986. var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
  1987. var len = str.length - presentationSequences.length - surrogatePairs.length;
  1988. var isInsideRange = len >= min && (typeof max === 'undefined' || len <= max);
  1989. if (isInsideRange && Array.isArray(options === null || options === void 0 ? void 0 : options.discreteLengths)) {
  1990. return options.discreteLengths.some(function (discreteLen) {
  1991. return discreteLen === len;
  1992. });
  1993. }
  1994. return isInsideRange;
  1995. }
  1996. function isULID(str) {
  1997. assertString(str);
  1998. return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i.test(str);
  1999. }
  2000. var uuid = {
  2001. 1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2002. 2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2003. 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2004. 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2005. 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2006. 6: /^[0-9A-F]{8}-[0-9A-F]{4}-6[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2007. 7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2008. 8: /^[0-9A-F]{8}-[0-9A-F]{4}-8[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  2009. nil: /^00000000-0000-0000-0000-000000000000$/i,
  2010. max: /^ffffffff-ffff-ffff-ffff-ffffffffffff$/i,
  2011. loose: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  2012. // From https://github.com/uuidjs/uuid/blob/main/src/regex.js
  2013. all: /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i
  2014. };
  2015. function isUUID(str, version) {
  2016. assertString(str);
  2017. if (version === undefined || version === null) {
  2018. version = 'all';
  2019. }
  2020. return version in uuid ? uuid[version].test(str) : false;
  2021. }
  2022. function isMongoId(str) {
  2023. assertString(str);
  2024. return isHexadecimal(str) && str.length === 24;
  2025. }
  2026. function isAfter(date, options) {
  2027. // For backwards compatibility:
  2028. // isAfter(str [, date]), i.e. `options` could be used as argument for the legacy `date`
  2029. var comparisonDate = (_typeof(options) === 'object' ? options.comparisonDate : options) || Date().toString();
  2030. var comparison = toDate(comparisonDate);
  2031. var original = toDate(date);
  2032. return !!(original && comparison && original > comparison);
  2033. }
  2034. function isBefore(date, options) {
  2035. // For backwards compatibility:
  2036. // isBefore(str [, date]), i.e. `options` could be used as argument for the legacy `date`
  2037. var comparisonDate = (_typeof(options) === 'object' ? options.comparisonDate : options) || Date().toString();
  2038. var comparison = toDate(comparisonDate);
  2039. var original = toDate(date);
  2040. return !!(original && comparison && original < comparison);
  2041. }
  2042. function isIn(str, options) {
  2043. assertString(str);
  2044. var i;
  2045. if (Object.prototype.toString.call(options) === '[object Array]') {
  2046. var array = [];
  2047. for (i in options) {
  2048. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  2049. // istanbul ignore else
  2050. if ({}.hasOwnProperty.call(options, i)) {
  2051. array[i] = toString$1(options[i]);
  2052. }
  2053. }
  2054. return array.indexOf(str) >= 0;
  2055. } else if (_typeof(options) === 'object') {
  2056. return options.hasOwnProperty(str);
  2057. } else if (options && typeof options.indexOf === 'function') {
  2058. return options.indexOf(str) >= 0;
  2059. }
  2060. return false;
  2061. }
  2062. function isLuhnNumber(str) {
  2063. assertString(str);
  2064. var sanitized = str.replace(/[- ]+/g, '');
  2065. var sum = 0;
  2066. var digit;
  2067. var tmpNum;
  2068. var shouldDouble;
  2069. for (var i = sanitized.length - 1; i >= 0; i--) {
  2070. digit = sanitized.substring(i, i + 1);
  2071. tmpNum = parseInt(digit, 10);
  2072. if (shouldDouble) {
  2073. tmpNum *= 2;
  2074. if (tmpNum >= 10) {
  2075. sum += tmpNum % 10 + 1;
  2076. } else {
  2077. sum += tmpNum;
  2078. }
  2079. } else {
  2080. sum += tmpNum;
  2081. }
  2082. shouldDouble = !shouldDouble;
  2083. }
  2084. return !!(sum % 10 === 0 ? sanitized : false);
  2085. }
  2086. var cards = {
  2087. amex: /^3[47][0-9]{13}$/,
  2088. dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
  2089. discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/,
  2090. jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
  2091. 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}$/,
  2092. // /^[25][1-7][0-9]{14}$/;
  2093. unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
  2094. visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/
  2095. };
  2096. var allCards = function () {
  2097. var tmpCardsArray = [];
  2098. for (var cardProvider in cards) {
  2099. // istanbul ignore else
  2100. if (cards.hasOwnProperty(cardProvider)) {
  2101. tmpCardsArray.push(cards[cardProvider]);
  2102. }
  2103. }
  2104. return tmpCardsArray;
  2105. }();
  2106. function isCreditCard(card) {
  2107. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2108. assertString(card);
  2109. var provider = options.provider;
  2110. var sanitized = card.replace(/[- ]+/g, '');
  2111. if (provider && provider.toLowerCase() in cards) {
  2112. // specific provider in the list
  2113. if (!cards[provider.toLowerCase()].test(sanitized)) {
  2114. return false;
  2115. }
  2116. } else if (provider && !(provider.toLowerCase() in cards)) {
  2117. /* specific provider not in the list */
  2118. throw new Error("".concat(provider, " is not a valid credit card provider."));
  2119. } else if (!allCards.some(function (cardProvider) {
  2120. return cardProvider.test(sanitized);
  2121. })) {
  2122. // no specific provider
  2123. return false;
  2124. }
  2125. return isLuhnNumber(card);
  2126. }
  2127. var validators = {
  2128. PL: function PL(str) {
  2129. assertString(str);
  2130. var weightOfDigits = {
  2131. 1: 1,
  2132. 2: 3,
  2133. 3: 7,
  2134. 4: 9,
  2135. 5: 1,
  2136. 6: 3,
  2137. 7: 7,
  2138. 8: 9,
  2139. 9: 1,
  2140. 10: 3,
  2141. 11: 0
  2142. };
  2143. if (str != null && str.length === 11 && isInt(str, {
  2144. allow_leading_zeroes: true
  2145. })) {
  2146. var digits = str.split('').slice(0, -1);
  2147. var sum = digits.reduce(function (acc, digit, index) {
  2148. return acc + Number(digit) * weightOfDigits[index + 1];
  2149. }, 0);
  2150. var modulo = sum % 10;
  2151. var lastDigit = Number(str.charAt(str.length - 1));
  2152. if (modulo === 0 && lastDigit === 0 || lastDigit === 10 - modulo) {
  2153. return true;
  2154. }
  2155. }
  2156. return false;
  2157. },
  2158. ES: function ES(str) {
  2159. assertString(str);
  2160. var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
  2161. var charsValue = {
  2162. X: 0,
  2163. Y: 1,
  2164. Z: 2
  2165. };
  2166. 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'];
  2167. // sanitize user input
  2168. var sanitized = str.trim().toUpperCase();
  2169. // validate the data structure
  2170. if (!DNI.test(sanitized)) {
  2171. return false;
  2172. }
  2173. // validate the control digit
  2174. var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
  2175. return charsValue[_char];
  2176. });
  2177. return sanitized.endsWith(controlDigits[number % 23]);
  2178. },
  2179. FI: function FI(str) {
  2180. // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated
  2181. assertString(str);
  2182. if (str.length !== 11) {
  2183. return false;
  2184. }
  2185. if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) {
  2186. return false;
  2187. }
  2188. var checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY';
  2189. var idAsNumber = parseInt(str.slice(0, 6), 10) * 1000 + parseInt(str.slice(7, 10), 10);
  2190. var remainder = idAsNumber % 31;
  2191. var checkDigit = checkDigits[remainder];
  2192. return checkDigit === str.slice(10, 11);
  2193. },
  2194. IN: function IN(str) {
  2195. var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/;
  2196. // multiplication table
  2197. 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]];
  2198. // permutation table
  2199. 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]];
  2200. // sanitize user input
  2201. var sanitized = str.trim();
  2202. // validate the data structure
  2203. if (!DNI.test(sanitized)) {
  2204. return false;
  2205. }
  2206. var c = 0;
  2207. var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
  2208. invertedArray.forEach(function (val, i) {
  2209. c = d[c][p[i % 8][val]];
  2210. });
  2211. return c === 0;
  2212. },
  2213. IR: function IR(str) {
  2214. if (!str.match(/^\d{10}$/)) return false;
  2215. str = "0000".concat(str).slice(str.length - 6);
  2216. if (parseInt(str.slice(3, 9), 10) === 0) return false;
  2217. var lastNumber = parseInt(str.slice(9, 10), 10);
  2218. var sum = 0;
  2219. for (var i = 0; i < 9; i++) {
  2220. sum += parseInt(str.slice(i, i + 1), 10) * (10 - i);
  2221. }
  2222. sum %= 11;
  2223. return sum < 2 && lastNumber === sum || sum >= 2 && lastNumber === 11 - sum;
  2224. },
  2225. IT: function IT(str) {
  2226. if (str.length !== 9) return false;
  2227. if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
  2228. return str.search(/C[A-Z]\d{5}[A-Z]{2}/i) > -1;
  2229. },
  2230. NO: function NO(str) {
  2231. var sanitized = str.trim();
  2232. if (isNaN(Number(sanitized))) return false;
  2233. if (sanitized.length !== 11) return false;
  2234. if (sanitized === '00000000000') return false;
  2235. // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
  2236. var f = sanitized.split('').map(Number);
  2237. 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;
  2238. 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;
  2239. if (k1 !== f[9] || k2 !== f[10]) return false;
  2240. return true;
  2241. },
  2242. TH: function TH(str) {
  2243. if (!str.match(/^[1-8]\d{12}$/)) return false;
  2244. // validate check digit
  2245. var sum = 0;
  2246. for (var i = 0; i < 12; i++) {
  2247. sum += parseInt(str[i], 10) * (13 - i);
  2248. }
  2249. return str[12] === ((11 - sum % 11) % 10).toString();
  2250. },
  2251. LK: function LK(str) {
  2252. var old_nic = /^[1-9]\d{8}[vx]$/i;
  2253. var new_nic = /^[1-9]\d{11}$/i;
  2254. if (str.length === 10 && old_nic.test(str)) return true;else if (str.length === 12 && new_nic.test(str)) return true;
  2255. return false;
  2256. },
  2257. 'he-IL': function heIL(str) {
  2258. var DNI = /^\d{9}$/;
  2259. // sanitize user input
  2260. var sanitized = str.trim();
  2261. // validate the data structure
  2262. if (!DNI.test(sanitized)) {
  2263. return false;
  2264. }
  2265. var id = sanitized;
  2266. var sum = 0,
  2267. incNum;
  2268. for (var i = 0; i < id.length; i++) {
  2269. incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
  2270. sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
  2271. }
  2272. return sum % 10 === 0;
  2273. },
  2274. 'ar-LY': function arLY(str) {
  2275. // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
  2276. var NIN = /^(1|2)\d{11}$/;
  2277. // sanitize user input
  2278. var sanitized = str.trim();
  2279. // validate the data structure
  2280. if (!NIN.test(sanitized)) {
  2281. return false;
  2282. }
  2283. return true;
  2284. },
  2285. 'ar-TN': function arTN(str) {
  2286. var DNI = /^\d{8}$/;
  2287. // sanitize user input
  2288. var sanitized = str.trim();
  2289. // validate the data structure
  2290. if (!DNI.test(sanitized)) {
  2291. return false;
  2292. }
  2293. return true;
  2294. },
  2295. 'zh-CN': function zhCN(str) {
  2296. var provincesAndCities = ['11',
  2297. // 北京
  2298. '12',
  2299. // 天津
  2300. '13',
  2301. // 河北
  2302. '14',
  2303. // 山西
  2304. '15',
  2305. // 内蒙古
  2306. '21',
  2307. // 辽宁
  2308. '22',
  2309. // 吉林
  2310. '23',
  2311. // 黑龙江
  2312. '31',
  2313. // 上海
  2314. '32',
  2315. // 江苏
  2316. '33',
  2317. // 浙江
  2318. '34',
  2319. // 安徽
  2320. '35',
  2321. // 福建
  2322. '36',
  2323. // 江西
  2324. '37',
  2325. // 山东
  2326. '41',
  2327. // 河南
  2328. '42',
  2329. // 湖北
  2330. '43',
  2331. // 湖南
  2332. '44',
  2333. // 广东
  2334. '45',
  2335. // 广西
  2336. '46',
  2337. // 海南
  2338. '50',
  2339. // 重庆
  2340. '51',
  2341. // 四川
  2342. '52',
  2343. // 贵州
  2344. '53',
  2345. // 云南
  2346. '54',
  2347. // 西藏
  2348. '61',
  2349. // 陕西
  2350. '62',
  2351. // 甘肃
  2352. '63',
  2353. // 青海
  2354. '64',
  2355. // 宁夏
  2356. '65',
  2357. // 新疆
  2358. '71',
  2359. // 台湾
  2360. '81',
  2361. // 香港
  2362. '82',
  2363. // 澳门
  2364. '91' // 国外
  2365. ];
  2366. var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
  2367. var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
  2368. var checkAddressCode = function checkAddressCode(addressCode) {
  2369. return includes$2(provincesAndCities, addressCode);
  2370. };
  2371. var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
  2372. var yyyy = parseInt(birDayCode.substring(0, 4), 10);
  2373. var mm = parseInt(birDayCode.substring(4, 6), 10);
  2374. var dd = parseInt(birDayCode.substring(6), 10);
  2375. var xdata = new Date(yyyy, mm - 1, dd);
  2376. if (xdata > new Date()) {
  2377. return false;
  2378. // eslint-disable-next-line max-len
  2379. } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
  2380. return true;
  2381. }
  2382. return false;
  2383. };
  2384. var getParityBit = function getParityBit(idCardNo) {
  2385. var id17 = idCardNo.substring(0, 17);
  2386. var power = 0;
  2387. for (var i = 0; i < 17; i++) {
  2388. power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
  2389. }
  2390. var mod = power % 11;
  2391. return parityBit[mod];
  2392. };
  2393. var checkParityBit = function checkParityBit(idCardNo) {
  2394. return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
  2395. };
  2396. var check15IdCardNo = function check15IdCardNo(idCardNo) {
  2397. 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);
  2398. if (!check) return false;
  2399. var addressCode = idCardNo.substring(0, 2);
  2400. check = checkAddressCode(addressCode);
  2401. if (!check) return false;
  2402. var birDayCode = "19".concat(idCardNo.substring(6, 12));
  2403. check = checkBirthDayCode(birDayCode);
  2404. if (!check) return false;
  2405. return true;
  2406. };
  2407. var check18IdCardNo = function check18IdCardNo(idCardNo) {
  2408. 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);
  2409. if (!check) return false;
  2410. var addressCode = idCardNo.substring(0, 2);
  2411. check = checkAddressCode(addressCode);
  2412. if (!check) return false;
  2413. var birDayCode = idCardNo.substring(6, 14);
  2414. check = checkBirthDayCode(birDayCode);
  2415. if (!check) return false;
  2416. return checkParityBit(idCardNo);
  2417. };
  2418. var checkIdCardNo = function checkIdCardNo(idCardNo) {
  2419. var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
  2420. if (!check) return false;
  2421. if (idCardNo.length === 15) {
  2422. return check15IdCardNo(idCardNo);
  2423. }
  2424. return check18IdCardNo(idCardNo);
  2425. };
  2426. return checkIdCardNo(str);
  2427. },
  2428. 'zh-HK': function zhHK(str) {
  2429. // sanitize user input
  2430. str = str.trim();
  2431. // HKID number starts with 1 or 2 letters, followed by 6 digits,
  2432. // then a checksum contained in square / round brackets or nothing
  2433. var regexHKID = /^[A-Z]{1,2}[0-9]{6}((\([0-9A]\))|(\[[0-9A]\])|([0-9A]))$/;
  2434. var regexIsDigit = /^[0-9]$/;
  2435. // convert the user input to all uppercase and apply regex
  2436. str = str.toUpperCase();
  2437. if (!regexHKID.test(str)) return false;
  2438. str = str.replace(/\[|\]|\(|\)/g, '');
  2439. if (str.length === 8) str = "3".concat(str);
  2440. var checkSumVal = 0;
  2441. for (var i = 0; i <= 7; i++) {
  2442. var convertedChar = void 0;
  2443. if (!regexIsDigit.test(str[i])) convertedChar = (str[i].charCodeAt(0) - 55) % 11;else convertedChar = str[i];
  2444. checkSumVal += convertedChar * (9 - i);
  2445. }
  2446. checkSumVal %= 11;
  2447. var checkSumConverted;
  2448. if (checkSumVal === 0) checkSumConverted = '0';else if (checkSumVal === 1) checkSumConverted = 'A';else checkSumConverted = String(11 - checkSumVal);
  2449. if (checkSumConverted === str[str.length - 1]) return true;
  2450. return false;
  2451. },
  2452. 'zh-TW': function zhTW(str) {
  2453. var ALPHABET_CODES = {
  2454. A: 10,
  2455. B: 11,
  2456. C: 12,
  2457. D: 13,
  2458. E: 14,
  2459. F: 15,
  2460. G: 16,
  2461. H: 17,
  2462. I: 34,
  2463. J: 18,
  2464. K: 19,
  2465. L: 20,
  2466. M: 21,
  2467. N: 22,
  2468. O: 35,
  2469. P: 23,
  2470. Q: 24,
  2471. R: 25,
  2472. S: 26,
  2473. T: 27,
  2474. U: 28,
  2475. V: 29,
  2476. W: 32,
  2477. X: 30,
  2478. Y: 31,
  2479. Z: 33
  2480. };
  2481. var sanitized = str.trim().toUpperCase();
  2482. if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
  2483. return Array.from(sanitized).reduce(function (sum, number, index) {
  2484. if (index === 0) {
  2485. var code = ALPHABET_CODES[number];
  2486. return code % 10 * 9 + Math.floor(code / 10);
  2487. }
  2488. if (index === 9) {
  2489. return (10 - sum % 10 - Number(number)) % 10 === 0;
  2490. }
  2491. return sum + Number(number) * (9 - index);
  2492. }, 0);
  2493. },
  2494. PK: function PK(str) {
  2495. // Pakistani National Identity Number CNIC is 13 digits
  2496. var CNIC = /^[1-7][0-9]{4}-[0-9]{7}-[1-9]$/;
  2497. // sanitize user input
  2498. var sanitized = str.trim();
  2499. // validate the data structure
  2500. return CNIC.test(sanitized);
  2501. }
  2502. };
  2503. function isIdentityCard(str, locale) {
  2504. assertString(str);
  2505. if (locale in validators) {
  2506. return validators[locale](str);
  2507. } else if (locale === 'any') {
  2508. for (var key in validators) {
  2509. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  2510. // istanbul ignore else
  2511. if (validators.hasOwnProperty(key)) {
  2512. var validator = validators[key];
  2513. if (validator(str)) {
  2514. return true;
  2515. }
  2516. }
  2517. }
  2518. return false;
  2519. }
  2520. throw new Error("Invalid locale '".concat(locale, "'"));
  2521. }
  2522. /**
  2523. * The most commonly used EAN standard is
  2524. * the thirteen-digit EAN-13, while the
  2525. * less commonly used 8-digit EAN-8 barcode was
  2526. * introduced for use on small packages.
  2527. * Also EAN/UCC-14 is used for Grouping of individual
  2528. * trade items above unit level(Intermediate, Carton or Pallet).
  2529. * For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
  2530. * EAN consists of:
  2531. * GS1 prefix, manufacturer code, product code and check digit
  2532. * Reference: https://en.wikipedia.org/wiki/International_Article_Number
  2533. * Reference: https://www.gtin.info/
  2534. */
  2535. /**
  2536. * Define EAN Lengths; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
  2537. * and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
  2538. * with exact numeric matching of 8 or 13 or 14 digits [0-9]
  2539. */
  2540. var LENGTH_EAN_8 = 8;
  2541. var LENGTH_EAN_14 = 14;
  2542. var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
  2543. /**
  2544. * Get position weight given:
  2545. * EAN length and digit index/position
  2546. *
  2547. * @param {number} length
  2548. * @param {number} index
  2549. * @return {number}
  2550. */
  2551. function getPositionWeightThroughLengthAndIndex(length, index) {
  2552. if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
  2553. return index % 2 === 0 ? 3 : 1;
  2554. }
  2555. return index % 2 === 0 ? 1 : 3;
  2556. }
  2557. /**
  2558. * Calculate EAN Check Digit
  2559. * Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
  2560. *
  2561. * @param {string} ean
  2562. * @return {number}
  2563. */
  2564. function calculateCheckDigit(ean) {
  2565. var checksum = ean.slice(0, -1).split('').map(function (_char, index) {
  2566. return Number(_char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
  2567. }).reduce(function (acc, partialSum) {
  2568. return acc + partialSum;
  2569. }, 0);
  2570. var remainder = 10 - checksum % 10;
  2571. return remainder < 10 ? remainder : 0;
  2572. }
  2573. /**
  2574. * Check if string is valid EAN:
  2575. * Matches EAN-8/EAN-13/EAN-14 regex
  2576. * Has valid check digit.
  2577. *
  2578. * @param {string} str
  2579. * @return {boolean}
  2580. */
  2581. function isEAN(str) {
  2582. assertString(str);
  2583. var actualCheckDigit = Number(str.slice(-1));
  2584. return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
  2585. }
  2586. var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;
  2587. // this link details how the check digit is calculated:
  2588. // https://www.isin.org/isin-format/. it is a little bit
  2589. // odd in that it works with digits, not numbers. in order
  2590. // to make only one pass through the ISIN characters, the
  2591. // each alpha character is handled as 2 characters within
  2592. // the loop.
  2593. function isISIN(str) {
  2594. assertString(str);
  2595. if (!isin.test(str)) {
  2596. return false;
  2597. }
  2598. var _double = true;
  2599. var sum = 0;
  2600. // convert values
  2601. for (var i = str.length - 2; i >= 0; i--) {
  2602. if (str[i] >= 'A' && str[i] <= 'Z') {
  2603. var value = str[i].charCodeAt(0) - 55;
  2604. var lo = value % 10;
  2605. var hi = Math.trunc(value / 10);
  2606. // letters have two digits, so handle the low order
  2607. // and high order digits separately.
  2608. for (var _i = 0, _arr = [lo, hi]; _i < _arr.length; _i++) {
  2609. var digit = _arr[_i];
  2610. if (_double) {
  2611. if (digit >= 5) {
  2612. sum += 1 + (digit - 5) * 2;
  2613. } else {
  2614. sum += digit * 2;
  2615. }
  2616. } else {
  2617. sum += digit;
  2618. }
  2619. _double = !_double;
  2620. }
  2621. } else {
  2622. var _digit = str[i].charCodeAt(0) - '0'.charCodeAt(0);
  2623. if (_double) {
  2624. if (_digit >= 5) {
  2625. sum += 1 + (_digit - 5) * 2;
  2626. } else {
  2627. sum += _digit * 2;
  2628. }
  2629. } else {
  2630. sum += _digit;
  2631. }
  2632. _double = !_double;
  2633. }
  2634. }
  2635. var check = Math.trunc((sum + 9) / 10) * 10 - sum;
  2636. return +str[str.length - 1] === check;
  2637. }
  2638. var possibleIsbn10 = /^(?:[0-9]{9}X|[0-9]{10})$/;
  2639. var possibleIsbn13 = /^(?:[0-9]{13})$/;
  2640. var factor = [1, 3];
  2641. function isISBN(isbn, options) {
  2642. assertString(isbn);
  2643. // For backwards compatibility:
  2644. // isISBN(str [, version]), i.e. `options` could be used as argument for the legacy `version`
  2645. var version = String((options === null || options === void 0 ? void 0 : options.version) || options);
  2646. if (!(options !== null && options !== void 0 && options.version || options)) {
  2647. return isISBN(isbn, {
  2648. version: 10
  2649. }) || isISBN(isbn, {
  2650. version: 13
  2651. });
  2652. }
  2653. var sanitizedIsbn = isbn.replace(/[\s-]+/g, '');
  2654. var checksum = 0;
  2655. if (version === '10') {
  2656. if (!possibleIsbn10.test(sanitizedIsbn)) {
  2657. return false;
  2658. }
  2659. for (var i = 0; i < version - 1; i++) {
  2660. checksum += (i + 1) * sanitizedIsbn.charAt(i);
  2661. }
  2662. if (sanitizedIsbn.charAt(9) === 'X') {
  2663. checksum += 10 * 10;
  2664. } else {
  2665. checksum += 10 * sanitizedIsbn.charAt(9);
  2666. }
  2667. if (checksum % 11 === 0) {
  2668. return true;
  2669. }
  2670. } else if (version === '13') {
  2671. if (!possibleIsbn13.test(sanitizedIsbn)) {
  2672. return false;
  2673. }
  2674. for (var _i = 0; _i < 12; _i++) {
  2675. checksum += factor[_i % 2] * sanitizedIsbn.charAt(_i);
  2676. }
  2677. if (sanitizedIsbn.charAt(12) - (10 - checksum % 10) % 10 === 0) {
  2678. return true;
  2679. }
  2680. }
  2681. return false;
  2682. }
  2683. var issn = '^\\d{4}-?\\d{3}[\\dX]$';
  2684. function isISSN(str) {
  2685. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2686. assertString(str);
  2687. var testIssn = issn;
  2688. testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn;
  2689. testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i');
  2690. if (!testIssn.test(str)) {
  2691. return false;
  2692. }
  2693. var digits = str.replace('-', '').toUpperCase();
  2694. var checksum = 0;
  2695. for (var i = 0; i < digits.length; i++) {
  2696. var digit = digits[i];
  2697. checksum += (digit === 'X' ? 10 : +digit) * (8 - i);
  2698. }
  2699. return checksum % 11 === 0;
  2700. }
  2701. /**
  2702. * Algorithmic validation functions
  2703. * May be used as is or implemented in the workflow of other validators.
  2704. */
  2705. /*
  2706. * ISO 7064 validation function
  2707. * Called with a string of numbers (incl. check digit)
  2708. * to validate according to ISO 7064 (MOD 11, 10).
  2709. */
  2710. function iso7064Check(str) {
  2711. var checkvalue = 10;
  2712. for (var i = 0; i < str.length - 1; i++) {
  2713. checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11;
  2714. }
  2715. checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue;
  2716. return checkvalue === parseInt(str[10], 10);
  2717. }
  2718. /*
  2719. * Luhn (mod 10) validation function
  2720. * Called with a string of numbers (incl. check digit)
  2721. * to validate according to the Luhn algorithm.
  2722. */
  2723. function luhnCheck(str) {
  2724. var checksum = 0;
  2725. var second = false;
  2726. for (var i = str.length - 1; i >= 0; i--) {
  2727. if (second) {
  2728. var product = parseInt(str[i], 10) * 2;
  2729. if (product > 9) {
  2730. // sum digits of product and add to checksum
  2731. checksum += product.toString().split('').map(function (a) {
  2732. return parseInt(a, 10);
  2733. }).reduce(function (a, b) {
  2734. return a + b;
  2735. }, 0);
  2736. } else {
  2737. checksum += product;
  2738. }
  2739. } else {
  2740. checksum += parseInt(str[i], 10);
  2741. }
  2742. second = !second;
  2743. }
  2744. return checksum % 10 === 0;
  2745. }
  2746. /*
  2747. * Reverse TIN multiplication and summation helper function
  2748. * Called with an array of single-digit integers and a base multiplier
  2749. * to calculate the sum of the digits multiplied in reverse.
  2750. * Normally used in variations of MOD 11 algorithmic checks.
  2751. */
  2752. function reverseMultiplyAndSum(digits, base) {
  2753. var total = 0;
  2754. for (var i = 0; i < digits.length; i++) {
  2755. total += digits[i] * (base - i);
  2756. }
  2757. return total;
  2758. }
  2759. /*
  2760. * Verhoeff validation helper function
  2761. * Called with a string of numbers
  2762. * to validate according to the Verhoeff algorithm.
  2763. */
  2764. function verhoeffCheck(str) {
  2765. 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]];
  2766. 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]];
  2767. // Copy (to prevent replacement) and reverse
  2768. var str_copy = str.split('').reverse().join('');
  2769. var checksum = 0;
  2770. for (var i = 0; i < str_copy.length; i++) {
  2771. checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]];
  2772. }
  2773. return checksum === 0;
  2774. }
  2775. /**
  2776. * TIN Validation
  2777. * Validates Tax Identification Numbers (TINs) from the US, EU member states and the United Kingdom.
  2778. *
  2779. * EU-UK:
  2780. * National TIN validity is calculated using public algorithms as made available by DG TAXUD.
  2781. *
  2782. * See `https://ec.europa.eu/taxation_customs/tin/specs/FS-TIN%20Algorithms-Public.docx` for more information.
  2783. *
  2784. * US:
  2785. * An Employer Identification Number (EIN), also known as a Federal Tax Identification Number,
  2786. * is used to identify a business entity.
  2787. *
  2788. * NOTES:
  2789. * - Prefix 47 is being reserved for future use
  2790. * - Prefixes 26, 27, 45, 46 and 47 were previously assigned by the Philadelphia campus.
  2791. *
  2792. * See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes`
  2793. * for more information.
  2794. */
  2795. // Locale functions
  2796. /*
  2797. * bg-BG validation function
  2798. * (Edinen graždanski nomer (EGN/ЕГН), persons only)
  2799. * Checks if birth date (first six digits) is valid and calculates check (last) digit
  2800. */
  2801. function bgBgCheck(tin) {
  2802. // Extract full year, normalize month and check birth date validity
  2803. var century_year = tin.slice(0, 2);
  2804. var month = parseInt(tin.slice(2, 4), 10);
  2805. if (month > 40) {
  2806. month -= 40;
  2807. century_year = "20".concat(century_year);
  2808. } else if (month > 20) {
  2809. month -= 20;
  2810. century_year = "18".concat(century_year);
  2811. } else {
  2812. century_year = "19".concat(century_year);
  2813. }
  2814. if (month < 10) {
  2815. month = "0".concat(month);
  2816. }
  2817. var date = "".concat(century_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2818. if (!isDate(date, 'YYYY/MM/DD')) {
  2819. return false;
  2820. }
  2821. // split digits into an array for further processing
  2822. var digits = tin.split('').map(function (a) {
  2823. return parseInt(a, 10);
  2824. });
  2825. // Calculate checksum by multiplying digits with fixed values
  2826. var multip_lookup = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2827. var checksum = 0;
  2828. for (var i = 0; i < multip_lookup.length; i++) {
  2829. checksum += digits[i] * multip_lookup[i];
  2830. }
  2831. checksum = checksum % 11 === 10 ? 0 : checksum % 11;
  2832. return checksum === digits[9];
  2833. }
  2834. /**
  2835. * Check if an input is a valid Canadian SIN (Social Insurance Number)
  2836. *
  2837. * The Social Insurance Number (SIN) is a 9 digit number that
  2838. * you need to work in Canada or to have access to government programs and benefits.
  2839. *
  2840. * https://en.wikipedia.org/wiki/Social_Insurance_Number
  2841. * https://www.canada.ca/en/employment-social-development/services/sin.html
  2842. * https://www.codercrunch.com/challenge/819302488/sin-validator
  2843. *
  2844. * @param {string} input
  2845. * @return {boolean}
  2846. */
  2847. function isCanadianSIN(input) {
  2848. var digitsArray = input.split('');
  2849. var even = digitsArray.filter(function (_, idx) {
  2850. return idx % 2;
  2851. }).map(function (i) {
  2852. return Number(i) * 2;
  2853. }).join('').split('');
  2854. var total = digitsArray.filter(function (_, idx) {
  2855. return !(idx % 2);
  2856. }).concat(even).map(function (i) {
  2857. return Number(i);
  2858. }).reduce(function (acc, cur) {
  2859. return acc + cur;
  2860. });
  2861. return total % 10 === 0;
  2862. }
  2863. /*
  2864. * cs-CZ validation function
  2865. * (Rodné číslo (RČ), persons only)
  2866. * Checks if birth date (first six digits) is valid and divisibility by 11
  2867. * Material not in DG TAXUD document sourced from:
  2868. * -`https://lorenc.info/3MA381/overeni-spravnosti-rodneho-cisla.htm`
  2869. * -`https://www.mvcr.cz/clanek/rady-a-sluzby-dokumenty-rodne-cislo.aspx`
  2870. */
  2871. function csCzCheck(tin) {
  2872. tin = tin.replace(/\W/, '');
  2873. // Extract full year from TIN length
  2874. var full_year = parseInt(tin.slice(0, 2), 10);
  2875. if (tin.length === 10) {
  2876. if (full_year < 54) {
  2877. full_year = "20".concat(full_year);
  2878. } else {
  2879. full_year = "19".concat(full_year);
  2880. }
  2881. } else {
  2882. if (tin.slice(6) === '000') {
  2883. return false;
  2884. } // Three-zero serial not assigned before 1954
  2885. if (full_year < 54) {
  2886. full_year = "19".concat(full_year);
  2887. } else {
  2888. return false; // No 18XX years seen in any of the resources
  2889. }
  2890. }
  2891. // Add missing zero if needed
  2892. if (full_year.length === 3) {
  2893. full_year = [full_year.slice(0, 2), '0', full_year.slice(2)].join('');
  2894. }
  2895. // Extract month from TIN and normalize
  2896. var month = parseInt(tin.slice(2, 4), 10);
  2897. if (month > 50) {
  2898. month -= 50;
  2899. }
  2900. if (month > 20) {
  2901. // Month-plus-twenty was only introduced in 2004
  2902. if (parseInt(full_year, 10) < 2004) {
  2903. return false;
  2904. }
  2905. month -= 20;
  2906. }
  2907. if (month < 10) {
  2908. month = "0".concat(month);
  2909. }
  2910. // Check date validity
  2911. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  2912. if (!isDate(date, 'YYYY/MM/DD')) {
  2913. return false;
  2914. }
  2915. // Verify divisibility by 11
  2916. if (tin.length === 10) {
  2917. if (parseInt(tin, 10) % 11 !== 0) {
  2918. // Some numbers up to and including 1985 are still valid if
  2919. // check (last) digit equals 0 and modulo of first 9 digits equals 10
  2920. var checkdigit = parseInt(tin.slice(0, 9), 10) % 11;
  2921. if (parseInt(full_year, 10) < 1986 && checkdigit === 10) {
  2922. if (parseInt(tin.slice(9), 10) !== 0) {
  2923. return false;
  2924. }
  2925. } else {
  2926. return false;
  2927. }
  2928. }
  2929. }
  2930. return true;
  2931. }
  2932. /*
  2933. * de-AT validation function
  2934. * (Abgabenkontonummer, persons/entities)
  2935. * Verify TIN validity by calling luhnCheck()
  2936. */
  2937. function deAtCheck(tin) {
  2938. return luhnCheck(tin);
  2939. }
  2940. /*
  2941. * de-DE validation function
  2942. * (Steueridentifikationsnummer (Steuer-IdNr.), persons only)
  2943. * Tests for single duplicate/triplicate value, then calculates ISO 7064 check (last) digit
  2944. * Partial implementation of spec (same result with both algorithms always)
  2945. */
  2946. function deDeCheck(tin) {
  2947. // Split digits into an array for further processing
  2948. var digits = tin.split('').map(function (a) {
  2949. return parseInt(a, 10);
  2950. });
  2951. // Fill array with strings of number positions
  2952. var occurrences = [];
  2953. for (var i = 0; i < digits.length - 1; i++) {
  2954. occurrences.push('');
  2955. for (var j = 0; j < digits.length - 1; j++) {
  2956. if (digits[i] === digits[j]) {
  2957. occurrences[i] += j;
  2958. }
  2959. }
  2960. }
  2961. // Remove digits with one occurrence and test for only one duplicate/triplicate
  2962. occurrences = occurrences.filter(function (a) {
  2963. return a.length > 1;
  2964. });
  2965. if (occurrences.length !== 2 && occurrences.length !== 3) {
  2966. return false;
  2967. }
  2968. // In case of triplicate value only two digits are allowed next to each other
  2969. if (occurrences[0].length === 3) {
  2970. var trip_locations = occurrences[0].split('').map(function (a) {
  2971. return parseInt(a, 10);
  2972. });
  2973. var recurrent = 0; // Amount of neighbor occurrences
  2974. for (var _i = 0; _i < trip_locations.length - 1; _i++) {
  2975. if (trip_locations[_i] + 1 === trip_locations[_i + 1]) {
  2976. recurrent += 1;
  2977. }
  2978. }
  2979. if (recurrent === 2) {
  2980. return false;
  2981. }
  2982. }
  2983. return iso7064Check(tin);
  2984. }
  2985. /*
  2986. * dk-DK validation function
  2987. * (CPR-nummer (personnummer), persons only)
  2988. * Checks if birth date (first six digits) is valid and assigned to century (seventh) digit,
  2989. * and calculates check (last) digit
  2990. */
  2991. function dkDkCheck(tin) {
  2992. tin = tin.replace(/\W/, '');
  2993. // Extract year, check if valid for given century digit and add century
  2994. var year = parseInt(tin.slice(4, 6), 10);
  2995. var century_digit = tin.slice(6, 7);
  2996. switch (century_digit) {
  2997. case '0':
  2998. case '1':
  2999. case '2':
  3000. case '3':
  3001. year = "19".concat(year);
  3002. break;
  3003. case '4':
  3004. case '9':
  3005. if (year < 37) {
  3006. year = "20".concat(year);
  3007. } else {
  3008. year = "19".concat(year);
  3009. }
  3010. break;
  3011. default:
  3012. if (year < 37) {
  3013. year = "20".concat(year);
  3014. } else if (year > 58) {
  3015. year = "18".concat(year);
  3016. } else {
  3017. return false;
  3018. }
  3019. break;
  3020. }
  3021. // Add missing zero if needed
  3022. if (year.length === 3) {
  3023. year = [year.slice(0, 2), '0', year.slice(2)].join('');
  3024. }
  3025. // Check date validity
  3026. var date = "".concat(year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  3027. if (!isDate(date, 'YYYY/MM/DD')) {
  3028. return false;
  3029. }
  3030. // Split digits into an array for further processing
  3031. var digits = tin.split('').map(function (a) {
  3032. return parseInt(a, 10);
  3033. });
  3034. var checksum = 0;
  3035. var weight = 4;
  3036. // Multiply by weight and add to checksum
  3037. for (var i = 0; i < 9; i++) {
  3038. checksum += digits[i] * weight;
  3039. weight -= 1;
  3040. if (weight === 1) {
  3041. weight = 7;
  3042. }
  3043. }
  3044. checksum %= 11;
  3045. if (checksum === 1) {
  3046. return false;
  3047. }
  3048. return checksum === 0 ? digits[9] === 0 : digits[9] === 11 - checksum;
  3049. }
  3050. /*
  3051. * el-CY validation function
  3052. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons only)
  3053. * Verify TIN validity by calculating ASCII value of check (last) character
  3054. */
  3055. function elCyCheck(tin) {
  3056. // split digits into an array for further processing
  3057. var digits = tin.slice(0, 8).split('').map(function (a) {
  3058. return parseInt(a, 10);
  3059. });
  3060. var checksum = 0;
  3061. // add digits in even places
  3062. for (var i = 1; i < digits.length; i += 2) {
  3063. checksum += digits[i];
  3064. }
  3065. // add digits in odd places
  3066. for (var _i2 = 0; _i2 < digits.length; _i2 += 2) {
  3067. if (digits[_i2] < 2) {
  3068. checksum += 1 - digits[_i2];
  3069. } else {
  3070. checksum += 2 * (digits[_i2] - 2) + 5;
  3071. if (digits[_i2] > 4) {
  3072. checksum += 2;
  3073. }
  3074. }
  3075. }
  3076. return String.fromCharCode(checksum % 26 + 65) === tin.charAt(8);
  3077. }
  3078. /*
  3079. * el-GR validation function
  3080. * (Arithmos Forologikou Mitroou (AFM/ΑΦΜ), persons/entities)
  3081. * Verify TIN validity by calculating check (last) digit
  3082. * Algorithm not in DG TAXUD document- sourced from:
  3083. * - `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`
  3084. */
  3085. function elGrCheck(tin) {
  3086. // split digits into an array for further processing
  3087. var digits = tin.split('').map(function (a) {
  3088. return parseInt(a, 10);
  3089. });
  3090. var checksum = 0;
  3091. for (var i = 0; i < 8; i++) {
  3092. checksum += digits[i] * Math.pow(2, 8 - i);
  3093. }
  3094. return checksum % 11 % 10 === digits[8];
  3095. }
  3096. /*
  3097. * en-GB validation function (should go here if needed)
  3098. * (National Insurance Number (NINO) or Unique Taxpayer Reference (UTR),
  3099. * persons/entities respectively)
  3100. */
  3101. /*
  3102. * en-IE validation function
  3103. * (Personal Public Service Number (PPS No), persons only)
  3104. * Verify TIN validity by calculating check (second to last) character
  3105. */
  3106. function enIeCheck(tin) {
  3107. var checksum = reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  3108. return parseInt(a, 10);
  3109. }), 8);
  3110. if (tin.length === 9 && tin[8] !== 'W') {
  3111. checksum += (tin[8].charCodeAt(0) - 64) * 9;
  3112. }
  3113. checksum %= 23;
  3114. if (checksum === 0) {
  3115. return tin[7].toUpperCase() === 'W';
  3116. }
  3117. return tin[7].toUpperCase() === String.fromCharCode(64 + checksum);
  3118. }
  3119. // Valid US IRS campus prefixes
  3120. var enUsCampusPrefix = {
  3121. andover: ['10', '12'],
  3122. atlanta: ['60', '67'],
  3123. austin: ['50', '53'],
  3124. 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'],
  3125. cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
  3126. fresno: ['15', '24'],
  3127. internet: ['20', '26', '27', '45', '46', '47'],
  3128. kansas: ['40', '44'],
  3129. memphis: ['94', '95'],
  3130. ogden: ['80', '90'],
  3131. 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'],
  3132. sba: ['31']
  3133. };
  3134. // Return an array of all US IRS campus prefixes
  3135. function enUsGetPrefixes() {
  3136. var prefixes = [];
  3137. for (var location in enUsCampusPrefix) {
  3138. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  3139. // istanbul ignore else
  3140. if (enUsCampusPrefix.hasOwnProperty(location)) {
  3141. prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location]));
  3142. }
  3143. }
  3144. return prefixes;
  3145. }
  3146. /*
  3147. * en-US validation function
  3148. * Verify that the TIN starts with a valid IRS campus prefix
  3149. */
  3150. function enUsCheck(tin) {
  3151. return enUsGetPrefixes().indexOf(tin.slice(0, 2)) !== -1;
  3152. }
  3153. /*
  3154. * es-AR validation function
  3155. * Clave Única de Identificación Tributaria (CUIT/CUIL)
  3156. * Sourced from:
  3157. * - https://servicioscf.afip.gob.ar/publico/abc/ABCpaso2.aspx?id_nivel1=3036&id_nivel2=3040&p=Conceptos%20b%C3%A1sicos
  3158. * - https://es.wikipedia.org/wiki/Clave_%C3%9Anica_de_Identificaci%C3%B3n_Tributaria
  3159. */
  3160. function esArCheck(tin) {
  3161. var accum = 0;
  3162. var digits = tin.split('');
  3163. var digit = parseInt(digits.pop(), 10);
  3164. for (var i = 0; i < digits.length; i++) {
  3165. accum += digits[9 - i] * (2 + i % 6);
  3166. }
  3167. var verif = 11 - accum % 11;
  3168. if (verif === 11) {
  3169. verif = 0;
  3170. } else if (verif === 10) {
  3171. verif = 9;
  3172. }
  3173. return digit === verif;
  3174. }
  3175. /*
  3176. * es-ES validation function
  3177. * (Documento Nacional de Identidad (DNI)
  3178. * or Número de Identificación de Extranjero (NIE), persons only)
  3179. * Verify TIN validity by calculating check (last) character
  3180. */
  3181. function esEsCheck(tin) {
  3182. // Split characters into an array for further processing
  3183. var chars = tin.toUpperCase().split('');
  3184. // Replace initial letter if needed
  3185. if (isNaN(parseInt(chars[0], 10)) && chars.length > 1) {
  3186. var lead_replace = 0;
  3187. switch (chars[0]) {
  3188. case 'Y':
  3189. lead_replace = 1;
  3190. break;
  3191. case 'Z':
  3192. lead_replace = 2;
  3193. break;
  3194. default:
  3195. }
  3196. chars.splice(0, 1, lead_replace);
  3197. // Fill with zeros if smaller than proper
  3198. } else {
  3199. while (chars.length < 9) {
  3200. chars.unshift(0);
  3201. }
  3202. }
  3203. // Calculate checksum and check according to lookup
  3204. 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'];
  3205. chars = chars.join('');
  3206. var checksum = parseInt(chars.slice(0, 8), 10) % 23;
  3207. return chars[8] === lookup[checksum];
  3208. }
  3209. /*
  3210. * et-EE validation function
  3211. * (Isikukood (IK), persons only)
  3212. * Checks if birth date (century digit and six following) is valid and calculates check (last) digit
  3213. * Material not in DG TAXUD document sourced from:
  3214. * - `https://www.oecd.org/tax/automatic-exchange/crs-implementation-and-assistance/tax-identification-numbers/Estonia-TIN.pdf`
  3215. */
  3216. function etEeCheck(tin) {
  3217. // Extract year and add century
  3218. var full_year = tin.slice(1, 3);
  3219. var century_digit = tin.slice(0, 1);
  3220. switch (century_digit) {
  3221. case '1':
  3222. case '2':
  3223. full_year = "18".concat(full_year);
  3224. break;
  3225. case '3':
  3226. case '4':
  3227. full_year = "19".concat(full_year);
  3228. break;
  3229. default:
  3230. full_year = "20".concat(full_year);
  3231. break;
  3232. }
  3233. // Check date validity
  3234. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  3235. if (!isDate(date, 'YYYY/MM/DD')) {
  3236. return false;
  3237. }
  3238. // Split digits into an array for further processing
  3239. var digits = tin.split('').map(function (a) {
  3240. return parseInt(a, 10);
  3241. });
  3242. var checksum = 0;
  3243. var weight = 1;
  3244. // Multiply by weight and add to checksum
  3245. for (var i = 0; i < 10; i++) {
  3246. checksum += digits[i] * weight;
  3247. weight += 1;
  3248. if (weight === 10) {
  3249. weight = 1;
  3250. }
  3251. }
  3252. // Do again if modulo 11 of checksum is 10
  3253. if (checksum % 11 === 10) {
  3254. checksum = 0;
  3255. weight = 3;
  3256. for (var _i3 = 0; _i3 < 10; _i3++) {
  3257. checksum += digits[_i3] * weight;
  3258. weight += 1;
  3259. if (weight === 10) {
  3260. weight = 1;
  3261. }
  3262. }
  3263. if (checksum % 11 === 10) {
  3264. return digits[10] === 0;
  3265. }
  3266. }
  3267. return checksum % 11 === digits[10];
  3268. }
  3269. /*
  3270. * fi-FI validation function
  3271. * (Henkilötunnus (HETU), persons only)
  3272. * Checks if birth date (first six digits plus century symbol) is valid
  3273. * and calculates check (last) digit
  3274. */
  3275. function fiFiCheck(tin) {
  3276. // Extract year and add century
  3277. var full_year = tin.slice(4, 6);
  3278. var century_symbol = tin.slice(6, 7);
  3279. switch (century_symbol) {
  3280. case '+':
  3281. full_year = "18".concat(full_year);
  3282. break;
  3283. case '-':
  3284. full_year = "19".concat(full_year);
  3285. break;
  3286. default:
  3287. full_year = "20".concat(full_year);
  3288. break;
  3289. }
  3290. // Check date validity
  3291. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(tin.slice(0, 2));
  3292. if (!isDate(date, 'YYYY/MM/DD')) {
  3293. return false;
  3294. }
  3295. // Calculate check character
  3296. var checksum = parseInt(tin.slice(0, 6) + tin.slice(7, 10), 10) % 31;
  3297. if (checksum < 10) {
  3298. return checksum === parseInt(tin.slice(10), 10);
  3299. }
  3300. checksum -= 10;
  3301. var letters_lookup = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'];
  3302. return letters_lookup[checksum] === tin.slice(10);
  3303. }
  3304. /*
  3305. * fr/nl-BE validation function
  3306. * (Numéro national (N.N.), persons only)
  3307. * Checks if birth date (first six digits) is valid and calculates check (last two) digits
  3308. */
  3309. function frBeCheck(tin) {
  3310. // Zero month/day value is acceptable
  3311. if (tin.slice(2, 4) !== '00' || tin.slice(4, 6) !== '00') {
  3312. // Extract date from first six digits of TIN
  3313. var date = "".concat(tin.slice(0, 2), "/").concat(tin.slice(2, 4), "/").concat(tin.slice(4, 6));
  3314. if (!isDate(date, 'YY/MM/DD')) {
  3315. return false;
  3316. }
  3317. }
  3318. var checksum = 97 - parseInt(tin.slice(0, 9), 10) % 97;
  3319. var checkdigits = parseInt(tin.slice(9, 11), 10);
  3320. if (checksum !== checkdigits) {
  3321. checksum = 97 - parseInt("2".concat(tin.slice(0, 9)), 10) % 97;
  3322. if (checksum !== checkdigits) {
  3323. return false;
  3324. }
  3325. }
  3326. return true;
  3327. }
  3328. /*
  3329. * fr-FR validation function
  3330. * (Numéro fiscal de référence (numéro SPI), persons only)
  3331. * Verify TIN validity by calculating check (last three) digits
  3332. */
  3333. function frFrCheck(tin) {
  3334. tin = tin.replace(/\s/g, '');
  3335. var checksum = parseInt(tin.slice(0, 10), 10) % 511;
  3336. var checkdigits = parseInt(tin.slice(10, 13), 10);
  3337. return checksum === checkdigits;
  3338. }
  3339. /*
  3340. * fr/lb-LU validation function
  3341. * (numéro d’identification personnelle, persons only)
  3342. * Verify birth date validity and run Luhn and Verhoeff checks
  3343. */
  3344. function frLuCheck(tin) {
  3345. // Extract date and check validity
  3346. var date = "".concat(tin.slice(0, 4), "/").concat(tin.slice(4, 6), "/").concat(tin.slice(6, 8));
  3347. if (!isDate(date, 'YYYY/MM/DD')) {
  3348. return false;
  3349. }
  3350. // Run Luhn check
  3351. if (!luhnCheck(tin.slice(0, 12))) {
  3352. return false;
  3353. }
  3354. // Remove Luhn check digit and run Verhoeff check
  3355. return verhoeffCheck("".concat(tin.slice(0, 11)).concat(tin[12]));
  3356. }
  3357. /*
  3358. * hr-HR validation function
  3359. * (Osobni identifikacijski broj (OIB), persons/entities)
  3360. * Verify TIN validity by calling iso7064Check(digits)
  3361. */
  3362. function hrHrCheck(tin) {
  3363. return iso7064Check(tin);
  3364. }
  3365. /*
  3366. * hu-HU validation function
  3367. * (Adóazonosító jel, persons only)
  3368. * Verify TIN validity by calculating check (last) digit
  3369. */
  3370. function huHuCheck(tin) {
  3371. // split digits into an array for further processing
  3372. var digits = tin.split('').map(function (a) {
  3373. return parseInt(a, 10);
  3374. });
  3375. var checksum = 8;
  3376. for (var i = 1; i < 9; i++) {
  3377. checksum += digits[i] * (i + 1);
  3378. }
  3379. return checksum % 11 === digits[9];
  3380. }
  3381. /*
  3382. * lt-LT validation function (should go here if needed)
  3383. * (Asmens kodas, persons/entities respectively)
  3384. * Current validation check is alias of etEeCheck- same format applies
  3385. */
  3386. /*
  3387. * it-IT first/last name validity check
  3388. * Accepts it-IT TIN-encoded names as a three-element character array and checks their validity
  3389. * Due to lack of clarity between resources ("Are only Italian consonants used?
  3390. * What happens if a person has X in their name?" etc.) only two test conditions
  3391. * have been implemented:
  3392. * Vowels may only be followed by other vowels or an X character
  3393. * and X characters after vowels may only be followed by other X characters.
  3394. */
  3395. function itItNameCheck(name) {
  3396. // true at the first occurrence of a vowel
  3397. var vowelflag = false;
  3398. // true at the first occurrence of an X AFTER vowel
  3399. // (to properly handle last names with X as consonant)
  3400. var xflag = false;
  3401. for (var i = 0; i < 3; i++) {
  3402. if (!vowelflag && /[AEIOU]/.test(name[i])) {
  3403. vowelflag = true;
  3404. } else if (!xflag && vowelflag && name[i] === 'X') {
  3405. xflag = true;
  3406. } else if (i > 0) {
  3407. if (vowelflag && !xflag) {
  3408. if (!/[AEIOU]/.test(name[i])) {
  3409. return false;
  3410. }
  3411. }
  3412. if (xflag) {
  3413. if (!/X/.test(name[i])) {
  3414. return false;
  3415. }
  3416. }
  3417. }
  3418. }
  3419. return true;
  3420. }
  3421. /*
  3422. * it-IT validation function
  3423. * (Codice fiscale (TIN-IT), persons only)
  3424. * Verify name, birth date and codice catastale validity
  3425. * and calculate check character.
  3426. * Material not in DG-TAXUD document sourced from:
  3427. * `https://en.wikipedia.org/wiki/Italian_fiscal_code`
  3428. */
  3429. function itItCheck(tin) {
  3430. // Capitalize and split characters into an array for further processing
  3431. var chars = tin.toUpperCase().split('');
  3432. // Check first and last name validity calling itItNameCheck()
  3433. if (!itItNameCheck(chars.slice(0, 3))) {
  3434. return false;
  3435. }
  3436. if (!itItNameCheck(chars.slice(3, 6))) {
  3437. return false;
  3438. }
  3439. // Convert letters in number spaces back to numbers if any
  3440. var number_locations = [6, 7, 9, 10, 12, 13, 14];
  3441. var number_replace = {
  3442. L: '0',
  3443. M: '1',
  3444. N: '2',
  3445. P: '3',
  3446. Q: '4',
  3447. R: '5',
  3448. S: '6',
  3449. T: '7',
  3450. U: '8',
  3451. V: '9'
  3452. };
  3453. for (var _i4 = 0, _number_locations = number_locations; _i4 < _number_locations.length; _i4++) {
  3454. var i = _number_locations[_i4];
  3455. if (chars[i] in number_replace) {
  3456. chars.splice(i, 1, number_replace[chars[i]]);
  3457. }
  3458. }
  3459. // Extract month and day, and check date validity
  3460. var month_replace = {
  3461. A: '01',
  3462. B: '02',
  3463. C: '03',
  3464. D: '04',
  3465. E: '05',
  3466. H: '06',
  3467. L: '07',
  3468. M: '08',
  3469. P: '09',
  3470. R: '10',
  3471. S: '11',
  3472. T: '12'
  3473. };
  3474. var month = month_replace[chars[8]];
  3475. var day = parseInt(chars[9] + chars[10], 10);
  3476. if (day > 40) {
  3477. day -= 40;
  3478. }
  3479. if (day < 10) {
  3480. day = "0".concat(day);
  3481. }
  3482. var date = "".concat(chars[6]).concat(chars[7], "/").concat(month, "/").concat(day);
  3483. if (!isDate(date, 'YY/MM/DD')) {
  3484. return false;
  3485. }
  3486. // Calculate check character by adding up even and odd characters as numbers
  3487. var checksum = 0;
  3488. for (var _i5 = 1; _i5 < chars.length - 1; _i5 += 2) {
  3489. var char_to_int = parseInt(chars[_i5], 10);
  3490. if (isNaN(char_to_int)) {
  3491. char_to_int = chars[_i5].charCodeAt(0) - 65;
  3492. }
  3493. checksum += char_to_int;
  3494. }
  3495. var odd_convert = {
  3496. // Maps of characters at odd places
  3497. A: 1,
  3498. B: 0,
  3499. C: 5,
  3500. D: 7,
  3501. E: 9,
  3502. F: 13,
  3503. G: 15,
  3504. H: 17,
  3505. I: 19,
  3506. J: 21,
  3507. K: 2,
  3508. L: 4,
  3509. M: 18,
  3510. N: 20,
  3511. O: 11,
  3512. P: 3,
  3513. Q: 6,
  3514. R: 8,
  3515. S: 12,
  3516. T: 14,
  3517. U: 16,
  3518. V: 10,
  3519. W: 22,
  3520. X: 25,
  3521. Y: 24,
  3522. Z: 23,
  3523. 0: 1,
  3524. 1: 0
  3525. };
  3526. for (var _i6 = 0; _i6 < chars.length - 1; _i6 += 2) {
  3527. var _char_to_int = 0;
  3528. if (chars[_i6] in odd_convert) {
  3529. _char_to_int = odd_convert[chars[_i6]];
  3530. } else {
  3531. var multiplier = parseInt(chars[_i6], 10);
  3532. _char_to_int = 2 * multiplier + 1;
  3533. if (multiplier > 4) {
  3534. _char_to_int += 2;
  3535. }
  3536. }
  3537. checksum += _char_to_int;
  3538. }
  3539. if (String.fromCharCode(65 + checksum % 26) !== chars[15]) {
  3540. return false;
  3541. }
  3542. return true;
  3543. }
  3544. /*
  3545. * lv-LV validation function
  3546. * (Personas kods (PK), persons only)
  3547. * Check validity of birth date and calculate check (last) digit
  3548. * Support only for old format numbers (not starting with '32', issued before 2017/07/01)
  3549. * Material not in DG TAXUD document sourced from:
  3550. * `https://boot.ritakafija.lv/forums/index.php?/topic/88314-personas-koda-algoritms-%C4%8Deksumma/`
  3551. */
  3552. function lvLvCheck(tin) {
  3553. tin = tin.replace(/\W/, '');
  3554. // Extract date from TIN
  3555. var day = tin.slice(0, 2);
  3556. if (day !== '32') {
  3557. // No date/checksum check if new format
  3558. var month = tin.slice(2, 4);
  3559. if (month !== '00') {
  3560. // No date check if unknown month
  3561. var full_year = tin.slice(4, 6);
  3562. switch (tin[6]) {
  3563. case '0':
  3564. full_year = "18".concat(full_year);
  3565. break;
  3566. case '1':
  3567. full_year = "19".concat(full_year);
  3568. break;
  3569. default:
  3570. full_year = "20".concat(full_year);
  3571. break;
  3572. }
  3573. // Check date validity
  3574. var date = "".concat(full_year, "/").concat(tin.slice(2, 4), "/").concat(day);
  3575. if (!isDate(date, 'YYYY/MM/DD')) {
  3576. return false;
  3577. }
  3578. }
  3579. // Calculate check digit
  3580. var checksum = 1101;
  3581. var multip_lookup = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  3582. for (var i = 0; i < tin.length - 1; i++) {
  3583. checksum -= parseInt(tin[i], 10) * multip_lookup[i];
  3584. }
  3585. return parseInt(tin[10], 10) === checksum % 11;
  3586. }
  3587. return true;
  3588. }
  3589. /*
  3590. * mt-MT validation function
  3591. * (Identity Card Number or Unique Taxpayer Reference, persons/entities)
  3592. * Verify Identity Card Number structure (no other tests found)
  3593. */
  3594. function mtMtCheck(tin) {
  3595. if (tin.length !== 9) {
  3596. // No tests for UTR
  3597. var chars = tin.toUpperCase().split('');
  3598. // Fill with zeros if smaller than proper
  3599. while (chars.length < 8) {
  3600. chars.unshift(0);
  3601. }
  3602. // Validate format according to last character
  3603. switch (tin[7]) {
  3604. case 'A':
  3605. case 'P':
  3606. if (parseInt(chars[6], 10) === 0) {
  3607. return false;
  3608. }
  3609. break;
  3610. default:
  3611. {
  3612. var first_part = parseInt(chars.join('').slice(0, 5), 10);
  3613. if (first_part > 32000) {
  3614. return false;
  3615. }
  3616. var second_part = parseInt(chars.join('').slice(5, 7), 10);
  3617. if (first_part === second_part) {
  3618. return false;
  3619. }
  3620. }
  3621. }
  3622. }
  3623. return true;
  3624. }
  3625. /*
  3626. * nl-NL validation function
  3627. * (Burgerservicenummer (BSN) or Rechtspersonen Samenwerkingsverbanden Informatie Nummer (RSIN),
  3628. * persons/entities respectively)
  3629. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3630. */
  3631. function nlNlCheck(tin) {
  3632. return reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  3633. return parseInt(a, 10);
  3634. }), 9) % 11 === parseInt(tin[8], 10);
  3635. }
  3636. /*
  3637. * pl-PL validation function
  3638. * (Powszechny Elektroniczny System Ewidencji Ludności (PESEL)
  3639. * or Numer identyfikacji podatkowej (NIP), persons/entities)
  3640. * Verify TIN validity by validating birth date (PESEL) and calculating check (last) digit
  3641. */
  3642. function plPlCheck(tin) {
  3643. // NIP
  3644. if (tin.length === 10) {
  3645. // Calculate last digit by multiplying with lookup
  3646. var lookup = [6, 5, 7, 2, 3, 4, 5, 6, 7];
  3647. var _checksum = 0;
  3648. for (var i = 0; i < lookup.length; i++) {
  3649. _checksum += parseInt(tin[i], 10) * lookup[i];
  3650. }
  3651. _checksum %= 11;
  3652. if (_checksum === 10) {
  3653. return false;
  3654. }
  3655. return _checksum === parseInt(tin[9], 10);
  3656. }
  3657. // PESEL
  3658. // Extract full year using month
  3659. var full_year = tin.slice(0, 2);
  3660. var month = parseInt(tin.slice(2, 4), 10);
  3661. if (month > 80) {
  3662. full_year = "18".concat(full_year);
  3663. month -= 80;
  3664. } else if (month > 60) {
  3665. full_year = "22".concat(full_year);
  3666. month -= 60;
  3667. } else if (month > 40) {
  3668. full_year = "21".concat(full_year);
  3669. month -= 40;
  3670. } else if (month > 20) {
  3671. full_year = "20".concat(full_year);
  3672. month -= 20;
  3673. } else {
  3674. full_year = "19".concat(full_year);
  3675. }
  3676. // Add leading zero to month if needed
  3677. if (month < 10) {
  3678. month = "0".concat(month);
  3679. }
  3680. // Check date validity
  3681. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  3682. if (!isDate(date, 'YYYY/MM/DD')) {
  3683. return false;
  3684. }
  3685. // Calculate last digit by multiplying with odd one-digit numbers except 5
  3686. var checksum = 0;
  3687. var multiplier = 1;
  3688. for (var _i7 = 0; _i7 < tin.length - 1; _i7++) {
  3689. checksum += parseInt(tin[_i7], 10) * multiplier % 10;
  3690. multiplier += 2;
  3691. if (multiplier > 10) {
  3692. multiplier = 1;
  3693. } else if (multiplier === 5) {
  3694. multiplier += 2;
  3695. }
  3696. }
  3697. checksum = 10 - checksum % 10;
  3698. return checksum === parseInt(tin[10], 10);
  3699. }
  3700. /*
  3701. * pt-BR validation function
  3702. * (Cadastro de Pessoas Físicas (CPF, persons)
  3703. * Cadastro Nacional de Pessoas Jurídicas (CNPJ, entities)
  3704. * Both inputs will be validated
  3705. */
  3706. function ptBrCheck(tin) {
  3707. if (tin.length === 11) {
  3708. var _sum;
  3709. var remainder;
  3710. _sum = 0;
  3711. if (
  3712. // Reject known invalid CPFs
  3713. tin === '11111111111' || tin === '22222222222' || tin === '33333333333' || tin === '44444444444' || tin === '55555555555' || tin === '66666666666' || tin === '77777777777' || tin === '88888888888' || tin === '99999999999' || tin === '00000000000') return false;
  3714. for (var i = 1; i <= 9; i++) _sum += parseInt(tin.substring(i - 1, i), 10) * (11 - i);
  3715. remainder = _sum * 10 % 11;
  3716. if (remainder === 10) remainder = 0;
  3717. if (remainder !== parseInt(tin.substring(9, 10), 10)) return false;
  3718. _sum = 0;
  3719. for (var _i8 = 1; _i8 <= 10; _i8++) _sum += parseInt(tin.substring(_i8 - 1, _i8), 10) * (12 - _i8);
  3720. remainder = _sum * 10 % 11;
  3721. if (remainder === 10) remainder = 0;
  3722. if (remainder !== parseInt(tin.substring(10, 11), 10)) return false;
  3723. return true;
  3724. }
  3725. if (
  3726. // Reject know invalid CNPJs
  3727. tin === '00000000000000' || tin === '11111111111111' || tin === '22222222222222' || tin === '33333333333333' || tin === '44444444444444' || tin === '55555555555555' || tin === '66666666666666' || tin === '77777777777777' || tin === '88888888888888' || tin === '99999999999999') {
  3728. return false;
  3729. }
  3730. var length = tin.length - 2;
  3731. var identifiers = tin.substring(0, length);
  3732. var verificators = tin.substring(length);
  3733. var sum = 0;
  3734. var pos = length - 7;
  3735. for (var _i9 = length; _i9 >= 1; _i9--) {
  3736. sum += identifiers.charAt(length - _i9) * pos;
  3737. pos -= 1;
  3738. if (pos < 2) {
  3739. pos = 9;
  3740. }
  3741. }
  3742. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  3743. if (result !== parseInt(verificators.charAt(0), 10)) {
  3744. return false;
  3745. }
  3746. length += 1;
  3747. identifiers = tin.substring(0, length);
  3748. sum = 0;
  3749. pos = length - 7;
  3750. for (var _i0 = length; _i0 >= 1; _i0--) {
  3751. sum += identifiers.charAt(length - _i0) * pos;
  3752. pos -= 1;
  3753. if (pos < 2) {
  3754. pos = 9;
  3755. }
  3756. }
  3757. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  3758. if (result !== parseInt(verificators.charAt(1), 10)) {
  3759. return false;
  3760. }
  3761. return true;
  3762. }
  3763. /*
  3764. * pt-PT validation function
  3765. * (Número de identificação fiscal (NIF), persons/entities)
  3766. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3767. */
  3768. function ptPtCheck(tin) {
  3769. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  3770. return parseInt(a, 10);
  3771. }), 9) % 11;
  3772. if (checksum > 9) {
  3773. return parseInt(tin[8], 10) === 0;
  3774. }
  3775. return checksum === parseInt(tin[8], 10);
  3776. }
  3777. /*
  3778. * ro-RO validation function
  3779. * (Cod Numeric Personal (CNP) or Cod de înregistrare fiscală (CIF),
  3780. * persons only)
  3781. * Verify CNP validity by calculating check (last) digit (test not found for CIF)
  3782. * Material not in DG TAXUD document sourced from:
  3783. * `https://en.wikipedia.org/wiki/National_identification_number#Romania`
  3784. */
  3785. function roRoCheck(tin) {
  3786. if (tin.slice(0, 4) !== '9000') {
  3787. // No test found for this format
  3788. // Extract full year using century digit if possible
  3789. var full_year = tin.slice(1, 3);
  3790. switch (tin[0]) {
  3791. case '1':
  3792. case '2':
  3793. full_year = "19".concat(full_year);
  3794. break;
  3795. case '3':
  3796. case '4':
  3797. full_year = "18".concat(full_year);
  3798. break;
  3799. case '5':
  3800. case '6':
  3801. full_year = "20".concat(full_year);
  3802. break;
  3803. default:
  3804. }
  3805. // Check date validity
  3806. var date = "".concat(full_year, "/").concat(tin.slice(3, 5), "/").concat(tin.slice(5, 7));
  3807. if (date.length === 8) {
  3808. if (!isDate(date, 'YY/MM/DD')) {
  3809. return false;
  3810. }
  3811. } else if (!isDate(date, 'YYYY/MM/DD')) {
  3812. return false;
  3813. }
  3814. // Calculate check digit
  3815. var digits = tin.split('').map(function (a) {
  3816. return parseInt(a, 10);
  3817. });
  3818. var multipliers = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
  3819. var checksum = 0;
  3820. for (var i = 0; i < multipliers.length; i++) {
  3821. checksum += digits[i] * multipliers[i];
  3822. }
  3823. if (checksum % 11 === 10) {
  3824. return digits[12] === 1;
  3825. }
  3826. return digits[12] === checksum % 11;
  3827. }
  3828. return true;
  3829. }
  3830. /*
  3831. * sk-SK validation function
  3832. * (Rodné číslo (RČ) or bezvýznamové identifikačné číslo (BIČ), persons only)
  3833. * Checks validity of pre-1954 birth numbers (rodné číslo) only
  3834. * Due to the introduction of the pseudo-random BIČ it is not possible to test
  3835. * post-1954 birth numbers without knowing whether they are BIČ or RČ beforehand
  3836. */
  3837. function skSkCheck(tin) {
  3838. if (tin.length === 9) {
  3839. tin = tin.replace(/\W/, '');
  3840. if (tin.slice(6) === '000') {
  3841. return false;
  3842. } // Three-zero serial not assigned before 1954
  3843. // Extract full year from TIN length
  3844. var full_year = parseInt(tin.slice(0, 2), 10);
  3845. if (full_year > 53) {
  3846. return false;
  3847. }
  3848. if (full_year < 10) {
  3849. full_year = "190".concat(full_year);
  3850. } else {
  3851. full_year = "19".concat(full_year);
  3852. }
  3853. // Extract month from TIN and normalize
  3854. var month = parseInt(tin.slice(2, 4), 10);
  3855. if (month > 50) {
  3856. month -= 50;
  3857. }
  3858. if (month < 10) {
  3859. month = "0".concat(month);
  3860. }
  3861. // Check date validity
  3862. var date = "".concat(full_year, "/").concat(month, "/").concat(tin.slice(4, 6));
  3863. if (!isDate(date, 'YYYY/MM/DD')) {
  3864. return false;
  3865. }
  3866. }
  3867. return true;
  3868. }
  3869. /*
  3870. * sl-SI validation function
  3871. * (Davčna številka, persons/entities)
  3872. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3873. */
  3874. function slSiCheck(tin) {
  3875. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 7).map(function (a) {
  3876. return parseInt(a, 10);
  3877. }), 8) % 11;
  3878. if (checksum === 10) {
  3879. return parseInt(tin[7], 10) === 0;
  3880. }
  3881. return checksum === parseInt(tin[7], 10);
  3882. }
  3883. /*
  3884. * sv-SE validation function
  3885. * (Personnummer or samordningsnummer, persons only)
  3886. * Checks validity of birth date and calls luhnCheck() to validate check (last) digit
  3887. */
  3888. function svSeCheck(tin) {
  3889. // Make copy of TIN and normalize to two-digit year form
  3890. var tin_copy = tin.slice(0);
  3891. if (tin.length > 11) {
  3892. tin_copy = tin_copy.slice(2);
  3893. }
  3894. // Extract date of birth
  3895. var full_year = '';
  3896. var month = tin_copy.slice(2, 4);
  3897. var day = parseInt(tin_copy.slice(4, 6), 10);
  3898. if (tin.length > 11) {
  3899. full_year = tin.slice(0, 4);
  3900. } else {
  3901. full_year = tin.slice(0, 2);
  3902. if (tin.length === 11 && day < 60) {
  3903. // Extract full year from centenarian symbol
  3904. // Should work just fine until year 10000 or so
  3905. var current_year = new Date().getFullYear().toString();
  3906. var current_century = parseInt(current_year.slice(0, 2), 10);
  3907. current_year = parseInt(current_year, 10);
  3908. if (tin[6] === '-') {
  3909. if (parseInt("".concat(current_century).concat(full_year), 10) > current_year) {
  3910. full_year = "".concat(current_century - 1).concat(full_year);
  3911. } else {
  3912. full_year = "".concat(current_century).concat(full_year);
  3913. }
  3914. } else {
  3915. full_year = "".concat(current_century - 1).concat(full_year);
  3916. if (current_year - parseInt(full_year, 10) < 100) {
  3917. return false;
  3918. }
  3919. }
  3920. }
  3921. }
  3922. // Normalize day and check date validity
  3923. if (day > 60) {
  3924. day -= 60;
  3925. }
  3926. if (day < 10) {
  3927. day = "0".concat(day);
  3928. }
  3929. var date = "".concat(full_year, "/").concat(month, "/").concat(day);
  3930. if (date.length === 8) {
  3931. if (!isDate(date, 'YY/MM/DD')) {
  3932. return false;
  3933. }
  3934. } else if (!isDate(date, 'YYYY/MM/DD')) {
  3935. return false;
  3936. }
  3937. return luhnCheck(tin.replace(/\W/, ''));
  3938. }
  3939. /**
  3940. * uk-UA validation function
  3941. * Verify TIN validity by calculating check (last) digit (variant of MOD 11)
  3942. */
  3943. function ukUaCheck(tin) {
  3944. // Calculate check digit
  3945. var digits = tin.split('').map(function (a) {
  3946. return parseInt(a, 10);
  3947. });
  3948. var multipliers = [-1, 5, 7, 9, 4, 6, 10, 5, 7];
  3949. var checksum = 0;
  3950. for (var i = 0; i < multipliers.length; i++) {
  3951. checksum += digits[i] * multipliers[i];
  3952. }
  3953. return checksum % 11 === 10 ? digits[9] === 0 : digits[9] === checksum % 11;
  3954. }
  3955. // Locale lookup objects
  3956. /*
  3957. * Tax id regex formats for various locales
  3958. *
  3959. * Where not explicitly specified in DG-TAXUD document both
  3960. * uppercase and lowercase letters are acceptable.
  3961. */
  3962. var taxIdFormat = {
  3963. 'bg-BG': /^\d{10}$/,
  3964. 'cs-CZ': /^\d{6}\/{0,1}\d{3,4}$/,
  3965. 'de-AT': /^\d{9}$/,
  3966. 'de-DE': /^[1-9]\d{10}$/,
  3967. 'dk-DK': /^\d{6}-{0,1}\d{4}$/,
  3968. 'el-CY': /^[09]\d{7}[A-Z]$/,
  3969. 'el-GR': /^([0-4]|[7-9])\d{8}$/,
  3970. 'en-CA': /^\d{9}$/,
  3971. 'en-GB': /^\d{10}$|^(?!GB|NK|TN|ZZ)(?![DFIQUV])[A-Z](?![DFIQUVO])[A-Z]\d{6}[ABCD ]$/i,
  3972. 'en-IE': /^\d{7}[A-W][A-IW]{0,1}$/i,
  3973. 'en-US': /^\d{2}[- ]{0,1}\d{7}$/,
  3974. 'es-AR': /(20|23|24|27|30|33|34)[0-9]{8}[0-9]/,
  3975. 'es-ES': /^(\d{0,8}|[XYZKLM]\d{7})[A-HJ-NP-TV-Z]$/i,
  3976. 'et-EE': /^[1-6]\d{6}(00[1-9]|0[1-9][0-9]|[1-6][0-9]{2}|70[0-9]|710)\d$/,
  3977. 'fi-FI': /^\d{6}[-+A]\d{3}[0-9A-FHJ-NPR-Y]$/i,
  3978. 'fr-BE': /^\d{11}$/,
  3979. 'fr-FR': /^[0-3]\d{12}$|^[0-3]\d\s\d{2}(\s\d{3}){3}$/,
  3980. // Conforms both to official spec and provided example
  3981. 'fr-LU': /^\d{13}$/,
  3982. 'hr-HR': /^\d{11}$/,
  3983. 'hu-HU': /^8\d{9}$/,
  3984. '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,
  3985. 'lv-LV': /^\d{6}-{0,1}\d{5}$/,
  3986. // Conforms both to DG TAXUD spec and original research
  3987. 'mt-MT': /^\d{3,7}[APMGLHBZ]$|^([1-8])\1\d{7}$/i,
  3988. 'nl-NL': /^\d{9}$/,
  3989. 'pl-PL': /^\d{10,11}$/,
  3990. 'pt-BR': /(?:^\d{11}$)|(?:^\d{14}$)/,
  3991. 'pt-PT': /^\d{9}$/,
  3992. 'ro-RO': /^\d{13}$/,
  3993. 'sk-SK': /^\d{6}\/{0,1}\d{3,4}$/,
  3994. 'sl-SI': /^[1-9]\d{7}$/,
  3995. 'sv-SE': /^(\d{6}[-+]{0,1}\d{4}|(18|19|20)\d{6}[-+]{0,1}\d{4})$/,
  3996. 'uk-UA': /^\d{10}$/
  3997. };
  3998. // taxIdFormat locale aliases
  3999. taxIdFormat['lb-LU'] = taxIdFormat['fr-LU'];
  4000. taxIdFormat['lt-LT'] = taxIdFormat['et-EE'];
  4001. taxIdFormat['nl-BE'] = taxIdFormat['fr-BE'];
  4002. taxIdFormat['fr-CA'] = taxIdFormat['en-CA'];
  4003. // Algorithmic tax id check functions for various locales
  4004. var taxIdCheck = {
  4005. 'bg-BG': bgBgCheck,
  4006. 'cs-CZ': csCzCheck,
  4007. 'de-AT': deAtCheck,
  4008. 'de-DE': deDeCheck,
  4009. 'dk-DK': dkDkCheck,
  4010. 'el-CY': elCyCheck,
  4011. 'el-GR': elGrCheck,
  4012. 'en-CA': isCanadianSIN,
  4013. 'en-IE': enIeCheck,
  4014. 'en-US': enUsCheck,
  4015. 'es-AR': esArCheck,
  4016. 'es-ES': esEsCheck,
  4017. 'et-EE': etEeCheck,
  4018. 'fi-FI': fiFiCheck,
  4019. 'fr-BE': frBeCheck,
  4020. 'fr-FR': frFrCheck,
  4021. 'fr-LU': frLuCheck,
  4022. 'hr-HR': hrHrCheck,
  4023. 'hu-HU': huHuCheck,
  4024. 'it-IT': itItCheck,
  4025. 'lv-LV': lvLvCheck,
  4026. 'mt-MT': mtMtCheck,
  4027. 'nl-NL': nlNlCheck,
  4028. 'pl-PL': plPlCheck,
  4029. 'pt-BR': ptBrCheck,
  4030. 'pt-PT': ptPtCheck,
  4031. 'ro-RO': roRoCheck,
  4032. 'sk-SK': skSkCheck,
  4033. 'sl-SI': slSiCheck,
  4034. 'sv-SE': svSeCheck,
  4035. 'uk-UA': ukUaCheck
  4036. };
  4037. // taxIdCheck locale aliases
  4038. taxIdCheck['lb-LU'] = taxIdCheck['fr-LU'];
  4039. taxIdCheck['lt-LT'] = taxIdCheck['et-EE'];
  4040. taxIdCheck['nl-BE'] = taxIdCheck['fr-BE'];
  4041. taxIdCheck['fr-CA'] = taxIdCheck['en-CA'];
  4042. // Regexes for locales where characters should be omitted before checking format
  4043. var allsymbols = /[-\\\/!@#$%\^&\*\(\)\+\=\[\]]+/g;
  4044. var sanitizeRegexes = {
  4045. 'de-AT': allsymbols,
  4046. 'de-DE': /[\/\\]/g,
  4047. 'fr-BE': allsymbols
  4048. };
  4049. // sanitizeRegexes locale aliases
  4050. sanitizeRegexes['nl-BE'] = sanitizeRegexes['fr-BE'];
  4051. /*
  4052. * Validator function
  4053. * Return true if the passed string is a valid tax identification number
  4054. * for the specified locale.
  4055. * Throw an error exception if the locale is not supported.
  4056. */
  4057. function isTaxID(str) {
  4058. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  4059. assertString(str);
  4060. // Copy TIN to avoid replacement if sanitized
  4061. var strcopy = str.slice(0);
  4062. if (locale in taxIdFormat) {
  4063. if (locale in sanitizeRegexes) {
  4064. strcopy = strcopy.replace(sanitizeRegexes[locale], '');
  4065. }
  4066. if (!taxIdFormat[locale].test(strcopy)) {
  4067. return false;
  4068. }
  4069. if (locale in taxIdCheck) {
  4070. return taxIdCheck[locale](strcopy);
  4071. }
  4072. // Fallthrough; not all locales have algorithmic checks
  4073. return true;
  4074. }
  4075. throw new Error("Invalid locale '".concat(locale, "'"));
  4076. }
  4077. /* eslint-disable max-len */
  4078. var phones = {
  4079. 'am-AM': /^(\+?374|0)(33|4[134]|55|77|88|9[13-689])\d{6}$/,
  4080. 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
  4081. 'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
  4082. 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
  4083. 'ar-LB': /^(\+?961)?((3|81)\d{6}|7\d{7})$/,
  4084. 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
  4085. 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
  4086. 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
  4087. 'ar-KW': /^(\+?965)([569]\d{7}|41\d{6})$/,
  4088. 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
  4089. 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/,
  4090. 'ar-OM': /^((\+|00)968)?([79][1-9])\d{6}$/,
  4091. 'ar-PS': /^(\+?970|0)5[6|9](\d{7})$/,
  4092. 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
  4093. 'ar-SD': /^((\+?249)|0)?(9[012369]|1[012])\d{7}$/,
  4094. 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
  4095. 'ar-TN': /^(\+?216)?[2459]\d{7}$/,
  4096. 'az-AZ': /^(\+994|0)(10|5[015]|7[07]|99)\d{7}$/,
  4097. 'ar-QA': /^(\+?974|0)?([3567]\d{7})$/,
  4098. 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
  4099. 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
  4100. 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
  4101. 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
  4102. 'ca-AD': /^(\+376)?[346]\d{5}$/,
  4103. 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  4104. 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
  4105. 'de-DE': /^((\+49|0)1)(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/,
  4106. 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
  4107. 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
  4108. 'de-LU': /^(\+352)?((6\d1)\d{6})$/,
  4109. 'dv-MV': /^(\+?960)?(7[2-9]|9[1-9])\d{5}$/,
  4110. 'el-GR': /^(\+?30|0)?6(8[5-9]|9(?![26])[0-9])\d{7}$/,
  4111. 'el-CY': /^(\+?357?)?(9(9|7|6|5|4)\d{6})$/,
  4112. '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}$/,
  4113. 'en-AU': /^(\+?61|0)4\d{8}$/,
  4114. 'en-AG': /^(?:\+1|1)268(?:464|7(?:1[3-9]|[28]\d|3[0246]|64|7[0-689]))\d{4}$/,
  4115. 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}$))/,
  4116. 'en-BS': /^(\+?1[-\s]?|0)?\(?242\)?[-\s]?\d{3}[-\s]?\d{4}$/,
  4117. 'en-GB': /^(\+?44|0)7[1-9]\d{8}$/,
  4118. 'en-GG': /^(\+?44|0)1481\d{6}$/,
  4119. 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|53|28|55|59)\d{7}$/,
  4120. 'en-GY': /^(\+592|0)6\d{6}$/,
  4121. 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
  4122. 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
  4123. 'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
  4124. 'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
  4125. 'en-JM': /^(\+?876)?\d{7}$/,
  4126. 'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
  4127. 'fr-CF': /^(\+?236| ?)(70|75|77|72|21|22)\d{6}$/,
  4128. 'en-SS': /^(\+?211|0)(9[1257])\d{7}$/,
  4129. 'en-KI': /^((\+686|686)?)?( )?((6|7)(2|3|8)[0-9]{6})$/,
  4130. 'en-KN': /^(?:\+1|1)869(?:46\d|48[89]|55[6-8]|66\d|76[02-7])\d{4}$/,
  4131. 'en-LS': /^(\+?266)(22|28|57|58|59|27|52)\d{6}$/,
  4132. 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
  4133. 'en-MU': /^(\+?230|0)?\d{8}$/,
  4134. 'en-MW': /^(\+?265|0)(((77|88|31|99|98|21)\d{7})|(((111)|1)\d{6})|(32000\d{4}))$/,
  4135. 'en-NA': /^(\+?264|0)(6|8)\d{7}$/,
  4136. 'en-NG': /^(\+?234|0)?[789]\d{9}$/,
  4137. 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
  4138. 'en-PG': /^(\+?675|0)?(7\d|8[18])\d{6}$/,
  4139. 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/,
  4140. 'en-PH': /^(09|\+639)\d{9}$/,
  4141. 'en-RW': /^(\+?250|0)?[7]\d{8}$/,
  4142. 'en-SG': /^(\+65)?[3689]\d{7}$/,
  4143. 'en-SL': /^(\+?232|0)\d{8}$/,
  4144. 'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
  4145. 'en-UG': /^(\+?256|0)?[7]\d{8}$/,
  4146. 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
  4147. 'en-ZA': /^(\+?27|0)\d{9}$/,
  4148. 'en-ZM': /^(\+?26)?0[79][567]\d{7}$/,
  4149. 'en-ZW': /^(\+263)[0-9]{9}$/,
  4150. 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/,
  4151. 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
  4152. 'es-BO': /^(\+?591)?(6|7)\d{7}$/,
  4153. 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/,
  4154. 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
  4155. 'es-CR': /^(\+506)?[2-8]\d{7}$/,
  4156. 'es-CU': /^(\+53|0053)?5\d{7}$/,
  4157. 'es-DO': /^(\+?1)?8[024]9\d{7}$/,
  4158. 'es-HN': /^(\+?504)?[9|8|3|2]\d{7}$/,
  4159. 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
  4160. 'es-ES': /^(\+?34)?[6|7]\d{8}$/,
  4161. 'es-GT': /^(\+?502)?[2|6|7]\d{7}$/,
  4162. 'es-PE': /^(\+?51)?9\d{8}$/,
  4163. 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
  4164. 'es-NI': /^(\+?505)\d{7,8}$/,
  4165. 'es-PA': /^(\+?507)\d{7,8}$/,
  4166. 'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
  4167. 'es-SV': /^(\+?503)?[67]\d{7}$/,
  4168. 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
  4169. 'es-VE': /^(\+?58)?(2|4)\d{9}$/,
  4170. 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
  4171. 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
  4172. 'fi-FI': /^(\+?358|0)\s?(4[0-6]|50)\s?(\d\s?){4,8}$/,
  4173. 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
  4174. 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  4175. 'fr-BF': /^(\+226|0)[67]\d{7}$/,
  4176. 'fr-BJ': /^(\+229)\d{8}$/,
  4177. 'fr-CD': /^(\+?243|0)?(8|9)\d{8}$/,
  4178. 'fr-CM': /^(\+?237)6[0-9]{8}$/,
  4179. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  4180. 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
  4181. 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
  4182. 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
  4183. 'fr-PF': /^(\+?689)?8[789]\d{6}$/,
  4184. 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
  4185. 'fr-WF': /^(\+681)?\d{6}$/,
  4186. 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
  4187. 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/,
  4188. 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
  4189. 'ir-IR': /^(\+98|0)?9\d{9}$/,
  4190. 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
  4191. 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
  4192. 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
  4193. 'ka-GE': /^(\+?995)?(79\d{7}|5\d{8})$/,
  4194. 'kk-KZ': /^(\+?7|8)?7\d{9}$/,
  4195. 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  4196. 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
  4197. 'ky-KG': /^(\+996\s?)?(22[0-9]|50[0-9]|55[0-9]|70[0-9]|75[0-9]|77[0-9]|880|990|995|996|997|998)\s?\d{3}\s?\d{3}$/,
  4198. 'lt-LT': /^(\+370|8)\d{8}$/,
  4199. 'lv-LV': /^(\+?371)2\d{7}$/,
  4200. 'mg-MG': /^((\+?261|0)(2|3)\d)?\d{7}$/,
  4201. 'mn-MN': /^(\+|00|011)?976(77|81|88|91|94|95|96|99)\d{6}$/,
  4202. '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}$/,
  4203. 'ms-MY': /^(\+?60|0)1(([0145](-|\s)?\d{7,8})|([236-9](-|\s)?\d{7}))$/,
  4204. 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/,
  4205. 'nb-NO': /^(\+?47)?[49]\d{7}$/,
  4206. 'ne-NP': /^(\+?977)?9[78]\d{8}$/,
  4207. 'nl-BE': /^(\+?32|0)4\d{8}$/,
  4208. 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
  4209. 'nl-AW': /^(\+)?297(56|59|64|73|74|99)\d{5}$/,
  4210. 'nn-NO': /^(\+?47)?[49]\d{7}$/,
  4211. 'pl-PL': /^(\+?48)? ?([5-8]\d|45) ?\d{3} ?\d{2} ?\d{2}$/,
  4212. '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}))$/,
  4213. 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
  4214. 'pt-AO': /^(\+?244)?9\d{8}$/,
  4215. 'ro-MD': /^(\+?373|0)((6(0|1|2|6|7|8|9))|(7(6|7|8|9)))\d{6}$/,
  4216. 'ro-RO': /^(\+?40|0)\s?7\d{2}(\/|\s|\.|-)?\d{3}(\s|\.|-)?\d{3}$/,
  4217. 'ru-RU': /^(\+?7|8)?9\d{9}$/,
  4218. 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/,
  4219. 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
  4220. 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  4221. 'so-SO': /^(\+?252|0)((6[0-9])\d{7}|(7[1-9])\d{7})$/,
  4222. 'sq-AL': /^(\+355|0)6[2-9]\d{7}$/,
  4223. 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
  4224. 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
  4225. 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/,
  4226. 'th-TH': /^(\+66|66|0)\d{9}$/,
  4227. 'tr-TR': /^(\+?90|0)?5\d{9}$/,
  4228. 'tk-TM': /^(\+993|993|8)\d{8}$/,
  4229. 'uk-UA': /^(\+?38)?0(50|6[36-8]|7[357]|9[1-9])\d{7}$/,
  4230. 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
  4231. 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
  4232. 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/,
  4233. 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
  4234. 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/,
  4235. 'ar-YE': /^(((\+|00)9677|0?7)[0137]\d{7}|((\+|00)967|0)[1-7]\d{6})$/,
  4236. 'ar-EH': /^(\+?212|0)[\s\-]?(5288|5289)[\s\-]?\d{5}$/,
  4237. 'fa-AF': /^(\+93|0)?(2{1}[0-8]{1}|[3-5]{1}[0-4]{1})(\d{7})$/,
  4238. 'mk-MK': /^(\+?389|0)?((?:2[2-9]\d{6}|(?:3[1-4]|4[2-8])\d{6}|500\d{5}|5[2-9]\d{6}|7[0-9][2-9]\d{5}|8[1-9]\d{6}|800\d{5}|8009\d{4}))$/
  4239. };
  4240. /* eslint-enable max-len */
  4241. // aliases
  4242. phones['en-CA'] = phones['en-US'];
  4243. phones['fr-CA'] = phones['en-CA'];
  4244. phones['fr-BE'] = phones['nl-BE'];
  4245. phones['zh-HK'] = phones['en-HK'];
  4246. phones['zh-MO'] = phones['en-MO'];
  4247. phones['ga-IE'] = phones['en-IE'];
  4248. phones['fr-CH'] = phones['de-CH'];
  4249. phones['it-CH'] = phones['fr-CH'];
  4250. function isMobilePhone(str, locale, options) {
  4251. assertString(str);
  4252. if (options && options.strictMode && !str.startsWith('+')) {
  4253. return false;
  4254. }
  4255. if (Array.isArray(locale)) {
  4256. return locale.some(function (key) {
  4257. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  4258. // istanbul ignore else
  4259. if (phones.hasOwnProperty(key)) {
  4260. var phone = phones[key];
  4261. if (phone.test(str)) {
  4262. return true;
  4263. }
  4264. }
  4265. return false;
  4266. });
  4267. } else if (locale in phones) {
  4268. return phones[locale].test(str);
  4269. // alias falsey locale as 'any'
  4270. } else if (!locale || locale === 'any') {
  4271. for (var key in phones) {
  4272. // istanbul ignore else
  4273. if (phones.hasOwnProperty(key)) {
  4274. var phone = phones[key];
  4275. if (phone.test(str)) {
  4276. return true;
  4277. }
  4278. }
  4279. }
  4280. return false;
  4281. }
  4282. throw new Error("Invalid locale '".concat(locale, "'"));
  4283. }
  4284. var locales$5 = Object.keys(phones);
  4285. var eth = /^(0x)[0-9a-f]{40}$/i;
  4286. function isEthereumAddress(str) {
  4287. assertString(str);
  4288. return eth.test(str);
  4289. }
  4290. function currencyRegex(options) {
  4291. var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
  4292. options.digits_after_decimal.forEach(function (digit, index) {
  4293. if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
  4294. });
  4295. var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
  4296. return "\\".concat(m);
  4297. }), ")").concat(options.require_symbol ? '' : '?'),
  4298. negative = '-?',
  4299. whole_dollar_amount_without_sep = '[1-9]\\d*',
  4300. whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
  4301. valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
  4302. whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
  4303. decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
  4304. var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : '');
  4305. // default is negative sign before symbol, but there are two other options (besides parens)
  4306. if (options.allow_negatives && !options.parens_for_negatives) {
  4307. if (options.negative_sign_after_digits) {
  4308. pattern += negative;
  4309. } else if (options.negative_sign_before_digits) {
  4310. pattern = negative + pattern;
  4311. }
  4312. }
  4313. // South African Rand, for example, uses R 123 (space) and R-123 (no space)
  4314. if (options.allow_negative_sign_placeholder) {
  4315. pattern = "( (?!\\-))?".concat(pattern);
  4316. } else if (options.allow_space_after_symbol) {
  4317. pattern = " ?".concat(pattern);
  4318. } else if (options.allow_space_after_digits) {
  4319. pattern += '( (?!$))?';
  4320. }
  4321. if (options.symbol_after_digits) {
  4322. pattern += symbol;
  4323. } else {
  4324. pattern = symbol + pattern;
  4325. }
  4326. if (options.allow_negatives) {
  4327. if (options.parens_for_negatives) {
  4328. pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
  4329. } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
  4330. pattern = negative + pattern;
  4331. }
  4332. }
  4333. // ensure there's a dollar and/or decimal amount, and that
  4334. // it doesn't start with a space or a negative sign followed by a space
  4335. return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
  4336. }
  4337. var default_currency_options = {
  4338. symbol: '$',
  4339. require_symbol: false,
  4340. allow_space_after_symbol: false,
  4341. symbol_after_digits: false,
  4342. allow_negatives: true,
  4343. parens_for_negatives: false,
  4344. negative_sign_before_digits: false,
  4345. negative_sign_after_digits: false,
  4346. allow_negative_sign_placeholder: false,
  4347. thousands_separator: ',',
  4348. decimal_separator: '.',
  4349. allow_decimal: true,
  4350. require_decimal: false,
  4351. digits_after_decimal: [2],
  4352. allow_space_after_digits: false
  4353. };
  4354. function isCurrency(str, options) {
  4355. assertString(str);
  4356. options = merge(options, default_currency_options);
  4357. return currencyRegex(options).test(str);
  4358. }
  4359. var bech32 = /^(bc1|tb1|bc1p|tb1p)[ac-hj-np-z02-9]{39,58}$/;
  4360. var base58 = /^(1|2|3|m)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
  4361. function isBtcAddress(str) {
  4362. assertString(str);
  4363. return bech32.test(str) || base58.test(str);
  4364. }
  4365. // https://en.wikipedia.org/wiki/ISO_6346
  4366. // according to ISO6346 standard, checksum digit is mandatory for freight container but recommended
  4367. // for other container types (J and Z)
  4368. var isISO6346Str = /^[A-Z]{3}(U[0-9]{7})|([J,Z][0-9]{6,7})$/;
  4369. var isDigit = /^[0-9]$/;
  4370. function isISO6346(str) {
  4371. assertString(str);
  4372. str = str.toUpperCase();
  4373. if (!isISO6346Str.test(str)) return false;
  4374. if (str.length === 11) {
  4375. var sum = 0;
  4376. for (var i = 0; i < str.length - 1; i++) {
  4377. if (!isDigit.test(str[i])) {
  4378. var convertedCode = void 0;
  4379. var letterCode = str.charCodeAt(i) - 55;
  4380. if (letterCode < 11) convertedCode = letterCode;else if (letterCode >= 11 && letterCode <= 20) convertedCode = 12 + letterCode % 11;else if (letterCode >= 21 && letterCode <= 30) convertedCode = 23 + letterCode % 21;else convertedCode = 34 + letterCode % 31;
  4381. sum += convertedCode * Math.pow(2, i);
  4382. } else sum += str[i] * Math.pow(2, i);
  4383. }
  4384. var checkSumDigit = sum % 11;
  4385. if (checkSumDigit === 10) checkSumDigit = 0;
  4386. return Number(str[str.length - 1]) === checkSumDigit;
  4387. }
  4388. return true;
  4389. }
  4390. var isFreightContainerID = isISO6346;
  4391. 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']);
  4392. function isISO6391(str) {
  4393. assertString(str);
  4394. return isISO6391Set.has(str);
  4395. }
  4396. /* eslint-disable max-len */
  4397. // from http://goo.gl/0ejHHW
  4398. 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)?)?)?)?$/;
  4399. // same as above, except with a strict 'T' separator between date and time
  4400. 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)?)?)?)?$/;
  4401. /* eslint-enable max-len */
  4402. var isValidDate = function isValidDate(str) {
  4403. // str must have passed the ISO8601 check
  4404. // this check is meant to catch invalid dates
  4405. // like 2009-02-31
  4406. // first check for ordinal dates
  4407. var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
  4408. if (ordinalMatch) {
  4409. var oYear = Number(ordinalMatch[1]);
  4410. var oDay = Number(ordinalMatch[2]);
  4411. // if is leap year
  4412. if (oYear % 4 === 0 && oYear % 100 !== 0 || oYear % 400 === 0) return oDay <= 366;
  4413. return oDay <= 365;
  4414. }
  4415. var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number);
  4416. var year = match[1];
  4417. var month = match[2];
  4418. var day = match[3];
  4419. var monthString = month ? "0".concat(month).slice(-2) : month;
  4420. var dayString = day ? "0".concat(day).slice(-2) : day;
  4421. // create a date object and compare
  4422. var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01'));
  4423. if (month && day) {
  4424. return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day;
  4425. }
  4426. return true;
  4427. };
  4428. function isISO8601(str) {
  4429. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4430. assertString(str);
  4431. var check = options.strictSeparator ? iso8601StrictSeparator.test(str) : iso8601.test(str);
  4432. if (check && options.strict) return isValidDate(str);
  4433. return check;
  4434. }
  4435. /* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */
  4436. var dateFullYear = /[0-9]{4}/;
  4437. var dateMonth = /(0[1-9]|1[0-2])/;
  4438. var dateMDay = /([12]\d|0[1-9]|3[01])/;
  4439. var timeHour = /([01][0-9]|2[0-3])/;
  4440. var timeMinute = /[0-5][0-9]/;
  4441. var timeSecond = /([0-5][0-9]|60)/;
  4442. var timeSecFrac = /(\.[0-9]+)?/;
  4443. var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source));
  4444. var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")"));
  4445. var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source));
  4446. var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source));
  4447. var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source));
  4448. var rfc3339 = new RegExp("^".concat(fullDate.source, "[ tT]").concat(fullTime.source, "$"));
  4449. function isRFC3339(str) {
  4450. assertString(str);
  4451. return rfc3339.test(str);
  4452. }
  4453. // from https://www.unicode.org/iso15924/iso15924-codes.html
  4454. var validISO15924Codes = new Set(['Adlm', 'Afak', 'Aghb', 'Ahom', 'Arab', 'Aran', 'Armi', 'Armn', 'Avst', 'Bali', 'Bamu', 'Bass', 'Batk', 'Beng', 'Bhks', 'Blis', 'Bopo', 'Brah', 'Brai', 'Bugi', 'Buhd', 'Cakm', 'Cans', 'Cari', 'Cham', 'Cher', 'Chis', 'Chrs', 'Cirt', 'Copt', 'Cpmn', 'Cprt', 'Cyrl', 'Cyrs', 'Deva', 'Diak', 'Dogr', 'Dsrt', 'Dupl', 'Egyd', 'Egyh', 'Egyp', 'Elba', 'Elym', 'Ethi', 'Gara', 'Geok', 'Geor', 'Glag', 'Gong', 'Gonm', 'Goth', 'Gran', 'Grek', 'Gujr', 'Gukh', 'Guru', 'Hanb', 'Hang', 'Hani', 'Hano', 'Hans', 'Hant', 'Hatr', 'Hebr', 'Hira', 'Hluw', 'Hmng', 'Hmnp', 'Hrkt', 'Hung', 'Inds', 'Ital', 'Jamo', 'Java', 'Jpan', 'Jurc', 'Kali', 'Kana', 'Kawi', 'Khar', 'Khmr', 'Khoj', 'Kitl', 'Kits', 'Knda', 'Kore', 'Kpel', 'Krai', 'Kthi', 'Lana', 'Laoo', 'Latf', 'Latg', 'Latn', 'Leke', 'Lepc', 'Limb', 'Lina', 'Linb', 'Lisu', 'Loma', 'Lyci', 'Lydi', 'Mahj', 'Maka', 'Mand', 'Mani', 'Marc', 'Maya', 'Medf', 'Mend', 'Merc', 'Mero', 'Mlym', 'Modi', 'Mong', 'Moon', 'Mroo', 'Mtei', 'Mult', 'Mymr', 'Nagm', 'Nand', 'Narb', 'Nbat', 'Newa', 'Nkdb', 'Nkgb', 'Nkoo', 'Nshu', 'Ogam', 'Olck', 'Onao', 'Orkh', 'Orya', 'Osge', 'Osma', 'Ougr', 'Palm', 'Pauc', 'Pcun', 'Pelm', 'Perm', 'Phag', 'Phli', 'Phlp', 'Phlv', 'Phnx', 'Plrd', 'Piqd', 'Prti', 'Psin', 'Qaaa', 'Qaab', 'Qaac', 'Qaad', 'Qaae', 'Qaaf', 'Qaag', 'Qaah', 'Qaai', 'Qaaj', 'Qaak', 'Qaal', 'Qaam', 'Qaan', 'Qaao', 'Qaap', 'Qaaq', 'Qaar', 'Qaas', 'Qaat', 'Qaau', 'Qaav', 'Qaaw', 'Qaax', 'Qaay', 'Qaaz', 'Qaba', 'Qabb', 'Qabc', 'Qabd', 'Qabe', 'Qabf', 'Qabg', 'Qabh', 'Qabi', 'Qabj', 'Qabk', 'Qabl', 'Qabm', 'Qabn', 'Qabo', 'Qabp', 'Qabq', 'Qabr', 'Qabs', 'Qabt', 'Qabu', 'Qabv', 'Qabw', 'Qabx', 'Ranj', 'Rjng', 'Rohg', 'Roro', 'Runr', 'Samr', 'Sara', 'Sarb', 'Saur', 'Sgnw', 'Shaw', 'Shrd', 'Shui', 'Sidd', 'Sidt', 'Sind', 'Sinh', 'Sogd', 'Sogo', 'Sora', 'Soyo', 'Sund', 'Sunu', 'Sylo', 'Syrc', 'Syre', 'Syrj', 'Syrn', 'Tagb', 'Takr', 'Tale', 'Talu', 'Taml', 'Tang', 'Tavt', 'Tayo', 'Telu', 'Teng', 'Tfng', 'Tglg', 'Thaa', 'Thai', 'Tibt', 'Tirh', 'Tnsa', 'Todr', 'Tols', 'Toto', 'Tutg', 'Ugar', 'Vaii', 'Visp', 'Vith', 'Wara', 'Wcho', 'Wole', 'Xpeo', 'Xsux', 'Yezi', 'Yiii', 'Zanb', 'Zinh', 'Zmth', 'Zsye', 'Zsym', 'Zxxx', 'Zyyy', 'Zzzz']);
  4455. function isISO15924(str) {
  4456. assertString(str);
  4457. return validISO15924Codes.has(str);
  4458. }
  4459. // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
  4460. 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']);
  4461. function isISO31661Alpha3(str) {
  4462. assertString(str);
  4463. return validISO31661Alpha3CountriesCodes.has(str.toUpperCase());
  4464. }
  4465. // from https://en.wikipedia.org/wiki/ISO_3166-1_numeric
  4466. var validISO31661NumericCountriesCodes = new Set(['004', '008', '010', '012', '016', '020', '024', '028', '031', '032', '036', '040', '044', '048', '050', '051', '052', '056', '060', '064', '068', '070', '072', '074', '076', '084', '086', '090', '092', '096', '100', '104', '108', '112', '116', '120', '124', '132', '136', '140', '144', '148', '152', '156', '158', '162', '166', '170', '174', '175', '178', '180', '184', '188', '191', '192', '196', '203', '204', '208', '212', '214', '218', '222', '226', '231', '232', '233', '234', '238', '239', '242', '246', '248', '250', '254', '258', '260', '262', '266', '268', '270', '275', '276', '288', '292', '296', '300', '304', '308', '312', '316', '320', '324', '328', '332', '334', '336', '340', '344', '348', '352', '356', '360', '364', '368', '372', '376', '380', '384', '388', '392', '398', '400', '404', '408', '410', '414', '417', '418', '422', '426', '428', '430', '434', '438', '440', '442', '446', '450', '454', '458', '462', '466', '470', '474', '478', '480', '484', '492', '496', '498', '499', '500', '504', '508', '512', '516', '520', '524', '528', '531', '533', '534', '535', '540', '548', '554', '558', '562', '566', '570', '574', '578', '580', '581', '583', '584', '585', '586', '591', '598', '600', '604', '608', '612', '616', '620', '624', '626', '630', '634', '638', '642', '643', '646', '652', '654', '659', '660', '662', '663', '666', '670', '674', '678', '682', '686', '688', '690', '694', '702', '703', '704', '705', '706', '710', '716', '724', '728', '729', '732', '740', '744', '748', '752', '756', '760', '762', '764', '768', '772', '776', '780', '784', '788', '792', '795', '796', '798', '800', '804', '807', '818', '826', '831', '832', '833', '834', '840', '850', '854', '858', '860', '862', '876', '882', '887', '894']);
  4467. function isISO31661Numeric(str) {
  4468. assertString(str);
  4469. return validISO31661NumericCountriesCodes.has(str);
  4470. }
  4471. // from https://en.wikipedia.org/wiki/ISO_4217
  4472. 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', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', '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', 'SLE', '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', 'VED', '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']);
  4473. function isISO4217(str) {
  4474. assertString(str);
  4475. return validISO4217CurrencyCodes.has(str.toUpperCase());
  4476. }
  4477. var base32 = /^[A-Z2-7]+=*$/;
  4478. var crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
  4479. var defaultBase32Options = {
  4480. crockford: false
  4481. };
  4482. function isBase32(str, options) {
  4483. assertString(str);
  4484. options = merge(options, defaultBase32Options);
  4485. if (options.crockford) {
  4486. return crockfordBase32.test(str);
  4487. }
  4488. var len = str.length;
  4489. if (len % 8 === 0 && base32.test(str)) {
  4490. return true;
  4491. }
  4492. return false;
  4493. }
  4494. // Accepted chars - 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
  4495. var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
  4496. function isBase58(str) {
  4497. assertString(str);
  4498. if (base58Reg.test(str)) {
  4499. return true;
  4500. }
  4501. return false;
  4502. }
  4503. var validMediaType = /^[a-z]+\/[a-z0-9\-\+\._]+$/i;
  4504. var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
  4505. var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
  4506. function isDataURI(str) {
  4507. assertString(str);
  4508. var data = str.split(',');
  4509. if (data.length < 2) {
  4510. return false;
  4511. }
  4512. var attributes = data.shift().trim().split(';');
  4513. var schemeAndMediaType = attributes.shift();
  4514. if (schemeAndMediaType.slice(0, 5) !== 'data:') {
  4515. return false;
  4516. }
  4517. var mediaType = schemeAndMediaType.slice(5);
  4518. if (mediaType !== '' && !validMediaType.test(mediaType)) {
  4519. return false;
  4520. }
  4521. for (var i = 0; i < attributes.length; i++) {
  4522. if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
  4523. return false;
  4524. }
  4525. }
  4526. for (var _i = 0; _i < data.length; _i++) {
  4527. if (!validData.test(data[_i])) {
  4528. return false;
  4529. }
  4530. }
  4531. return true;
  4532. }
  4533. 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;
  4534. function isMagnetURI(url) {
  4535. assertString(url);
  4536. if (url.indexOf('magnet:?') !== 0) {
  4537. return false;
  4538. }
  4539. return magnetURIComponent.test(url);
  4540. }
  4541. function rtrim(str, chars) {
  4542. assertString(str);
  4543. if (chars) {
  4544. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  4545. var pattern = new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g');
  4546. return str.replace(pattern, '');
  4547. }
  4548. // Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript
  4549. var strIndex = str.length - 1;
  4550. while (/\s/.test(str.charAt(strIndex))) {
  4551. strIndex -= 1;
  4552. }
  4553. return str.slice(0, strIndex + 1);
  4554. }
  4555. function ltrim(str, chars) {
  4556. assertString(str);
  4557. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  4558. var pattern = chars ? new RegExp("^[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+"), 'g') : /^\s+/g;
  4559. return str.replace(pattern, '');
  4560. }
  4561. function trim(str, chars) {
  4562. return rtrim(ltrim(str, chars), chars);
  4563. }
  4564. function parseMailtoQueryString(queryString) {
  4565. var allowedParams = new Set(['subject', 'body', 'cc', 'bcc']),
  4566. query = {
  4567. cc: '',
  4568. bcc: ''
  4569. };
  4570. var isParseFailed = false;
  4571. var queryParams = queryString.split('&');
  4572. if (queryParams.length > 4) {
  4573. return false;
  4574. }
  4575. var _iterator = _createForOfIteratorHelper(queryParams),
  4576. _step;
  4577. try {
  4578. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  4579. var q = _step.value;
  4580. var _q$split = q.split('='),
  4581. _q$split2 = _slicedToArray(_q$split, 2),
  4582. key = _q$split2[0],
  4583. value = _q$split2[1];
  4584. // checked for invalid and duplicated query params
  4585. if (key && !allowedParams.has(key)) {
  4586. isParseFailed = true;
  4587. break;
  4588. }
  4589. if (value && (key === 'cc' || key === 'bcc')) {
  4590. query[key] = value;
  4591. }
  4592. if (key) {
  4593. allowedParams["delete"](key);
  4594. }
  4595. }
  4596. } catch (err) {
  4597. _iterator.e(err);
  4598. } finally {
  4599. _iterator.f();
  4600. }
  4601. return isParseFailed ? false : query;
  4602. }
  4603. function isMailtoURI(url, options) {
  4604. assertString(url);
  4605. if (url.indexOf('mailto:') !== 0) {
  4606. return false;
  4607. }
  4608. var _url$replace$split = url.replace('mailto:', '').split('?'),
  4609. _url$replace$split2 = _slicedToArray(_url$replace$split, 2),
  4610. to = _url$replace$split2[0],
  4611. _url$replace$split2$ = _url$replace$split2[1],
  4612. queryString = _url$replace$split2$ === void 0 ? '' : _url$replace$split2$;
  4613. if (!to && !queryString) {
  4614. return true;
  4615. }
  4616. var query = parseMailtoQueryString(queryString);
  4617. if (!query) {
  4618. return false;
  4619. }
  4620. return "".concat(to, ",").concat(query.cc, ",").concat(query.bcc).split(',').every(function (email) {
  4621. email = trim(email, ' ');
  4622. if (email) {
  4623. return isEmail(email, options);
  4624. }
  4625. return true;
  4626. });
  4627. }
  4628. /*
  4629. Checks if the provided string matches to a correct Media type format (MIME type)
  4630. This function only checks is the string format follows the
  4631. established rules by the according RFC specifications.
  4632. This function supports 'charset' in textual media types
  4633. (https://tools.ietf.org/html/rfc6657).
  4634. This function does not check against all the media types listed
  4635. by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml)
  4636. because of lightness purposes : it would require to include
  4637. all these MIME types in this library, which would weigh it
  4638. significantly. This kind of effort maybe is not worth for the use that
  4639. this function has in this entire library.
  4640. More information in the RFC specifications :
  4641. - https://tools.ietf.org/html/rfc2045
  4642. - https://tools.ietf.org/html/rfc2046
  4643. - https://tools.ietf.org/html/rfc7231#section-3.1.1.1
  4644. - https://tools.ietf.org/html/rfc7231#section-3.1.1.5
  4645. */
  4646. // Match simple MIME types
  4647. // NB :
  4648. // Subtype length must not exceed 100 characters.
  4649. // This rule does not comply to the RFC specs (what is the max length ?).
  4650. var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+_]{1,100}$/i; // eslint-disable-line max-len
  4651. // Handle "charset" in "text/*"
  4652. 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
  4653. // Handle "boundary" in "multipart/*"
  4654. 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
  4655. function isMimeType(str) {
  4656. assertString(str);
  4657. return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str);
  4658. }
  4659. var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
  4660. var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
  4661. var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i;
  4662. 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;
  4663. var defaultLatLongOptions = {
  4664. checkDMS: false
  4665. };
  4666. function isLatLong(str, options) {
  4667. assertString(str);
  4668. options = merge(options, defaultLatLongOptions);
  4669. if (!includes(str, ',')) return false;
  4670. var pair = str.split(',');
  4671. if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
  4672. if (options.checkDMS) {
  4673. return latDMS.test(pair[0]) && longDMS.test(pair[1]);
  4674. }
  4675. return lat.test(pair[0]) && _long.test(pair[1]);
  4676. }
  4677. // common patterns
  4678. var threeDigit = /^\d{3}$/;
  4679. var fourDigit = /^\d{4}$/;
  4680. var fiveDigit = /^\d{5}$/;
  4681. var sixDigit = /^\d{6}$/;
  4682. var patterns = {
  4683. AD: /^AD\d{3}$/,
  4684. AT: fourDigit,
  4685. AU: fourDigit,
  4686. AZ: /^AZ\d{4}$/,
  4687. BA: /^([7-8]\d{4}$)/,
  4688. BD: /^([1-8][0-9]{3}|9[0-4][0-9]{2})$/,
  4689. BE: fourDigit,
  4690. BG: fourDigit,
  4691. BR: /^\d{5}-?\d{3}$/,
  4692. BY: /^2[1-4]\d{4}$/,
  4693. CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
  4694. CH: fourDigit,
  4695. 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}$/,
  4696. CO: /^(05|08|11|13|15|17|18|19|20|23|25|27|41|44|47|50|52|54|63|66|68|70|73|76|81|85|86|88|91|94|95|97|99)(\d{4})$/,
  4697. CZ: /^\d{3}\s?\d{2}$/,
  4698. DE: fiveDigit,
  4699. DK: fourDigit,
  4700. DO: fiveDigit,
  4701. DZ: fiveDigit,
  4702. EE: fiveDigit,
  4703. ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
  4704. FI: fiveDigit,
  4705. FR: /^(?:(?:0[1-9]|[1-8]\d|9[0-5])\d{3}|97[1-46]\d{2})$/,
  4706. GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
  4707. GR: /^\d{3}\s?\d{2}$/,
  4708. HR: /^([1-5]\d{4}$)/,
  4709. HT: /^HT\d{4}$/,
  4710. HU: fourDigit,
  4711. ID: fiveDigit,
  4712. IE: /^(?!.*(?:o))[A-Za-z]\d[\dw]\s\w{4}$/i,
  4713. IL: /^(\d{5}|\d{7})$/,
  4714. IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
  4715. IR: /^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/,
  4716. IS: threeDigit,
  4717. IT: fiveDigit,
  4718. JP: /^\d{3}\-\d{4}$/,
  4719. KE: fiveDigit,
  4720. KR: /^(\d{5}|\d{6})$/,
  4721. LI: /^(948[5-9]|949[0-7])$/,
  4722. LT: /^LT\-\d{5}$/,
  4723. LU: fourDigit,
  4724. LV: /^LV\-\d{4}$/,
  4725. LK: fiveDigit,
  4726. MG: threeDigit,
  4727. MX: fiveDigit,
  4728. MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
  4729. MY: fiveDigit,
  4730. NL: /^[1-9]\d{3}\s?(?!sa|sd|ss)[a-z]{2}$/i,
  4731. NO: fourDigit,
  4732. NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
  4733. NZ: fourDigit,
  4734. // https://www.pakpost.gov.pk/postcodes.php
  4735. PK: fiveDigit,
  4736. PL: /^\d{2}\-\d{3}$/,
  4737. PR: /^00[679]\d{2}([ -]\d{4})?$/,
  4738. PT: /^\d{4}\-\d{3}?$/,
  4739. RO: sixDigit,
  4740. RU: sixDigit,
  4741. SA: fiveDigit,
  4742. SE: /^[1-9]\d{2}\s?\d{2}$/,
  4743. SG: sixDigit,
  4744. SI: fourDigit,
  4745. SK: /^\d{3}\s?\d{2}$/,
  4746. TH: fiveDigit,
  4747. TN: fourDigit,
  4748. TW: /^\d{3}(\d{2,3})?$/,
  4749. UA: fiveDigit,
  4750. US: /^\d{5}(-\d{4})?$/,
  4751. ZA: fourDigit,
  4752. ZM: fiveDigit
  4753. };
  4754. var locales$6 = Object.keys(patterns);
  4755. function isPostalCode(str, locale) {
  4756. assertString(str);
  4757. if (locale in patterns) {
  4758. return patterns[locale].test(str);
  4759. } else if (locale === 'any') {
  4760. for (var key in patterns) {
  4761. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  4762. // istanbul ignore else
  4763. if (patterns.hasOwnProperty(key)) {
  4764. var pattern = patterns[key];
  4765. if (pattern.test(str)) {
  4766. return true;
  4767. }
  4768. }
  4769. }
  4770. return false;
  4771. }
  4772. throw new Error("Invalid locale '".concat(locale, "'"));
  4773. }
  4774. function escape(str) {
  4775. assertString(str);
  4776. 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;');
  4777. }
  4778. function unescape(str) {
  4779. assertString(str);
  4780. 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, '&');
  4781. // &amp; replacement has to be the last one to prevent
  4782. // bugs with intermediate strings containing escape sequences
  4783. // See: https://github.com/validatorjs/validator.js/issues/1827
  4784. }
  4785. function blacklist$1(str, chars) {
  4786. assertString(str);
  4787. return str.replace(new RegExp("[".concat(chars, "]+"), 'g'), '');
  4788. }
  4789. function stripLow(str, keep_new_lines) {
  4790. assertString(str);
  4791. var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
  4792. return blacklist$1(str, chars);
  4793. }
  4794. function whitelist(str, chars) {
  4795. assertString(str);
  4796. return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), '');
  4797. }
  4798. function isWhitelisted(str, chars) {
  4799. assertString(str);
  4800. for (var i = str.length - 1; i >= 0; i--) {
  4801. if (chars.indexOf(str[i]) === -1) {
  4802. return false;
  4803. }
  4804. }
  4805. return true;
  4806. }
  4807. var default_normalize_email_options = {
  4808. // The following options apply to all email addresses
  4809. // Lowercases the local part of the email address.
  4810. // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
  4811. // The domain is always lowercased, as per RFC 1035
  4812. all_lowercase: true,
  4813. // The following conversions are specific to GMail
  4814. // Lowercases the local part of the GMail address (known to be case-insensitive)
  4815. gmail_lowercase: true,
  4816. // Removes dots from the local part of the email address, as that's ignored by GMail
  4817. gmail_remove_dots: true,
  4818. // Removes the subaddress (e.g. "+foo") from the email address
  4819. gmail_remove_subaddress: true,
  4820. // Conversts the googlemail.com domain to gmail.com
  4821. gmail_convert_googlemaildotcom: true,
  4822. // The following conversions are specific to Outlook.com / Windows Live / Hotmail
  4823. // Lowercases the local part of the Outlook.com address (known to be case-insensitive)
  4824. outlookdotcom_lowercase: true,
  4825. // Removes the subaddress (e.g. "+foo") from the email address
  4826. outlookdotcom_remove_subaddress: true,
  4827. // The following conversions are specific to Yahoo
  4828. // Lowercases the local part of the Yahoo address (known to be case-insensitive)
  4829. yahoo_lowercase: true,
  4830. // Removes the subaddress (e.g. "-foo") from the email address
  4831. yahoo_remove_subaddress: true,
  4832. // The following conversions are specific to Yandex
  4833. // Lowercases the local part of the Yandex address (known to be case-insensitive)
  4834. yandex_lowercase: true,
  4835. // all yandex domains are equal, this explicitly sets the domain to 'yandex.ru'
  4836. yandex_convert_yandexru: true,
  4837. // The following conversions are specific to iCloud
  4838. // Lowercases the local part of the iCloud address (known to be case-insensitive)
  4839. icloud_lowercase: true,
  4840. // Removes the subaddress (e.g. "+foo") from the email address
  4841. icloud_remove_subaddress: true
  4842. };
  4843. // List of domains used by iCloud
  4844. var icloud_domains = ['icloud.com', 'me.com'];
  4845. // List of domains used by Outlook.com and its predecessors
  4846. // This list is likely incomplete.
  4847. // Partial reference:
  4848. // https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/
  4849. 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'];
  4850. // List of domains used by Yahoo Mail
  4851. // This list is likely incomplete
  4852. var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];
  4853. // List of domains used by yandex.ru
  4854. var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];
  4855. // replace single dots, but not multiple consecutive dots
  4856. function dotsReplacer(match) {
  4857. if (match.length > 1) {
  4858. return match;
  4859. }
  4860. return '';
  4861. }
  4862. function normalizeEmail(email, options) {
  4863. options = merge(options, default_normalize_email_options);
  4864. var raw_parts = email.split('@');
  4865. var domain = raw_parts.pop();
  4866. var user = raw_parts.join('@');
  4867. var parts = [user, domain];
  4868. // The domain is always lowercased, as it's case-insensitive per RFC 1035
  4869. parts[1] = parts[1].toLowerCase();
  4870. if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
  4871. // Address is GMail
  4872. if (options.gmail_remove_subaddress) {
  4873. parts[0] = parts[0].split('+')[0];
  4874. }
  4875. if (options.gmail_remove_dots) {
  4876. // this does not replace consecutive dots like example..email@gmail.com
  4877. parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
  4878. }
  4879. if (!parts[0].length) {
  4880. return false;
  4881. }
  4882. if (options.all_lowercase || options.gmail_lowercase) {
  4883. parts[0] = parts[0].toLowerCase();
  4884. }
  4885. parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
  4886. } else if (icloud_domains.indexOf(parts[1]) >= 0) {
  4887. // Address is iCloud
  4888. if (options.icloud_remove_subaddress) {
  4889. parts[0] = parts[0].split('+')[0];
  4890. }
  4891. if (!parts[0].length) {
  4892. return false;
  4893. }
  4894. if (options.all_lowercase || options.icloud_lowercase) {
  4895. parts[0] = parts[0].toLowerCase();
  4896. }
  4897. } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) {
  4898. // Address is Outlook.com
  4899. if (options.outlookdotcom_remove_subaddress) {
  4900. parts[0] = parts[0].split('+')[0];
  4901. }
  4902. if (!parts[0].length) {
  4903. return false;
  4904. }
  4905. if (options.all_lowercase || options.outlookdotcom_lowercase) {
  4906. parts[0] = parts[0].toLowerCase();
  4907. }
  4908. } else if (yahoo_domains.indexOf(parts[1]) >= 0) {
  4909. // Address is Yahoo
  4910. if (options.yahoo_remove_subaddress) {
  4911. var components = parts[0].split('-');
  4912. parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
  4913. }
  4914. if (!parts[0].length) {
  4915. return false;
  4916. }
  4917. if (options.all_lowercase || options.yahoo_lowercase) {
  4918. parts[0] = parts[0].toLowerCase();
  4919. }
  4920. } else if (yandex_domains.indexOf(parts[1]) >= 0) {
  4921. if (options.all_lowercase || options.yandex_lowercase) {
  4922. parts[0] = parts[0].toLowerCase();
  4923. }
  4924. parts[1] = options.yandex_convert_yandexru ? 'yandex.ru' : parts[1];
  4925. } else if (options.all_lowercase) {
  4926. // Any other address
  4927. parts[0] = parts[0].toLowerCase();
  4928. }
  4929. return parts.join('@');
  4930. }
  4931. var charsetRegex = /^[^\s-_](?!.*?[-_]{2,})[a-z0-9-\\][^\s]*[^-_\s]$/;
  4932. function isSlug(str) {
  4933. assertString(str);
  4934. return charsetRegex.test(str);
  4935. }
  4936. var validators$1 = {
  4937. 'cs-CZ': function csCZ(str) {
  4938. return /^(([ABCDEFHIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str);
  4939. },
  4940. 'de-DE': function deDE(str) {
  4941. 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);
  4942. },
  4943. 'de-LI': function deLI(str) {
  4944. return /^FL[- ]?\d{1,5}[UZ]?$/.test(str);
  4945. },
  4946. 'en-IN': function enIN(str) {
  4947. return /^[A-Z]{2}[ -]?[0-9]{1,2}(?:[ -]?[A-Z])(?:[ -]?[A-Z]*)?[ -]?[0-9]{4}$/.test(str);
  4948. },
  4949. 'en-SG': function enSG(str) {
  4950. return /^[A-Z]{3}[ -]?[\d]{4}[ -]?[A-Z]{1}$/.test(str);
  4951. },
  4952. 'es-AR': function esAR(str) {
  4953. return /^(([A-Z]{2} ?[0-9]{3} ?[A-Z]{2})|([A-Z]{3} ?[0-9]{3}))$/.test(str);
  4954. },
  4955. 'fi-FI': function fiFI(str) {
  4956. return /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str);
  4957. },
  4958. 'hu-HU': function huHU(str) {
  4959. 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);
  4960. },
  4961. 'pt-BR': function ptBR(str) {
  4962. return /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str);
  4963. },
  4964. 'pt-PT': function ptPT(str) {
  4965. return /^(([A-Z]{2}[ -·]?[0-9]{2}[ -·]?[0-9]{2})|([0-9]{2}[ -·]?[A-Z]{2}[ -·]?[0-9]{2})|([0-9]{2}[ -·]?[0-9]{2}[ -·]?[A-Z]{2})|([A-Z]{2}[ -·]?[0-9]{2}[ -·]?[A-Z]{2}))$/.test(str);
  4966. },
  4967. 'sq-AL': function sqAL(str) {
  4968. return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str);
  4969. },
  4970. 'sv-SE': function svSE(str) {
  4971. return /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim());
  4972. },
  4973. 'en-PK': function enPK(str) {
  4974. return /(^[A-Z]{2}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\s|-){0,1})[0-9]{4}((\s|-)[0-9]{2}){0,1}$)/.test(str.trim());
  4975. }
  4976. };
  4977. function isLicensePlate(str, locale) {
  4978. assertString(str);
  4979. if (locale in validators$1) {
  4980. return validators$1[locale](str);
  4981. } else if (locale === 'any') {
  4982. for (var key in validators$1) {
  4983. /* eslint guard-for-in: 0 */
  4984. var validator = validators$1[key];
  4985. if (validator(str)) {
  4986. return true;
  4987. }
  4988. }
  4989. return false;
  4990. }
  4991. throw new Error("Invalid locale '".concat(locale, "'"));
  4992. }
  4993. var upperCaseRegex = /^[A-Z]$/;
  4994. var lowerCaseRegex = /^[a-z]$/;
  4995. var numberRegex = /^[0-9]$/;
  4996. var symbolRegex = /^[-#!$@£%^&*()_+|~=`{}\[\]:";'<>?,.\/\\ ]$/;
  4997. var defaultOptions$1 = {
  4998. minLength: 8,
  4999. minLowercase: 1,
  5000. minUppercase: 1,
  5001. minNumbers: 1,
  5002. minSymbols: 1,
  5003. returnScore: false,
  5004. pointsPerUnique: 1,
  5005. pointsPerRepeat: 0.5,
  5006. pointsForContainingLower: 10,
  5007. pointsForContainingUpper: 10,
  5008. pointsForContainingNumber: 10,
  5009. pointsForContainingSymbol: 10
  5010. };
  5011. /* Counts number of occurrences of each char in a string
  5012. * could be moved to util/ ?
  5013. */
  5014. function countChars(str) {
  5015. var result = {};
  5016. Array.from(str).forEach(function (_char) {
  5017. var curVal = result[_char];
  5018. if (curVal) {
  5019. result[_char] += 1;
  5020. } else {
  5021. result[_char] = 1;
  5022. }
  5023. });
  5024. return result;
  5025. }
  5026. /* Return information about a password */
  5027. function analyzePassword(password) {
  5028. var charMap = countChars(password);
  5029. var analysis = {
  5030. length: password.length,
  5031. uniqueChars: Object.keys(charMap).length,
  5032. uppercaseCount: 0,
  5033. lowercaseCount: 0,
  5034. numberCount: 0,
  5035. symbolCount: 0
  5036. };
  5037. Object.keys(charMap).forEach(function (_char2) {
  5038. /* istanbul ignore else */
  5039. if (upperCaseRegex.test(_char2)) {
  5040. analysis.uppercaseCount += charMap[_char2];
  5041. } else if (lowerCaseRegex.test(_char2)) {
  5042. analysis.lowercaseCount += charMap[_char2];
  5043. } else if (numberRegex.test(_char2)) {
  5044. analysis.numberCount += charMap[_char2];
  5045. } else if (symbolRegex.test(_char2)) {
  5046. analysis.symbolCount += charMap[_char2];
  5047. }
  5048. });
  5049. return analysis;
  5050. }
  5051. function scorePassword(analysis, scoringOptions) {
  5052. var points = 0;
  5053. points += analysis.uniqueChars * scoringOptions.pointsPerUnique;
  5054. points += (analysis.length - analysis.uniqueChars) * scoringOptions.pointsPerRepeat;
  5055. if (analysis.lowercaseCount > 0) {
  5056. points += scoringOptions.pointsForContainingLower;
  5057. }
  5058. if (analysis.uppercaseCount > 0) {
  5059. points += scoringOptions.pointsForContainingUpper;
  5060. }
  5061. if (analysis.numberCount > 0) {
  5062. points += scoringOptions.pointsForContainingNumber;
  5063. }
  5064. if (analysis.symbolCount > 0) {
  5065. points += scoringOptions.pointsForContainingSymbol;
  5066. }
  5067. return points;
  5068. }
  5069. function isStrongPassword(str) {
  5070. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  5071. assertString(str);
  5072. var analysis = analyzePassword(str);
  5073. options = merge(options || {}, defaultOptions$1);
  5074. if (options.returnScore) {
  5075. return scorePassword(analysis, options);
  5076. }
  5077. return analysis.length >= options.minLength && analysis.lowercaseCount >= options.minLowercase && analysis.uppercaseCount >= options.minUppercase && analysis.numberCount >= options.minNumbers && analysis.symbolCount >= options.minSymbols;
  5078. }
  5079. var AU = function AU(str) {
  5080. var match = str.match(/^(AU)?(\d{11})$/);
  5081. if (!match) {
  5082. return false;
  5083. }
  5084. // @see {@link https://abr.business.gov.au/Help/AbnFormat}
  5085. var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
  5086. str = str.replace(/^AU/, '');
  5087. var ABN = (parseInt(str.slice(0, 1), 10) - 1).toString() + str.slice(1);
  5088. var total = 0;
  5089. for (var i = 0; i < 11; i++) {
  5090. total += weights[i] * ABN.charAt(i);
  5091. }
  5092. return total !== 0 && total % 89 === 0;
  5093. };
  5094. var CH = function CH(str) {
  5095. // @see {@link https://www.ech.ch/de/ech/ech-0097/5.2.0}
  5096. var hasValidCheckNumber = function hasValidCheckNumber(digits) {
  5097. var lastDigit = digits.pop(); // used as check number
  5098. var weights = [5, 4, 3, 2, 7, 6, 5, 4];
  5099. var calculatedCheckNumber = (11 - digits.reduce(function (acc, el, idx) {
  5100. return acc + el * weights[idx];
  5101. }, 0) % 11) % 11;
  5102. return lastDigit === calculatedCheckNumber;
  5103. };
  5104. // @see {@link https://www.estv.admin.ch/estv/de/home/mehrwertsteuer/uid/mwst-uid-nummer.html}
  5105. return /^(CHE[- ]?)?(\d{9}|(\d{3}\.\d{3}\.\d{3})|(\d{3} \d{3} \d{3})) ?(TVA|MWST|IVA)?$/.test(str) && hasValidCheckNumber(str.match(/\d/g).map(function (el) {
  5106. return +el;
  5107. }));
  5108. };
  5109. var PT = function PT(str) {
  5110. var match = str.match(/^(PT)?(\d{9})$/);
  5111. if (!match) {
  5112. return false;
  5113. }
  5114. var tin = match[2];
  5115. var checksum = 11 - reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
  5116. return parseInt(a, 10);
  5117. }), 9) % 11;
  5118. if (checksum > 9) {
  5119. return parseInt(tin[8], 10) === 0;
  5120. }
  5121. return checksum === parseInt(tin[8], 10);
  5122. };
  5123. var vatMatchers = {
  5124. /**
  5125. * European Union VAT identification numbers
  5126. */
  5127. AT: function AT(str) {
  5128. return /^(AT)?U\d{8}$/.test(str);
  5129. },
  5130. BE: function BE(str) {
  5131. return /^(BE)?\d{10}$/.test(str);
  5132. },
  5133. BG: function BG(str) {
  5134. return /^(BG)?\d{9,10}$/.test(str);
  5135. },
  5136. HR: function HR(str) {
  5137. return /^(HR)?\d{11}$/.test(str);
  5138. },
  5139. CY: function CY(str) {
  5140. return /^(CY)?\w{9}$/.test(str);
  5141. },
  5142. CZ: function CZ(str) {
  5143. return /^(CZ)?\d{8,10}$/.test(str);
  5144. },
  5145. DK: function DK(str) {
  5146. return /^(DK)?\d{8}$/.test(str);
  5147. },
  5148. EE: function EE(str) {
  5149. return /^(EE)?\d{9}$/.test(str);
  5150. },
  5151. FI: function FI(str) {
  5152. return /^(FI)?\d{8}$/.test(str);
  5153. },
  5154. FR: function FR(str) {
  5155. return /^(FR)([A-Z0-9]{2}\d{9})$/.test(str);
  5156. },
  5157. DE: function DE(str) {
  5158. return /^(DE)?\d{9}$/.test(str);
  5159. },
  5160. EL: function EL(str) {
  5161. return /^(EL)?\d{9}$/.test(str);
  5162. },
  5163. HU: function HU(str) {
  5164. return /^(HU)?\d{8}$/.test(str);
  5165. },
  5166. IE: function IE(str) {
  5167. return /^(IE)?\d{7}\w{1}(W)?$/.test(str);
  5168. },
  5169. IT: function IT(str) {
  5170. return /^(IT)?\d{11}$/.test(str);
  5171. },
  5172. LV: function LV(str) {
  5173. return /^(LV)?\d{11}$/.test(str);
  5174. },
  5175. LT: function LT(str) {
  5176. return /^(LT)?\d{9,12}$/.test(str);
  5177. },
  5178. LU: function LU(str) {
  5179. return /^(LU)?\d{8}$/.test(str);
  5180. },
  5181. MT: function MT(str) {
  5182. return /^(MT)?\d{8}$/.test(str);
  5183. },
  5184. NL: function NL(str) {
  5185. return /^(NL)?\d{9}B\d{2}$/.test(str);
  5186. },
  5187. PL: function PL(str) {
  5188. return /^(PL)?(\d{10}|(\d{3}-\d{3}-\d{2}-\d{2})|(\d{3}-\d{2}-\d{2}-\d{3}))$/.test(str);
  5189. },
  5190. PT: PT,
  5191. RO: function RO(str) {
  5192. return /^(RO)?\d{2,10}$/.test(str);
  5193. },
  5194. SK: function SK(str) {
  5195. return /^(SK)?\d{10}$/.test(str);
  5196. },
  5197. SI: function SI(str) {
  5198. return /^(SI)?\d{8}$/.test(str);
  5199. },
  5200. ES: function ES(str) {
  5201. return /^(ES)?\w\d{7}[A-Z]$/.test(str);
  5202. },
  5203. SE: function SE(str) {
  5204. return /^(SE)?\d{12}$/.test(str);
  5205. },
  5206. /**
  5207. * VAT numbers of non-EU countries
  5208. */
  5209. AL: function AL(str) {
  5210. return /^(AL)?\w{9}[A-Z]$/.test(str);
  5211. },
  5212. MK: function MK(str) {
  5213. return /^(MK)?\d{13}$/.test(str);
  5214. },
  5215. AU: AU,
  5216. BY: function BY(str) {
  5217. return /^(УНП )?\d{9}$/.test(str);
  5218. },
  5219. CA: function CA(str) {
  5220. return /^(CA)?\d{9}$/.test(str);
  5221. },
  5222. IS: function IS(str) {
  5223. return /^(IS)?\d{5,6}$/.test(str);
  5224. },
  5225. IN: function IN(str) {
  5226. return /^(IN)?\d{15}$/.test(str);
  5227. },
  5228. ID: function ID(str) {
  5229. return /^(ID)?(\d{15}|(\d{2}.\d{3}.\d{3}.\d{1}-\d{3}.\d{3}))$/.test(str);
  5230. },
  5231. IL: function IL(str) {
  5232. return /^(IL)?\d{9}$/.test(str);
  5233. },
  5234. KZ: function KZ(str) {
  5235. return /^(KZ)?\d{12}$/.test(str);
  5236. },
  5237. NZ: function NZ(str) {
  5238. return /^(NZ)?\d{9}$/.test(str);
  5239. },
  5240. NG: function NG(str) {
  5241. return /^(NG)?(\d{12}|(\d{8}-\d{4}))$/.test(str);
  5242. },
  5243. NO: function NO(str) {
  5244. return /^(NO)?\d{9}MVA$/.test(str);
  5245. },
  5246. PH: function PH(str) {
  5247. return /^(PH)?(\d{12}|\d{3} \d{3} \d{3} \d{3})$/.test(str);
  5248. },
  5249. RU: function RU(str) {
  5250. return /^(RU)?(\d{10}|\d{12})$/.test(str);
  5251. },
  5252. SM: function SM(str) {
  5253. return /^(SM)?\d{5}$/.test(str);
  5254. },
  5255. SA: function SA(str) {
  5256. return /^(SA)?\d{15}$/.test(str);
  5257. },
  5258. RS: function RS(str) {
  5259. return /^(RS)?\d{9}$/.test(str);
  5260. },
  5261. CH: CH,
  5262. TR: function TR(str) {
  5263. return /^(TR)?\d{10}$/.test(str);
  5264. },
  5265. UA: function UA(str) {
  5266. return /^(UA)?\d{12}$/.test(str);
  5267. },
  5268. GB: function GB(str) {
  5269. 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);
  5270. },
  5271. UZ: function UZ(str) {
  5272. return /^(UZ)?\d{9}$/.test(str);
  5273. },
  5274. /**
  5275. * VAT numbers of Latin American countries
  5276. */
  5277. AR: function AR(str) {
  5278. return /^(AR)?\d{11}$/.test(str);
  5279. },
  5280. BO: function BO(str) {
  5281. return /^(BO)?\d{7}$/.test(str);
  5282. },
  5283. BR: function BR(str) {
  5284. return /^(BR)?((\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})|(\d{3}.\d{3}.\d{3}-\d{2}))$/.test(str);
  5285. },
  5286. CL: function CL(str) {
  5287. return /^(CL)?\d{8}-\d{1}$/.test(str);
  5288. },
  5289. CO: function CO(str) {
  5290. return /^(CO)?\d{10}$/.test(str);
  5291. },
  5292. CR: function CR(str) {
  5293. return /^(CR)?\d{9,12}$/.test(str);
  5294. },
  5295. EC: function EC(str) {
  5296. return /^(EC)?\d{13}$/.test(str);
  5297. },
  5298. SV: function SV(str) {
  5299. return /^(SV)?\d{4}-\d{6}-\d{3}-\d{1}$/.test(str);
  5300. },
  5301. GT: function GT(str) {
  5302. return /^(GT)?\d{7}-\d{1}$/.test(str);
  5303. },
  5304. HN: function HN(str) {
  5305. return /^(HN)?$/.test(str);
  5306. },
  5307. MX: function MX(str) {
  5308. return /^(MX)?\w{3,4}\d{6}\w{3}$/.test(str);
  5309. },
  5310. NI: function NI(str) {
  5311. return /^(NI)?\d{3}-\d{6}-\d{4}\w{1}$/.test(str);
  5312. },
  5313. PA: function PA(str) {
  5314. return /^(PA)?$/.test(str);
  5315. },
  5316. PY: function PY(str) {
  5317. return /^(PY)?\d{6,8}-\d{1}$/.test(str);
  5318. },
  5319. PE: function PE(str) {
  5320. return /^(PE)?\d{11}$/.test(str);
  5321. },
  5322. DO: function DO(str) {
  5323. 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);
  5324. },
  5325. UY: function UY(str) {
  5326. return /^(UY)?\d{12}$/.test(str);
  5327. },
  5328. VE: function VE(str) {
  5329. return /^(VE)?[J,G,V,E]{1}-(\d{9}|(\d{8}-\d{1}))$/.test(str);
  5330. }
  5331. };
  5332. function isVAT(str, countryCode) {
  5333. assertString(str);
  5334. assertString(countryCode);
  5335. if (countryCode in vatMatchers) {
  5336. return vatMatchers[countryCode](str);
  5337. }
  5338. throw new Error("Invalid country code: '".concat(countryCode, "'"));
  5339. }
  5340. var version = '13.15.26';
  5341. var validator = {
  5342. version: version,
  5343. toDate: toDate,
  5344. toFloat: toFloat,
  5345. toInt: toInt,
  5346. toBoolean: toBoolean,
  5347. equals: equals,
  5348. contains: contains,
  5349. matches: matches,
  5350. isEmail: isEmail,
  5351. isURL: isURL,
  5352. isMACAddress: isMACAddress,
  5353. isIP: isIP,
  5354. isIPRange: isIPRange,
  5355. isFQDN: isFQDN,
  5356. isBoolean: isBoolean,
  5357. isIBAN: isIBAN,
  5358. isBIC: isBIC,
  5359. isAbaRouting: isAbaRouting,
  5360. isAlpha: isAlpha,
  5361. isAlphaLocales: locales$1,
  5362. isAlphanumeric: isAlphanumeric,
  5363. isAlphanumericLocales: locales$2,
  5364. isNumeric: isNumeric,
  5365. isPassportNumber: isPassportNumber,
  5366. passportNumberLocales: locales$3,
  5367. isPort: isPort,
  5368. isLowercase: isLowercase,
  5369. isUppercase: isUppercase,
  5370. isAscii: isAscii,
  5371. isFullWidth: isFullWidth,
  5372. isHalfWidth: isHalfWidth,
  5373. isVariableWidth: isVariableWidth,
  5374. isMultibyte: isMultibyte,
  5375. isSemVer: isSemVer,
  5376. isSurrogatePair: isSurrogatePair,
  5377. isInt: isInt,
  5378. isIMEI: isIMEI,
  5379. isFloat: isFloat,
  5380. isFloatLocales: locales,
  5381. isDecimal: isDecimal,
  5382. isHexadecimal: isHexadecimal,
  5383. isOctal: isOctal,
  5384. isDivisibleBy: isDivisibleBy,
  5385. isHexColor: isHexColor,
  5386. isRgbColor: isRgbColor,
  5387. isHSL: isHSL,
  5388. isISRC: isISRC,
  5389. isMD5: isMD5,
  5390. isHash: isHash,
  5391. isJWT: isJWT,
  5392. isJSON: isJSON,
  5393. isEmpty: isEmpty,
  5394. isLength: isLength,
  5395. isLocale: isLocale,
  5396. isByteLength: isByteLength,
  5397. isULID: isULID,
  5398. isUUID: isUUID,
  5399. isMongoId: isMongoId,
  5400. isAfter: isAfter,
  5401. isBefore: isBefore,
  5402. isIn: isIn,
  5403. isLuhnNumber: isLuhnNumber,
  5404. isCreditCard: isCreditCard,
  5405. isIdentityCard: isIdentityCard,
  5406. isEAN: isEAN,
  5407. isISIN: isISIN,
  5408. isISBN: isISBN,
  5409. isISSN: isISSN,
  5410. isMobilePhone: isMobilePhone,
  5411. isMobilePhoneLocales: locales$5,
  5412. isPostalCode: isPostalCode,
  5413. isPostalCodeLocales: locales$6,
  5414. isEthereumAddress: isEthereumAddress,
  5415. isCurrency: isCurrency,
  5416. isBtcAddress: isBtcAddress,
  5417. isISO6346: isISO6346,
  5418. isFreightContainerID: isFreightContainerID,
  5419. isISO6391: isISO6391,
  5420. isISO8601: isISO8601,
  5421. isISO15924: isISO15924,
  5422. isRFC3339: isRFC3339,
  5423. isISO31661Alpha2: isISO31661Alpha2,
  5424. isISO31661Alpha3: isISO31661Alpha3,
  5425. isISO31661Numeric: isISO31661Numeric,
  5426. isISO4217: isISO4217,
  5427. isBase32: isBase32,
  5428. isBase58: isBase58,
  5429. isBase64: isBase64,
  5430. isDataURI: isDataURI,
  5431. isMagnetURI: isMagnetURI,
  5432. isMailtoURI: isMailtoURI,
  5433. isMimeType: isMimeType,
  5434. isLatLong: isLatLong,
  5435. ltrim: ltrim,
  5436. rtrim: rtrim,
  5437. trim: trim,
  5438. escape: escape,
  5439. unescape: unescape,
  5440. stripLow: stripLow,
  5441. whitelist: whitelist,
  5442. blacklist: blacklist$1,
  5443. isWhitelisted: isWhitelisted,
  5444. normalizeEmail: normalizeEmail,
  5445. toString: toString,
  5446. isSlug: isSlug,
  5447. isStrongPassword: isStrongPassword,
  5448. isTaxID: isTaxID,
  5449. isDate: isDate,
  5450. isTime: isTime,
  5451. isLicensePlate: isLicensePlate,
  5452. isVAT: isVAT,
  5453. ibanLocales: locales$4
  5454. };
  5455. return validator;
  5456. })));