formValidation.js 361 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360
  1. /*!
  2. * FormValidation (http://formvalidation.io)
  3. * The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit and custom frameworks
  4. *
  5. * @version v0.6.2-dev, built on 2015-03-13 8:15:45 AM
  6. * @author https://twitter.com/nghuuphuoc
  7. * @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
  8. * @license http://formvalidation.io/license/
  9. */
  10. // Register the namespace
  11. window.FormValidation = {
  12. AddOn: {}, // Add-ons
  13. Framework: {}, // Supported frameworks
  14. I18n: {}, // i18n
  15. Validator: {} // Available validators
  16. };
  17. if (typeof jQuery === 'undefined') {
  18. throw new Error('FormValidation requires jQuery');
  19. }
  20. (function($) {
  21. var version = $.fn.jquery.split(' ')[0].split('.');
  22. if ((+version[0] < 2 && +version[1] < 9) || (+version[0] === 1 && +version[1] === 9 && +version[2] < 1)) {
  23. throw new Error('FormValidation requires jQuery version 1.9.1 or higher');
  24. }
  25. }(jQuery));
  26. (function($) {
  27. // TODO: Remove backward compatibility in v0.7.0
  28. /**
  29. * Constructor
  30. *
  31. * @param {jQuery|String} form The form element or selector
  32. * @param {Object} options The options
  33. * @param {String} [namespace] The optional namespace which is used for data-{namespace}-xxx attributes and internal data.
  34. * Currently, it's used to support backward version
  35. * @constructor
  36. */
  37. FormValidation.Base = function(form, options, namespace) {
  38. this.$form = $(form);
  39. this.options = $.extend({}, $.fn.formValidation.DEFAULT_OPTIONS, options);
  40. this._namespace = namespace || 'fv';
  41. this.$invalidFields = $([]); // Array of invalid fields
  42. this.$submitButton = null; // The submit button which is clicked to submit form
  43. this.$hiddenButton = null;
  44. // Validating status
  45. this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
  46. this.STATUS_VALIDATING = 'VALIDATING';
  47. this.STATUS_INVALID = 'INVALID';
  48. this.STATUS_VALID = 'VALID';
  49. this.STATUS_IGNORED = 'IGNORED';
  50. // Determine the event that is fired when user change the field value
  51. // Most modern browsers supports input event except IE 7, 8.
  52. // IE 9 supports input event but the event is still not fired if I press the backspace key.
  53. // Get IE version
  54. // https://gist.github.com/padolsey/527683/#comment-7595
  55. var ieVersion = (function() {
  56. var v = 3, div = document.createElement('div'), a = div.all || [];
  57. while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]) {}
  58. return v > 4 ? v : !v;
  59. }());
  60. var el = document.createElement('div');
  61. this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';
  62. // The flag to indicate that the form is ready to submit when a remote/callback validator returns
  63. this._submitIfValid = null;
  64. // Field elements
  65. this._cacheFields = {};
  66. this._init();
  67. };
  68. FormValidation.Base.prototype = {
  69. constructor: FormValidation.Base,
  70. /**
  71. * Check if the number of characters of field value exceed the threshold or not
  72. *
  73. * @param {jQuery} $field The field element
  74. * @returns {Boolean}
  75. */
  76. _exceedThreshold: function($field) {
  77. var ns = this._namespace,
  78. field = $field.attr('data-' + ns + '-field'),
  79. threshold = this.options.fields[field].threshold || this.options.threshold;
  80. if (!threshold) {
  81. return true;
  82. }
  83. var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
  84. return (cannotType || $field.val().length >= threshold);
  85. },
  86. /**
  87. * Init form
  88. */
  89. _init: function() {
  90. var that = this,
  91. ns = this._namespace,
  92. options = {
  93. addOns: {},
  94. autoFocus: this.$form.attr('data-' + ns + '-autofocus'),
  95. button: {
  96. selector: this.$form.attr('data-' + ns + '-button-selector') || this.$form.attr('data-' + ns + '-submitbuttons'), // Support backward
  97. disabled: this.$form.attr('data-' + ns + '-button-disabled')
  98. },
  99. control: {
  100. valid: this.$form.attr('data-' + ns + '-control-valid'),
  101. invalid: this.$form.attr('data-' + ns + '-control-invalid')
  102. },
  103. err: {
  104. clazz: this.$form.attr('data-' + ns + '-err-clazz'),
  105. container: this.$form.attr('data-' + ns + '-err-container') || this.$form.attr('data-' + ns + '-container'), // Support backward
  106. parent: this.$form.attr('data-' + ns + '-err-parent')
  107. },
  108. events: {
  109. formInit: this.$form.attr('data-' + ns + '-events-form-init'),
  110. formError: this.$form.attr('data-' + ns + '-events-form-error'),
  111. formSuccess: this.$form.attr('data-' + ns + '-events-form-success'),
  112. fieldAdded: this.$form.attr('data-' + ns + '-events-field-added'),
  113. fieldRemoved: this.$form.attr('data-' + ns + '-events-field-removed'),
  114. fieldInit: this.$form.attr('data-' + ns + '-events-field-init'),
  115. fieldError: this.$form.attr('data-' + ns + '-events-field-error'),
  116. fieldSuccess: this.$form.attr('data-' + ns + '-events-field-success'),
  117. fieldStatus: this.$form.attr('data-' + ns + '-events-field-status'),
  118. localeChanged: this.$form.attr('data-' + ns + '-events-locale-changed'),
  119. validatorError: this.$form.attr('data-' + ns + '-events-validator-error'),
  120. validatorSuccess: this.$form.attr('data-' + ns + '-events-validator-success'),
  121. validatorIgnored: this.$form.attr('data-' + ns + '-events-validator-ignored')
  122. },
  123. excluded: this.$form.attr('data-' + ns + '-excluded'),
  124. icon: {
  125. valid: this.$form.attr('data-' + ns + '-icon-valid') || this.$form.attr('data-' + ns + '-feedbackicons-valid'), // Support backward
  126. invalid: this.$form.attr('data-' + ns + '-icon-invalid') || this.$form.attr('data-' + ns + '-feedbackicons-invalid'), // Support backward
  127. validating: this.$form.attr('data-' + ns + '-icon-validating') || this.$form.attr('data-' + ns + '-feedbackicons-validating'), // Support backward
  128. feedback: this.$form.attr('data-' + ns + '-icon-feedback')
  129. },
  130. live: this.$form.attr('data-' + ns + '-live'),
  131. locale: this.$form.attr('data-' + ns + '-locale'),
  132. message: this.$form.attr('data-' + ns + '-message'),
  133. onError: this.$form.attr('data-' + ns + '-onerror'),
  134. onSuccess: this.$form.attr('data-' + ns + '-onsuccess'),
  135. row: {
  136. selector: this.$form.attr('data-' + ns + '-row-selector') || this.$form.attr('data-' + ns + '-group'), // Support backward
  137. valid: this.$form.attr('data-' + ns + '-row-valid'),
  138. invalid: this.$form.attr('data-' + ns + '-row-invalid'),
  139. feedback: this.$form.attr('data-' + ns + '-row-feedback')
  140. },
  141. threshold: this.$form.attr('data-' + ns + '-threshold'),
  142. trigger: this.$form.attr('data-' + ns + '-trigger'),
  143. verbose: this.$form.attr('data-' + ns + '-verbose'),
  144. fields: {}
  145. };
  146. this.$form
  147. // Disable client side validation in HTML 5
  148. .attr('novalidate', 'novalidate')
  149. .addClass(this.options.elementClass)
  150. // Disable the default submission first
  151. .on('submit.' + ns, function(e) {
  152. e.preventDefault();
  153. that.validate();
  154. })
  155. .on('click.' + ns, this.options.button.selector, function() {
  156. that.$submitButton = $(this);
  157. // The user just click the submit button
  158. that._submitIfValid = true;
  159. });
  160. if (this.options.declarative === true || this.options.declarative === 'true') {
  161. // Find all fields which have either "name" or "data-{namespace}-field" attribute
  162. this.$form
  163. .find('[name], [data-' + ns + '-field]')
  164. .each(function () {
  165. var $field = $(this),
  166. field = $field.attr('name') || $field.attr('data-' + ns + '-field'),
  167. opts = that._parseOptions($field);
  168. if (opts) {
  169. $field.attr('data-' + ns + '-field', field);
  170. options.fields[field] = $.extend({}, opts, options.fields[field]);
  171. }
  172. });
  173. }
  174. this.options = $.extend(true, this.options, options);
  175. // Normalize the err.parent option
  176. if ('string' === typeof this.options.err.parent) {
  177. this.options.err.parent = new RegExp(this.options.err.parent);
  178. }
  179. // Support backward
  180. if (this.options.container) {
  181. this.options.err.container = this.options.container;
  182. delete this.options.container;
  183. }
  184. if (this.options.feedbackIcons) {
  185. this.options.icon = $.extend(true, this.options.icon, this.options.feedbackIcons);
  186. delete this.options.feedbackIcons;
  187. }
  188. if (this.options.group) {
  189. this.options.row.selector = this.options.group;
  190. delete this.options.group;
  191. }
  192. if (this.options.submitButtons) {
  193. this.options.button.selector = this.options.submitButtons;
  194. delete this.options.submitButtons;
  195. }
  196. // If the locale is not found, reset it to default one
  197. if (!FormValidation.I18n[this.options.locale]) {
  198. this.options.locale = $.fn.formValidation.DEFAULT_OPTIONS.locale;
  199. }
  200. // Parse the add-on options from HTML attributes
  201. if (this.options.declarative === true || this.options.declarative === 'true') {
  202. this.options = $.extend(true, this.options, { addOns: this._parseAddOnOptions() });
  203. }
  204. // When pressing Enter on any field in the form, the first submit button will do its job.
  205. // The form then will be submitted.
  206. // I create a first hidden submit button
  207. this.$hiddenButton = $('<button/>')
  208. .attr('type', 'submit')
  209. .prependTo(this.$form)
  210. .addClass('fv-hidden-submit')
  211. .css({ display: 'none', width: 0, height: 0 });
  212. this.$form
  213. .on('click.' + this._namespace, '[type="submit"]', function(e) {
  214. // #746: Check if the button click handler returns false
  215. if (!e.isDefaultPrevented()) {
  216. var $target = $(e.target),
  217. // The button might contain HTML tag
  218. $button = $target.is('[type="submit"]') ? $target.eq(0) : $target.parent('[type="submit"]').eq(0);
  219. // Don't perform validation when clicking on the submit button/input
  220. // which aren't defined by the 'button.selector' option
  221. if (that.options.button.selector && !$button.is(that.options.button.selector) && !$button.is(that.$hiddenButton)) {
  222. that.$form.off('submit.' + that._namespace).submit();
  223. }
  224. }
  225. });
  226. for (var field in this.options.fields) {
  227. this._initField(field);
  228. }
  229. // Init the add-ons
  230. for (var addOn in this.options.addOns) {
  231. if ('function' === typeof FormValidation.AddOn[addOn].init) {
  232. FormValidation.AddOn[addOn].init(this, this.options.addOns[addOn]);
  233. }
  234. }
  235. this.$form.trigger($.Event(this.options.events.formInit), {
  236. bv: this, // Support backward
  237. fv: this,
  238. options: this.options
  239. });
  240. // Prepare the events
  241. if (this.options.onSuccess) {
  242. this.$form.on(this.options.events.formSuccess, function(e) {
  243. FormValidation.Helper.call(that.options.onSuccess, [e]);
  244. });
  245. }
  246. if (this.options.onError) {
  247. this.$form.on(this.options.events.formError, function(e) {
  248. FormValidation.Helper.call(that.options.onError, [e]);
  249. });
  250. }
  251. },
  252. /**
  253. * Init field
  254. *
  255. * @param {String|jQuery} field The field name or field element
  256. */
  257. _initField: function(field) {
  258. var ns = this._namespace,
  259. fields = $([]);
  260. switch (typeof field) {
  261. case 'object':
  262. fields = field;
  263. field = field.attr('data-' + ns + '-field');
  264. break;
  265. case 'string':
  266. fields = this.getFieldElements(field);
  267. fields.attr('data-' + ns + '-field', field);
  268. break;
  269. default:
  270. break;
  271. }
  272. // We don't need to validate non-existing fields
  273. if (fields.length === 0) {
  274. return;
  275. }
  276. if (this.options.fields[field] === null || this.options.fields[field].validators === null) {
  277. return;
  278. }
  279. var validatorName;
  280. for (validatorName in this.options.fields[field].validators) {
  281. if (!FormValidation.Validator[validatorName]) {
  282. delete this.options.fields[field].validators[validatorName];
  283. }
  284. }
  285. if (this.options.fields[field].enabled === null) {
  286. this.options.fields[field].enabled = true;
  287. }
  288. var that = this,
  289. total = fields.length,
  290. type = fields.attr('type'),
  291. updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
  292. trigger = this._getFieldTrigger(fields.eq(0)),
  293. events = $.map(trigger, function(item) {
  294. return item + '.update.' + ns;
  295. }).join(' ');
  296. for (var i = 0; i < total; i++) {
  297. var $field = fields.eq(i),
  298. row = this.options.fields[field].row || this.options.row.selector,
  299. $parent = $field.closest(row),
  300. // Allow user to indicate where the error messages are shown
  301. // Support backward
  302. container = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container))
  303. ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this)
  304. : (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container),
  305. $message = (container && container !== 'tooltip' && container !== 'popover') ? $(container) : this._getMessageContainer($field, row);
  306. if (container && container !== 'tooltip' && container !== 'popover') {
  307. $message.addClass(this.options.err.clazz);
  308. }
  309. // Remove all error messages and feedback icons
  310. $message.find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove();
  311. $parent.find('i[data-' + ns + '-icon-for="' + field + '"]').remove();
  312. // Whenever the user change the field value, mark it as not validated yet
  313. $field.off(events).on(events, function() {
  314. that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
  315. });
  316. // Create help block elements for showing the error messages
  317. $field.data(ns + '.messages', $message);
  318. for (validatorName in this.options.fields[field].validators) {
  319. $field.data(ns + '.result.' + validatorName, this.STATUS_NOT_VALIDATED);
  320. if (!updateAll || i === total - 1) {
  321. $('<small/>')
  322. .css('display', 'none')
  323. .addClass(this.options.err.clazz)
  324. .attr('data-' + ns + '-validator', validatorName)
  325. .attr('data-' + ns + '-for', field)
  326. .attr('data-' + ns + '-result', this.STATUS_NOT_VALIDATED)
  327. .html(this._getMessage(field, validatorName))
  328. .appendTo($message);
  329. }
  330. // Init the validator
  331. if ('function' === typeof FormValidation.Validator[validatorName].init) {
  332. FormValidation.Validator[validatorName].init(this, $field, this.options.fields[field].validators[validatorName]);
  333. }
  334. }
  335. // Prepare the feedback icons
  336. if (this.options.fields[field].icon !== false && this.options.fields[field].icon !== 'false'
  337. && this.options.icon
  338. && this.options.icon.valid && this.options.icon.invalid && this.options.icon.validating
  339. && (!updateAll || i === total - 1))
  340. {
  341. // $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid).addClass(this.options.row.feedback);
  342. // Keep error messages which are populated from back-end
  343. $parent.addClass(this.options.row.feedback);
  344. var $icon = $('<i/>')
  345. .css('display', 'none')
  346. .addClass(this.options.icon.feedback)
  347. .attr('data-' + ns + '-icon-for', field)
  348. .insertAfter($field);
  349. // Store the icon as a data of field element
  350. (!updateAll ? $field : fields).data(ns + '.icon', $icon);
  351. if ('tooltip' === container || 'popover' === container) {
  352. (!updateAll ? $field : fields)
  353. .on(this.options.events.fieldError, function() {
  354. $parent.addClass('fv-has-tooltip');
  355. })
  356. .on(this.options.events.fieldSuccess, function() {
  357. $parent.removeClass('fv-has-tooltip');
  358. });
  359. $field
  360. // Show tooltip/popover message when field gets focus
  361. .off('focus.container.' + ns)
  362. .on('focus.container.' + ns, function() {
  363. that._showTooltip($field, container);
  364. })
  365. // and hide them when losing focus
  366. .off('blur.container.' + ns)
  367. .on('blur.container.' + ns, function() {
  368. that._hideTooltip($field, container);
  369. });
  370. }
  371. if ('string' === typeof this.options.fields[field].icon && this.options.fields[field].icon !== 'true') {
  372. $icon.appendTo($(this.options.fields[field].icon));
  373. } else {
  374. this._fixIcon($field, $icon);
  375. }
  376. }
  377. }
  378. // Prepare the events
  379. fields
  380. .on(this.options.events.fieldSuccess, function(e, data) {
  381. var onSuccess = that.getOptions(data.field, null, 'onSuccess');
  382. if (onSuccess) {
  383. FormValidation.Helper.call(onSuccess, [e, data]);
  384. }
  385. })
  386. .on(this.options.events.fieldError, function(e, data) {
  387. var onError = that.getOptions(data.field, null, 'onError');
  388. if (onError) {
  389. FormValidation.Helper.call(onError, [e, data]);
  390. }
  391. })
  392. .on(this.options.events.fieldStatus, function(e, data) {
  393. var onStatus = that.getOptions(data.field, null, 'onStatus');
  394. if (onStatus) {
  395. FormValidation.Helper.call(onStatus, [e, data]);
  396. }
  397. })
  398. .on(this.options.events.validatorError, function(e, data) {
  399. var onError = that.getOptions(data.field, data.validator, 'onError');
  400. if (onError) {
  401. FormValidation.Helper.call(onError, [e, data]);
  402. }
  403. })
  404. .on(this.options.events.validatorSuccess, function(e, data) {
  405. var onSuccess = that.getOptions(data.field, data.validator, 'onSuccess');
  406. if (onSuccess) {
  407. FormValidation.Helper.call(onSuccess, [e, data]);
  408. }
  409. });
  410. // Set live mode
  411. this.onLiveChange(fields, 'live', function() {
  412. if (that._exceedThreshold($(this))) {
  413. that.validateField($(this));
  414. }
  415. });
  416. fields.trigger($.Event(this.options.events.fieldInit), {
  417. bv: this, // Support backward
  418. fv: this,
  419. field: field,
  420. element: fields
  421. });
  422. },
  423. /**
  424. * Check if the field is excluded.
  425. * Returning true means that the field will not be validated
  426. *
  427. * @param {jQuery} $field The field element
  428. * @returns {Boolean}
  429. */
  430. _isExcluded: function($field) {
  431. var ns = this._namespace,
  432. excludedAttr = $field.attr('data-' + ns + '-excluded'),
  433. // I still need to check the 'name' attribute while initializing the field
  434. field = $field.attr('data-' + ns + '-field') || $field.attr('name');
  435. switch (true) {
  436. case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'true' || this.options.fields[field].excluded === true)):
  437. case (excludedAttr === 'true'):
  438. case (excludedAttr === ''):
  439. return true;
  440. case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'false' || this.options.fields[field].excluded === false)):
  441. case (excludedAttr === 'false'):
  442. return false;
  443. case (!!field && this.options.fields && this.options.fields[field] && 'function' === typeof this.options.fields[field].excluded):
  444. return this.options.fields[field].excluded.call(this, $field, this);
  445. case (!!field && this.options.fields && this.options.fields[field] && 'string' === typeof this.options.fields[field].excluded):
  446. case (excludedAttr):
  447. return FormValidation.Helper.call(this.options.fields[field].excluded, [$field, this]);
  448. default:
  449. if (this.options.excluded) {
  450. // Convert to array first
  451. if ('string' === typeof this.options.excluded) {
  452. this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
  453. // Trim the spaces
  454. return $.trim(item);
  455. });
  456. }
  457. var length = this.options.excluded.length;
  458. for (var i = 0; i < length; i++) {
  459. if (('string' === typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
  460. || ('function' === typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) === true))
  461. {
  462. return true;
  463. }
  464. }
  465. }
  466. return false;
  467. }
  468. },
  469. /**
  470. * Get a field changed trigger event
  471. *
  472. * @param {jQuery} $field The field element
  473. * @returns {String[]} The event names triggered on field change
  474. */
  475. _getFieldTrigger: function($field) {
  476. var ns = this._namespace,
  477. trigger = $field.data(ns + '.trigger');
  478. if (trigger) {
  479. return trigger;
  480. }
  481. var type = $field.attr('type'),
  482. name = $field.attr('data-' + ns + '-field'),
  483. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === $field.get(0).tagName) ? 'change' : this._changeEvent;
  484. trigger = ((this.options.fields[name] ? this.options.fields[name].trigger : null) || this.options.trigger || event).split(' ');
  485. // Since the trigger data is used many times, I need to cache it to use later
  486. $field.data(ns + '.trigger', trigger);
  487. return trigger;
  488. },
  489. /**
  490. * Get the error message for given field and validator
  491. *
  492. * @param {String} field The field name
  493. * @param {String} validatorName The validator name
  494. * @returns {String}
  495. */
  496. _getMessage: function(field, validatorName) {
  497. if (!this.options.fields[field] || !FormValidation.Validator[validatorName]
  498. || !this.options.fields[field].validators || !this.options.fields[field].validators[validatorName])
  499. {
  500. return '';
  501. }
  502. switch (true) {
  503. case !!this.options.fields[field].validators[validatorName].message:
  504. return this.options.fields[field].validators[validatorName].message;
  505. case !!this.options.fields[field].message:
  506. return this.options.fields[field].message;
  507. case (!!FormValidation.I18n[this.options.locale] && !!FormValidation.I18n[this.options.locale][validatorName] && !!FormValidation.I18n[this.options.locale][validatorName]['default']):
  508. return FormValidation.I18n[this.options.locale][validatorName]['default'];
  509. default:
  510. return this.options.message;
  511. }
  512. },
  513. /**
  514. * Get the element to place the error messages
  515. *
  516. * @param {jQuery} $field The field element
  517. * @param {String} row
  518. * @returns {jQuery}
  519. */
  520. _getMessageContainer: function($field, row) {
  521. if (!this.options.err.parent) {
  522. throw new Error('The err.parent option is not defined');
  523. }
  524. var $parent = $field.parent();
  525. if ($parent.is(row)) {
  526. return $parent;
  527. }
  528. var cssClasses = $parent.attr('class');
  529. if (!cssClasses) {
  530. return this._getMessageContainer($parent, row);
  531. }
  532. if (this.options.err.parent.test(cssClasses)) {
  533. return $parent;
  534. }
  535. return this._getMessageContainer($parent, row);
  536. },
  537. /**
  538. * Parse the add-on options from HTML attributes
  539. *
  540. * @returns {Object}
  541. */
  542. _parseAddOnOptions: function() {
  543. var ns = this._namespace,
  544. names = this.$form.attr('data-' + ns + '-addons'),
  545. addOns = this.options.addOns || {};
  546. if (names) {
  547. names = names.replace(/\s/g, '').split(',');
  548. for (var i = 0; i < names.length; i++) {
  549. if (!addOns[names[i]]) {
  550. addOns[names[i]] = {};
  551. }
  552. }
  553. }
  554. // Try to parse each add-on options
  555. var addOn, attrMap, attr, option;
  556. for (addOn in addOns) {
  557. if (!FormValidation.AddOn[addOn]) {
  558. // Add-on is not found
  559. delete addOns[addOn];
  560. continue;
  561. }
  562. attrMap = FormValidation.AddOn[addOn].html5Attributes;
  563. if (attrMap) {
  564. for (attr in attrMap) {
  565. option = this.$form.attr('data-' + ns + '-addons-' + addOn.toLowerCase() + '-' + attr.toLowerCase());
  566. if (option) {
  567. addOns[addOn][attrMap[attr]] = option;
  568. }
  569. }
  570. }
  571. }
  572. return addOns;
  573. },
  574. /**
  575. * Parse the validator options from HTML attributes
  576. *
  577. * @param {jQuery} $field The field element
  578. * @returns {Object}
  579. */
  580. _parseOptions: function($field) {
  581. var ns = this._namespace,
  582. field = $field.attr('name') || $field.attr('data-' + ns + '-field'),
  583. validators = {},
  584. validator,
  585. v, // Validator name
  586. attrName,
  587. enabled,
  588. optionName,
  589. optionAttrName,
  590. optionValue,
  591. html5AttrName,
  592. html5AttrMap;
  593. for (v in FormValidation.Validator) {
  594. validator = FormValidation.Validator[v];
  595. attrName = 'data-' + ns + '-' + v.toLowerCase(),
  596. enabled = $field.attr(attrName) + '';
  597. html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
  598. if ((html5AttrMap && enabled !== 'false')
  599. || (html5AttrMap !== true && ('' === enabled || 'true' === enabled || attrName === enabled.toLowerCase())))
  600. {
  601. // Try to parse the options via attributes
  602. validator.html5Attributes = $.extend({}, {
  603. message: 'message',
  604. onerror: 'onError',
  605. onsuccess: 'onSuccess',
  606. transformer: 'transformer'
  607. }, validator.html5Attributes);
  608. validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]);
  609. for (html5AttrName in validator.html5Attributes) {
  610. optionName = validator.html5Attributes[html5AttrName];
  611. optionAttrName = 'data-' + ns + '-' + v.toLowerCase() + '-' + html5AttrName,
  612. optionValue = $field.attr(optionAttrName);
  613. if (optionValue) {
  614. if ('true' === optionValue || optionAttrName === optionValue.toLowerCase()) {
  615. optionValue = true;
  616. } else if ('false' === optionValue) {
  617. optionValue = false;
  618. }
  619. validators[v][optionName] = optionValue;
  620. }
  621. }
  622. }
  623. }
  624. var opts = {
  625. autoFocus: $field.attr('data-' + ns + '-autofocus'),
  626. err: $field.attr('data-' + ns + '-err-container') || $field.attr('data-' + ns + '-container'), // Support backward
  627. excluded: $field.attr('data-' + ns + '-excluded'),
  628. icon: $field.attr('data-' + ns + '-icon') || $field.attr('data-' + ns + '-feedbackicons') || (this.options.fields && this.options.fields[field] ? this.options.fields[field].feedbackIcons : null), // Support backward
  629. message: $field.attr('data-' + ns + '-message'),
  630. onError: $field.attr('data-' + ns + '-onerror'),
  631. onStatus: $field.attr('data-' + ns + '-onstatus'),
  632. onSuccess: $field.attr('data-' + ns + '-onsuccess'),
  633. row: $field.attr('data-' + ns + '-row') || $field.attr('data-' + ns + '-group') || (this.options.fields && this.options.fields[field] ? this.options.fields[field].group : null), // Support backward
  634. selector: $field.attr('data-' + ns + '-selector'),
  635. threshold: $field.attr('data-' + ns + '-threshold'),
  636. transformer: $field.attr('data-' + ns + '-transformer'),
  637. trigger: $field.attr('data-' + ns + '-trigger'),
  638. verbose: $field.attr('data-' + ns + '-verbose'),
  639. validators: validators
  640. },
  641. emptyOptions = $.isEmptyObject(opts), // Check if the field options are set using HTML attributes
  642. emptyValidators = $.isEmptyObject(validators); // Check if the field validators are set using HTML attributes
  643. if (!emptyValidators || (!emptyOptions && this.options.fields && this.options.fields[field])) {
  644. opts.validators = validators;
  645. return opts;
  646. } else {
  647. return null;
  648. }
  649. },
  650. /**
  651. * Called when all validations are completed
  652. */
  653. _submit: function() {
  654. var isValid = this.isValid();
  655. if (isValid === null) {
  656. return;
  657. }
  658. var eventType = isValid ? this.options.events.formSuccess : this.options.events.formError,
  659. e = $.Event(eventType);
  660. this.$form.trigger(e);
  661. // Call default handler
  662. // Check if whether the submit button is clicked
  663. if (this.$submitButton) {
  664. isValid ? this._onSuccess(e) : this._onError(e);
  665. }
  666. },
  667. // ~~~~~~
  668. // Events
  669. // ~~~~~~
  670. /**
  671. * The default handler of error.form.fv event.
  672. * It will be called when there is a invalid field
  673. *
  674. * @param {jQuery.Event} e The jQuery event object
  675. */
  676. _onError: function(e) {
  677. if (e.isDefaultPrevented()) {
  678. return;
  679. }
  680. if ('submitted' === this.options.live) {
  681. // Enable live mode
  682. this.options.live = 'enabled';
  683. var that = this;
  684. for (var field in this.options.fields) {
  685. (function(f) {
  686. var fields = that.getFieldElements(f);
  687. if (fields.length) {
  688. that.onLiveChange(fields, 'live', function() {
  689. if (that._exceedThreshold($(this))) {
  690. that.validateField($(this));
  691. }
  692. });
  693. }
  694. })(field);
  695. }
  696. }
  697. // Determined the first invalid field which will be focused on automatically
  698. var ns = this._namespace;
  699. for (var i = 0; i < this.$invalidFields.length; i++) {
  700. var $field = this.$invalidFields.eq(i),
  701. autoFocus = this.isOptionEnabled($field.attr('data-' + ns + '-field'), 'autoFocus');
  702. if (autoFocus) {
  703. // Focus the field
  704. $field.focus();
  705. break;
  706. }
  707. }
  708. },
  709. /**
  710. * Called after validating a field element
  711. *
  712. * @param {jQuery} $field The field element
  713. * @param {String} [validatorName] The validator name
  714. */
  715. _onFieldValidated: function($field, validatorName) {
  716. var ns = this._namespace,
  717. field = $field.attr('data-' + ns + '-field'),
  718. validators = this.options.fields[field].validators,
  719. counter = {},
  720. numValidators = 0,
  721. data = {
  722. bv: this, // Support backward
  723. fv: this,
  724. field: field,
  725. element: $field,
  726. validator: validatorName,
  727. result: $field.data(ns + '.response.' + validatorName)
  728. };
  729. // Trigger an event after given validator completes
  730. if (validatorName) {
  731. switch ($field.data(ns + '.result.' + validatorName)) {
  732. case this.STATUS_INVALID:
  733. $field.trigger($.Event(this.options.events.validatorError), data);
  734. break;
  735. case this.STATUS_VALID:
  736. $field.trigger($.Event(this.options.events.validatorSuccess), data);
  737. break;
  738. case this.STATUS_IGNORED:
  739. $field.trigger($.Event(this.options.events.validatorIgnored), data);
  740. break;
  741. default:
  742. break;
  743. }
  744. }
  745. counter[this.STATUS_NOT_VALIDATED] = 0;
  746. counter[this.STATUS_VALIDATING] = 0;
  747. counter[this.STATUS_INVALID] = 0;
  748. counter[this.STATUS_VALID] = 0;
  749. counter[this.STATUS_IGNORED] = 0;
  750. for (var v in validators) {
  751. if (validators[v].enabled === false) {
  752. continue;
  753. }
  754. numValidators++;
  755. var result = $field.data(ns + '.result.' + v);
  756. if (result) {
  757. counter[result]++;
  758. }
  759. }
  760. // The sum of valid fields now also include ignored fields
  761. if (counter[this.STATUS_VALID] + counter[this.STATUS_IGNORED] === numValidators) {
  762. // Remove from the list of invalid fields
  763. this.$invalidFields = this.$invalidFields.not($field);
  764. $field.trigger($.Event(this.options.events.fieldSuccess), data);
  765. }
  766. // If all validators are completed and there is at least one validator which doesn't pass
  767. else if ((counter[this.STATUS_NOT_VALIDATED] === 0 || !this.isOptionEnabled(field, 'verbose')) && counter[this.STATUS_VALIDATING] === 0 && counter[this.STATUS_INVALID] > 0) {
  768. // Add to the list of invalid fields
  769. this.$invalidFields = this.$invalidFields.add($field);
  770. $field.trigger($.Event(this.options.events.fieldError), data);
  771. }
  772. },
  773. /**
  774. * The default handler of success.form.fv event.
  775. * It will be called when all the fields are valid
  776. *
  777. * @param {jQuery.Event} e The jQuery event object
  778. */
  779. _onSuccess: function(e) {
  780. if (e.isDefaultPrevented()) {
  781. return;
  782. }
  783. // Submit the form
  784. this.disableSubmitButtons(true).defaultSubmit();
  785. },
  786. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  787. // Abstract methods
  788. // Need to be implemented by sub-class that supports specific framework
  789. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  790. /**
  791. * Specific framework might need to adjust the icon position
  792. *
  793. * @param {jQuery} $field The field element
  794. * @param {jQuery} $icon The icon element
  795. */
  796. _fixIcon: function($field, $icon) {
  797. },
  798. /**
  799. * Create a tooltip or popover
  800. * It will be shown when focusing on the field
  801. *
  802. * @param {jQuery} $field The field element
  803. * @param {String} message The message
  804. * @param {String} type Can be 'tooltip' or 'popover'
  805. */
  806. _createTooltip: function($field, message, type) {
  807. },
  808. /**
  809. * Destroy the tooltip or popover
  810. *
  811. * @param {jQuery} $field The field element
  812. * @param {String} type Can be 'tooltip' or 'popover'
  813. */
  814. _destroyTooltip: function($field, type) {
  815. },
  816. /**
  817. * Hide a tooltip or popover
  818. *
  819. * @param {jQuery} $field The field element
  820. * @param {String} type Can be 'tooltip' or 'popover'
  821. */
  822. _hideTooltip: function($field, type) {
  823. },
  824. /**
  825. * Show a tooltip or popover
  826. *
  827. * @param {jQuery} $field The field element
  828. * @param {String} type Can be 'tooltip' or 'popover'
  829. */
  830. _showTooltip: function($field, type) {
  831. },
  832. // ~~~~~~~~~~~~~~
  833. // Public methods
  834. // ~~~~~~~~~~~~~~
  835. /**
  836. * Submit the form using default submission.
  837. * It also does not perform any validations when submitting the form
  838. */
  839. defaultSubmit: function() {
  840. var ns = this._namespace;
  841. if (this.$submitButton) {
  842. // Create hidden input to send the submit buttons
  843. $('<input/>')
  844. .attr({
  845. 'type': 'hidden',
  846. name: this.$submitButton.attr('name')
  847. })
  848. .attr('data-' + ns + '-submit-hidden', '')
  849. .val(this.$submitButton.val())
  850. .appendTo(this.$form);
  851. }
  852. // Submit form
  853. this.$form.off('submit.' + ns).submit();
  854. },
  855. /**
  856. * Disable/enable submit buttons
  857. *
  858. * @param {Boolean} disabled Can be true or false
  859. * @returns {FormValidation.Base}
  860. */
  861. disableSubmitButtons: function(disabled) {
  862. if (!disabled) {
  863. this.$form
  864. .find(this.options.button.selector)
  865. .removeAttr('disabled')
  866. .removeClass(this.options.button.disabled);
  867. } else if (this.options.live !== 'disabled') {
  868. // Don't disable if the live validating mode is disabled
  869. this.$form
  870. .find(this.options.button.selector)
  871. .attr('disabled', 'disabled')
  872. .addClass(this.options.button.disabled);
  873. }
  874. return this;
  875. },
  876. /**
  877. * Retrieve the field elements by given name
  878. *
  879. * @param {String} field The field name
  880. * @returns {null|jQuery[]}
  881. */
  882. getFieldElements: function(field) {
  883. if (!this._cacheFields[field]) {
  884. if (this.options.fields[field] && this.options.fields[field].selector) {
  885. // Look for the field inside the form first
  886. var f = this.$form.find(this.options.fields[field].selector);
  887. // If not found, search in entire document
  888. this._cacheFields[field] = f.length ? f : $(this.options.fields[field].selector);
  889. } else {
  890. this._cacheFields[field] = this.$form.find('[name="' + field + '"]');
  891. }
  892. }
  893. return this._cacheFields[field];
  894. },
  895. /**
  896. * Get the field value after applying transformer
  897. *
  898. * @param {String|jQuery} field The field name or field element
  899. * @param {String} validatorName The validator name
  900. * @returns {String}
  901. */
  902. getFieldValue: function(field, validatorName) {
  903. var $field, ns = this._namespace;
  904. if ('string' === typeof field) {
  905. $field = this.getFieldElements(field);
  906. if ($field.length === 0) {
  907. return null;
  908. }
  909. } else {
  910. $field = field;
  911. field = $field.attr('data-' + ns + '-field');
  912. }
  913. if (!field || !this.options.fields[field]) {
  914. return $field.val();
  915. }
  916. var transformer = (this.options.fields[field].validators && this.options.fields[field].validators[validatorName]
  917. ? this.options.fields[field].validators[validatorName].transformer : null)
  918. || this.options.fields[field].transformer;
  919. return transformer ? FormValidation.Helper.call(transformer, [$field, validatorName, this]) : $field.val();
  920. },
  921. /**
  922. * Get the namespace
  923. *
  924. * @returns {String}
  925. */
  926. getNamespace: function() {
  927. return this._namespace;
  928. },
  929. /**
  930. * Get the field options
  931. *
  932. * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
  933. * @param {String} [validator] The name of validator. It null, the method returns form options
  934. * @param {String} [option] The option name
  935. * @return {String|Object}
  936. */
  937. getOptions: function(field, validator, option) {
  938. var ns = this._namespace;
  939. if (!field) {
  940. return option ? this.options[option] : this.options;
  941. }
  942. if ('object' === typeof field) {
  943. field = field.attr('data-' + ns + '-field');
  944. }
  945. if (!this.options.fields[field]) {
  946. return null;
  947. }
  948. var options = this.options.fields[field];
  949. if (!validator) {
  950. return option ? options[option] : options;
  951. }
  952. if (!options.validators || !options.validators[validator]) {
  953. return null;
  954. }
  955. return option ? options.validators[validator][option] : options.validators[validator];
  956. },
  957. /**
  958. * Get the validating result of field
  959. *
  960. * @param {String|jQuery} field The field name or field element
  961. * @param {String} validatorName The validator name
  962. * @returns {String} The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID', 'VALID' or 'IGNORED'
  963. */
  964. getStatus: function(field, validatorName) {
  965. var ns = this._namespace;
  966. switch (typeof field) {
  967. case 'object':
  968. return field.data(ns + '.result.' + validatorName);
  969. case 'string':
  970. /* falls through */
  971. default:
  972. return this.getFieldElements(field).eq(0).data(ns + '.result.' + validatorName);
  973. }
  974. },
  975. /**
  976. * Check whether or not a field option is enabled
  977. *
  978. * @param {String} field The field name
  979. * @param {String} option The option name, "verbose", "autoFocus", for example
  980. * @returns {Boolean}
  981. */
  982. isOptionEnabled: function(field, option) {
  983. if (this.options.fields[field] && (this.options.fields[field][option] === 'true' || this.options.fields[field][option] === true)) {
  984. return true;
  985. }
  986. if (this.options.fields[field] && (this.options.fields[field][option] === 'false' || this.options.fields[field][option] === false)) {
  987. return false;
  988. }
  989. return this.options[option] === 'true' || this.options[option] === true;
  990. },
  991. /**
  992. * Check the form validity
  993. *
  994. * @returns {Boolean|null} Returns one of three values
  995. * - true, if all fields are valid
  996. * - false, if there is one invalid field
  997. * - null, if there is at least one field which is not validated yet or being validated
  998. */
  999. isValid: function() {
  1000. for (var field in this.options.fields) {
  1001. var isValidField = this.isValidField(field);
  1002. if (isValidField === null) {
  1003. return null;
  1004. }
  1005. if (isValidField === false) {
  1006. return false;
  1007. }
  1008. }
  1009. return true;
  1010. },
  1011. /**
  1012. * Check if all fields inside a given container are valid.
  1013. * It's useful when working with a wizard-like such as tab, collapse
  1014. *
  1015. * @param {String|jQuery} container The container selector or element
  1016. * @returns {Boolean|null} Returns one of three values
  1017. * - true, if all fields inside the container are valid
  1018. * - false, if there is one invalid field inside the container
  1019. * - null, if the container consists of at least one field which is not validated yet or being validated
  1020. */
  1021. isValidContainer: function(container) {
  1022. var that = this,
  1023. ns = this._namespace,
  1024. fields = [],
  1025. $container = ('string' === typeof container) ? $(container) : container;
  1026. if ($container.length === 0) {
  1027. return true;
  1028. }
  1029. $container.find('[data-' + ns + '-field]').each(function() {
  1030. var $field = $(this);
  1031. if (!that._isExcluded($field)) {
  1032. fields.push($field);
  1033. }
  1034. });
  1035. var total = fields.length;
  1036. for (var i = 0; i < total; i++) {
  1037. var $f = fields[i],
  1038. field = $f.attr('data-' + ns + '-field'),
  1039. $errors = $f.data(ns + '.messages')
  1040. .find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]');
  1041. if ($errors.filter('[data-' + ns + '-result="' + this.STATUS_INVALID + '"]').length > 0) {
  1042. return false;
  1043. }
  1044. // If the field is not validated
  1045. if ($errors.filter('[data-' + ns + '-result="' + this.STATUS_NOT_VALIDATED + '"]').length > 0
  1046. || $errors.filter('[data-' + ns + '-result="' + this.STATUS_VALIDATING + '"]').length > 0)
  1047. {
  1048. return null;
  1049. }
  1050. }
  1051. return true;
  1052. },
  1053. /**
  1054. * Check if the field is valid or not
  1055. *
  1056. * @param {String|jQuery} field The field name or field element
  1057. * @returns {Boolean|null} Returns one of three values
  1058. * - true, if the field passes all validators
  1059. * - false, if the field doesn't pass any validator
  1060. * - null, if there is at least one validator which isn't validated yet or being validated
  1061. */
  1062. isValidField: function(field) {
  1063. var ns = this._namespace,
  1064. fields = $([]);
  1065. switch (typeof field) {
  1066. case 'object':
  1067. fields = field;
  1068. field = field.attr('data-' + ns + '-field');
  1069. break;
  1070. case 'string':
  1071. fields = this.getFieldElements(field);
  1072. break;
  1073. default:
  1074. break;
  1075. }
  1076. if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
  1077. return true;
  1078. }
  1079. var type = fields.attr('type'),
  1080. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  1081. $field, validatorName, status;
  1082. for (var i = 0; i < total; i++) {
  1083. $field = fields.eq(i);
  1084. if (this._isExcluded($field)) {
  1085. continue;
  1086. }
  1087. for (validatorName in this.options.fields[field].validators) {
  1088. if (this.options.fields[field].validators[validatorName].enabled === false) {
  1089. continue;
  1090. }
  1091. status = $field.data(ns + '.result.' + validatorName);
  1092. if (status === this.STATUS_VALIDATING || status === this.STATUS_NOT_VALIDATED) {
  1093. return null;
  1094. } else if (status === this.STATUS_INVALID) {
  1095. return false;
  1096. }
  1097. }
  1098. }
  1099. return true;
  1100. },
  1101. /**
  1102. * Detach a handler function for a field live change event
  1103. *
  1104. * @param {jQuery[]} $fields The field elements
  1105. * @param {String} namespace The event namespace
  1106. * @returns {FormValidation.Base}
  1107. */
  1108. offLiveChange: function($fields, namespace) {
  1109. if ($fields === null || $fields.length === 0) {
  1110. return this;
  1111. }
  1112. var ns = this._namespace,
  1113. trigger = this._getFieldTrigger($fields.eq(0)),
  1114. events = $.map(trigger, function(item) {
  1115. return item + '.' + namespace + '.' + ns;
  1116. }).join(' ');
  1117. $fields.off(events);
  1118. return this;
  1119. },
  1120. /**
  1121. * Attach a handler function for a field live change event
  1122. *
  1123. * @param {jQuery[]} $fields The field elements
  1124. * @param {String} namespace The event namespace
  1125. * @param {Function} handler The handler function
  1126. * @returns {FormValidation.Base}
  1127. */
  1128. onLiveChange: function($fields, namespace, handler) {
  1129. if ($fields === null || $fields.length === 0) {
  1130. return this;
  1131. }
  1132. var ns = this._namespace,
  1133. trigger = this._getFieldTrigger($fields.eq(0)),
  1134. events = $.map(trigger, function(item) {
  1135. return item + '.' + namespace + '.' + ns;
  1136. }).join(' ');
  1137. switch (this.options.live) {
  1138. case 'submitted':
  1139. break;
  1140. case 'disabled':
  1141. $fields.off(events);
  1142. break;
  1143. case 'enabled':
  1144. /* falls through */
  1145. default:
  1146. $fields.off(events).on(events, function(e) {
  1147. handler.apply(this, arguments);
  1148. });
  1149. break;
  1150. }
  1151. return this;
  1152. },
  1153. /**
  1154. * Update the error message
  1155. *
  1156. * @param {String|jQuery} field The field name or field element
  1157. * @param {String} validator The validator name
  1158. * @param {String} message The message
  1159. * @returns {FormValidation.Base}
  1160. */
  1161. updateMessage: function(field, validator, message) {
  1162. var that = this,
  1163. ns = this._namespace,
  1164. $fields = $([]);
  1165. switch (typeof field) {
  1166. case 'object':
  1167. $fields = field;
  1168. field = field.attr('data-' + ns + '-field');
  1169. break;
  1170. case 'string':
  1171. $fields = this.getFieldElements(field);
  1172. break;
  1173. default:
  1174. break;
  1175. }
  1176. $fields.each(function() {
  1177. $(this)
  1178. .data(ns + '.messages')
  1179. .find('.' + that.options.err.clazz + '[data-' + ns + '-validator="' + validator + '"][data-' + ns + '-for="' + field + '"]').html(message);
  1180. });
  1181. return this;
  1182. },
  1183. /**
  1184. * Update all validating results of field
  1185. *
  1186. * @param {String|jQuery} field The field name or field element
  1187. * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID', 'VALID' or 'IGNORED'
  1188. * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  1189. * @returns {FormValidation.Base}
  1190. */
  1191. updateStatus: function(field, status, validatorName) {
  1192. var ns = this._namespace,
  1193. fields = $([]);
  1194. switch (typeof field) {
  1195. case 'object':
  1196. fields = field;
  1197. field = field.attr('data-' + ns + '-field');
  1198. break;
  1199. case 'string':
  1200. fields = this.getFieldElements(field);
  1201. break;
  1202. default:
  1203. break;
  1204. }
  1205. if (!field || !this.options.fields[field]) {
  1206. return this;
  1207. }
  1208. if (status === this.STATUS_NOT_VALIDATED) {
  1209. // Reset the flag
  1210. // To prevent the form from doing submit when a deferred validator returns true while typing
  1211. this._submitIfValid = false;
  1212. }
  1213. var that = this,
  1214. type = fields.attr('type'),
  1215. row = this.options.fields[field].row || this.options.row.selector,
  1216. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1217. for (var i = 0; i < total; i++) {
  1218. var $field = fields.eq(i);
  1219. if (this._isExcluded($field)) {
  1220. continue;
  1221. }
  1222. var $parent = $field.closest(row),
  1223. $message = $field.data(ns + '.messages'),
  1224. $allErrors = $message.find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]'),
  1225. $errors = validatorName ? $allErrors.filter('[data-' + ns + '-validator="' + validatorName + '"]') : $allErrors,
  1226. $icon = $field.data(ns + '.icon'),
  1227. // Support backward
  1228. container = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container))
  1229. ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this)
  1230. : (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container),
  1231. isValidField = null,
  1232. isValidating,
  1233. isNotValidated;
  1234. // Update status
  1235. if (validatorName) {
  1236. $field.data(ns + '.result.' + validatorName, status);
  1237. } else {
  1238. for (var v in this.options.fields[field].validators) {
  1239. $field.data(ns + '.result.' + v, status);
  1240. }
  1241. }
  1242. // Show/hide error elements and feedback icons
  1243. $errors.attr('data-' + ns + '-result', status);
  1244. switch (status) {
  1245. case this.STATUS_VALIDATING:
  1246. isValidField = null;
  1247. this.disableSubmitButtons(true);
  1248. $field.removeClass(this.options.control.valid).removeClass(this.options.control.invalid);
  1249. $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid);
  1250. if ($icon) {
  1251. $icon.removeClass(this.options.icon.valid).removeClass(this.options.icon.invalid).addClass(this.options.icon.validating).show();
  1252. }
  1253. break;
  1254. case this.STATUS_INVALID:
  1255. isValidField = false;
  1256. this.disableSubmitButtons(true);
  1257. $field.removeClass(this.options.control.valid).addClass(this.options.control.invalid);
  1258. $parent.removeClass(this.options.row.valid).addClass(this.options.row.invalid);
  1259. if ($icon) {
  1260. $icon.removeClass(this.options.icon.valid).removeClass(this.options.icon.validating).addClass(this.options.icon.invalid).show();
  1261. }
  1262. break;
  1263. case this.STATUS_VALID:
  1264. case this.STATUS_IGNORED: // Treat ignored fields like they are valid with some specialties
  1265. isValidating = ($allErrors.filter('[data-' + ns + '-result="' + this.STATUS_VALIDATING +'"]').length > 0);
  1266. isNotValidated = ($allErrors.filter('[data-' + ns + '-result="' + this.STATUS_NOT_VALIDATED +'"]').length > 0);
  1267. // If the field is valid (passes all validators)
  1268. isValidField = (isValidating || isNotValidated) // There are some validators that have not done
  1269. ? null
  1270. : ($allErrors.filter('[data-' + ns + '-result="' + this.STATUS_VALID +'"]').length
  1271. + $allErrors.filter('[data-' + ns + '-result="' + this.STATUS_IGNORED +'"]').length === $allErrors.length); // All validators are completed
  1272. $field.removeClass(this.options.control.valid).removeClass(this.options.control.invalid);
  1273. if (isValidField === true) {
  1274. this.disableSubmitButtons(this.isValid() === false);
  1275. if (status === this.STATUS_VALID) {
  1276. $field.addClass(this.options.control.valid);
  1277. }
  1278. } else if (isValidField === false) {
  1279. this.disableSubmitButtons(true);
  1280. if (status === this.STATUS_VALID) {
  1281. $field.addClass(this.options.control.invalid);
  1282. }
  1283. }
  1284. if ($icon) {
  1285. $icon.removeClass(this.options.icon.invalid).removeClass(this.options.icon.validating).removeClass(this.options.icon.valid);
  1286. if (status === this.STATUS_VALID) {
  1287. $icon.addClass(isValidField === null
  1288. ? '' : (isValidField ? this.options.icon.valid : (isValidating ? this.options.icon.validating : this.options.icon.invalid)))
  1289. .show();
  1290. }
  1291. }
  1292. var isValidContainer = this.isValidContainer($parent);
  1293. if (isValidContainer !== null) {
  1294. $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid);
  1295. if (status === this.STATUS_VALID || $allErrors.length > 1) {
  1296. $parent.addClass(isValidContainer ? this.options.row.valid : this.options.row.invalid);
  1297. }
  1298. }
  1299. break;
  1300. case this.STATUS_NOT_VALIDATED:
  1301. /* falls through */
  1302. default:
  1303. isValidField = null;
  1304. this.disableSubmitButtons(false);
  1305. $field.removeClass(this.options.control.valid).removeClass(this.options.control.invalid);
  1306. $parent.removeClass(this.options.row.valid).removeClass(this.options.row.invalid);
  1307. if ($icon) {
  1308. $icon.removeClass(this.options.icon.valid).removeClass(this.options.icon.invalid).removeClass(this.options.icon.validating).hide();
  1309. }
  1310. break;
  1311. }
  1312. if ($icon && ('tooltip' === container || 'popover' === container)) {
  1313. (isValidField === false)
  1314. // Only show the first error message
  1315. ? this._createTooltip($field, $allErrors.filter('[data-' + ns + '-result="' + that.STATUS_INVALID + '"]').eq(0).html(), container)
  1316. : this._destroyTooltip($field, container);
  1317. } else {
  1318. (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
  1319. }
  1320. // Trigger an event
  1321. $field.trigger($.Event(this.options.events.fieldStatus), {
  1322. bv: this, // Support backward
  1323. fv: this,
  1324. field: field,
  1325. element: $field,
  1326. status: status
  1327. });
  1328. this._onFieldValidated($field, validatorName);
  1329. }
  1330. return this;
  1331. },
  1332. /**
  1333. * Validate the form
  1334. *
  1335. * @returns {FormValidation.Base}
  1336. */
  1337. validate: function() {
  1338. if ($.isEmptyObject(this.options.fields)) {
  1339. this._submit();
  1340. return this;
  1341. }
  1342. this.disableSubmitButtons(true);
  1343. this._submitIfValid = false;
  1344. for (var field in this.options.fields) {
  1345. this.validateField(field);
  1346. }
  1347. this._submit();
  1348. this._submitIfValid = true;
  1349. return this;
  1350. },
  1351. /**
  1352. * Validate given field
  1353. *
  1354. * @param {String|jQuery} field The field name or field element
  1355. * @returns {FormValidation.Base}
  1356. */
  1357. validateField: function(field) {
  1358. var ns = this._namespace,
  1359. fields = $([]);
  1360. switch (typeof field) {
  1361. case 'object':
  1362. fields = field;
  1363. field = field.attr('data-' + ns + '-field');
  1364. break;
  1365. case 'string':
  1366. fields = this.getFieldElements(field);
  1367. break;
  1368. default:
  1369. break;
  1370. }
  1371. if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
  1372. return this;
  1373. }
  1374. var that = this,
  1375. type = fields.attr('type'),
  1376. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  1377. updateAll = ('radio' === type || 'checkbox' === type),
  1378. validators = this.options.fields[field].validators,
  1379. verbose = this.isOptionEnabled(field, 'verbose'),
  1380. validatorName,
  1381. validateResult;
  1382. for (var i = 0; i < total; i++) {
  1383. var $field = fields.eq(i);
  1384. if (this._isExcluded($field)) {
  1385. continue;
  1386. }
  1387. var stop = false;
  1388. for (validatorName in validators) {
  1389. if ($field.data(ns + '.dfs.' + validatorName)) {
  1390. $field.data(ns + '.dfs.' + validatorName).reject();
  1391. }
  1392. if (stop) {
  1393. break;
  1394. }
  1395. // Don't validate field if it is already done
  1396. var result = $field.data(ns + '.result.' + validatorName);
  1397. if (result === this.STATUS_VALID || result === this.STATUS_INVALID) {
  1398. this._onFieldValidated($field, validatorName);
  1399. continue;
  1400. } else if (validators[validatorName].enabled === false) {
  1401. this.updateStatus(updateAll ? field : $field, this.STATUS_VALID, validatorName);
  1402. continue;
  1403. }
  1404. $field.data(ns + '.result.' + validatorName, this.STATUS_VALIDATING);
  1405. validateResult = FormValidation.Validator[validatorName].validate(this, $field, validators[validatorName]);
  1406. // validateResult can be a $.Deferred object ...
  1407. if ('object' === typeof validateResult && validateResult.resolve) {
  1408. this.updateStatus(updateAll ? field : $field, this.STATUS_VALIDATING, validatorName);
  1409. $field.data(ns + '.dfs.' + validatorName, validateResult);
  1410. validateResult.done(function($f, v, response) {
  1411. // v is validator name
  1412. $f.removeData(ns + '.dfs.' + v).data(ns + '.response.' + v, response);
  1413. if (response.message) {
  1414. that.updateMessage($f, v, response.message);
  1415. }
  1416. that.updateStatus(updateAll ? $f.attr('data-' + ns + '-field') : $f,
  1417. response.valid === true ? that.STATUS_VALID : (response.valid === false ? that.STATUS_INVALID : that.STATUS_IGNORED),
  1418. v);
  1419. if (response.valid && that._submitIfValid === true) {
  1420. // If a remote validator returns true and the form is ready to submit, then do it
  1421. that._submit();
  1422. } else if (response.valid === false && !verbose) {
  1423. stop = true;
  1424. }
  1425. });
  1426. }
  1427. // ... or object { valid: true/false/null, message: 'dynamic message', otherKey: value, ... }
  1428. else if ('object' === typeof validateResult && validateResult.valid !== undefined) {
  1429. $field.data(ns + '.response.' + validatorName, validateResult);
  1430. if (validateResult.message) {
  1431. this.updateMessage(updateAll ? field : $field, validatorName, validateResult.message);
  1432. }
  1433. this.updateStatus(updateAll ? field : $field,
  1434. validateResult.valid === true ? this.STATUS_VALID : (validateResult.valid === false ? this.STATUS_INVALID : this.STATUS_IGNORED),
  1435. validatorName);
  1436. if (validateResult.valid === false && !verbose) {
  1437. break;
  1438. }
  1439. }
  1440. // ... or a boolean value
  1441. else if ('boolean' === typeof validateResult) {
  1442. $field.data(ns + '.response.' + validatorName, validateResult);
  1443. this.updateStatus(updateAll ? field : $field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  1444. if (!validateResult && !verbose) {
  1445. break;
  1446. }
  1447. }
  1448. // ... or null/undefined
  1449. // to indicate that the field should be ignored for current validation
  1450. else if (null === validateResult || undefined === validateResult) {
  1451. $field.data(ns + '.response.' + validatorName, validateResult);
  1452. this.updateStatus(updateAll ? field : $field, this.STATUS_IGNORED, validatorName);
  1453. }
  1454. }
  1455. }
  1456. return this;
  1457. },
  1458. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1459. // Useful APIs which aren't used internally
  1460. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1461. /**
  1462. * Add a new field
  1463. *
  1464. * @param {String|jQuery} field The field name or field element
  1465. * @param {Object} [options] The validator rules
  1466. * @returns {FormValidation.Base}
  1467. */
  1468. addField: function(field, options) {
  1469. var ns = this._namespace,
  1470. fields = $([]);
  1471. switch (typeof field) {
  1472. case 'object':
  1473. fields = field;
  1474. field = field.attr('data-' + ns + '-field') || field.attr('name');
  1475. break;
  1476. case 'string':
  1477. delete this._cacheFields[field];
  1478. fields = this.getFieldElements(field);
  1479. break;
  1480. default:
  1481. break;
  1482. }
  1483. fields.attr('data-' + ns + '-field', field);
  1484. var type = fields.attr('type'),
  1485. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1486. for (var i = 0; i < total; i++) {
  1487. var $field = fields.eq(i);
  1488. // Try to parse the options from HTML attributes
  1489. var opts = this._parseOptions($field);
  1490. opts = (opts === null) ? options : $.extend(true, opts, options);
  1491. this.options.fields[field] = $.extend(true, this.options.fields[field], opts);
  1492. // Update the cache
  1493. this._cacheFields[field] = this._cacheFields[field] ? this._cacheFields[field].add($field) : $field;
  1494. // Init the element
  1495. this._initField(('checkbox' === type || 'radio' === type) ? field : $field);
  1496. }
  1497. this.disableSubmitButtons(false);
  1498. // Trigger an event
  1499. this.$form.trigger($.Event(this.options.events.fieldAdded), {
  1500. field: field,
  1501. element: fields,
  1502. options: this.options.fields[field]
  1503. });
  1504. return this;
  1505. },
  1506. /**
  1507. * Destroy the plugin
  1508. * It will remove all error messages, feedback icons and turn off the events
  1509. */
  1510. destroy: function() {
  1511. var ns = this._namespace, i, field, fields, $field, validator, $icon, row;
  1512. // Destroy the validators first
  1513. for (field in this.options.fields) {
  1514. fields = this.getFieldElements(field);
  1515. for (i = 0; i < fields.length; i++) {
  1516. $field = fields.eq(i);
  1517. for (validator in this.options.fields[field].validators) {
  1518. if ($field.data(ns + '.dfs.' + validator)) {
  1519. $field.data(ns + '.dfs.' + validator).reject();
  1520. }
  1521. $field.removeData(ns + '.result.' + validator)
  1522. .removeData(ns + '.response.' + validator)
  1523. .removeData(ns + '.dfs.' + validator);
  1524. // Destroy the validator
  1525. if ('function' === typeof FormValidation.Validator[validator].destroy) {
  1526. FormValidation.Validator[validator].destroy(this, $field, this.options.fields[field].validators[validator]);
  1527. }
  1528. }
  1529. }
  1530. }
  1531. // Remove messages and icons
  1532. for (field in this.options.fields) {
  1533. fields = this.getFieldElements(field);
  1534. row = this.options.fields[field].row || this.options.row.selector;
  1535. for (i = 0; i < fields.length; i++) {
  1536. $field = fields.eq(i);
  1537. $field
  1538. // Remove all error messages
  1539. .data(ns + '.messages')
  1540. .find('.' + this.options.err.clazz.split(' ').join('.') + '[data-' + ns + '-validator][data-' + ns + '-for="' + field + '"]').remove().end()
  1541. .end()
  1542. .removeData(ns + '.messages')
  1543. // Remove feedback classes
  1544. .closest(row)
  1545. .removeClass(this.options.row.valid)
  1546. .removeClass(this.options.row.invalid)
  1547. .removeClass(this.options.row.feedback)
  1548. .end()
  1549. // Turn off events
  1550. .off('.' + ns)
  1551. .removeAttr('data-' + ns + '-field');
  1552. // Remove feedback icons, tooltip/popover container
  1553. // Support backward
  1554. var container = ('function' === typeof (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container))
  1555. ? (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container).call(this, $field, this)
  1556. : (this.options.fields[field].container || this.options.fields[field].err || this.options.err.container);
  1557. if ('tooltip' === container || 'popover' === container) {
  1558. this._destroyTooltip($field, container);
  1559. }
  1560. $icon = $field.data(ns + '.icon');
  1561. if ($icon) {
  1562. $icon.remove();
  1563. }
  1564. $field.removeData(ns + '.icon')
  1565. // It's safe to remove trigger data here, because it might be used when destroying the validator
  1566. .removeData(ns + '.trigger');
  1567. }
  1568. }
  1569. // Destroy the add-ons
  1570. for (var addOn in this.options.addOns) {
  1571. if ('function' === typeof FormValidation.AddOn[addOn].destroy) {
  1572. FormValidation.AddOn[addOn].destroy(this, this.options.addOns[addOn]);
  1573. }
  1574. }
  1575. this.disableSubmitButtons(false); // Enable submit buttons
  1576. this.$hiddenButton.remove(); // Remove the hidden button
  1577. this.$form
  1578. .removeClass(this.options.elementClass)
  1579. .off('.' + ns)
  1580. .removeData('bootstrapValidator') // Support backward
  1581. .removeData('formValidation')
  1582. // Remove generated hidden elements
  1583. .find('[data-' + ns + '-submit-hidden]').remove().end()
  1584. .find('[type="submit"]')
  1585. .off('click.' + ns);
  1586. },
  1587. /**
  1588. * Enable/Disable all validators to given field
  1589. *
  1590. * @param {String} field The field name
  1591. * @param {Boolean} enabled Enable/Disable field validators
  1592. * @param {String} [validatorName] The validator name. If null, all validators will be enabled/disabled
  1593. * @returns {FormValidation.Base}
  1594. */
  1595. enableFieldValidators: function(field, enabled, validatorName) {
  1596. var validators = this.options.fields[field].validators;
  1597. // Enable/disable particular validator
  1598. if (validatorName
  1599. && validators
  1600. && validators[validatorName] && validators[validatorName].enabled !== enabled)
  1601. {
  1602. this.options.fields[field].validators[validatorName].enabled = enabled;
  1603. this.updateStatus(field, this.STATUS_NOT_VALIDATED, validatorName);
  1604. }
  1605. // Enable/disable all validators
  1606. else if (!validatorName && this.options.fields[field].enabled !== enabled) {
  1607. this.options.fields[field].enabled = enabled;
  1608. for (var v in validators) {
  1609. this.enableFieldValidators(field, enabled, v);
  1610. }
  1611. }
  1612. return this;
  1613. },
  1614. /**
  1615. * Some validators have option which its value is dynamic.
  1616. * For example, the zipCode validator has the country option which might be changed dynamically by a select element.
  1617. *
  1618. * @param {jQuery|String} field The field name or element
  1619. * @param {String|Function} option The option which can be determined by:
  1620. * - a string
  1621. * - name of field which defines the value
  1622. * - name of function which returns the value
  1623. * - a function returns the value
  1624. *
  1625. * The callback function has the format of
  1626. * callback: function(value, validator, $field) {
  1627. * // value is the value of field
  1628. * // validator is the BootstrapValidator instance
  1629. * // $field is the field element
  1630. * }
  1631. *
  1632. * @returns {String}
  1633. */
  1634. getDynamicOption: function(field, option) {
  1635. var $field = ('string' === typeof field) ? this.getFieldElements(field) : field,
  1636. value = $field.val();
  1637. // Option can be determined by
  1638. // ... a function
  1639. if ('function' === typeof option) {
  1640. return FormValidation.Helper.call(option, [value, this, $field]);
  1641. }
  1642. // ... value of other field
  1643. else if ('string' === typeof option) {
  1644. var $f = this.getFieldElements(option);
  1645. if ($f.length) {
  1646. return $f.val();
  1647. }
  1648. // ... return value of callback
  1649. else {
  1650. return FormValidation.Helper.call(option, [value, this, $field]) || option;
  1651. }
  1652. }
  1653. return null;
  1654. },
  1655. /**
  1656. * Get the form element
  1657. *
  1658. * @returns {jQuery}
  1659. */
  1660. getForm: function() {
  1661. return this.$form;
  1662. },
  1663. /**
  1664. * Get the list of invalid fields
  1665. *
  1666. * @returns {jQuery[]}
  1667. */
  1668. getInvalidFields: function() {
  1669. return this.$invalidFields;
  1670. },
  1671. /**
  1672. * Get the current locale
  1673. *
  1674. * @return {String}
  1675. */
  1676. getLocale: function() {
  1677. return this.options.locale;
  1678. },
  1679. /**
  1680. * Get the error messages
  1681. *
  1682. * @param {String|jQuery} [field] The field name or field element
  1683. * If the field is not defined, the method returns all error messages of all fields
  1684. * @param {String} [validator] The name of validator
  1685. * If the validator is not defined, the method returns error messages of all validators
  1686. * @returns {String[]}
  1687. */
  1688. getMessages: function(field, validator) {
  1689. var that = this,
  1690. ns = this._namespace,
  1691. messages = [],
  1692. $fields = $([]);
  1693. switch (true) {
  1694. case (field && 'object' === typeof field):
  1695. $fields = field;
  1696. break;
  1697. case (field && 'string' === typeof field):
  1698. var f = this.getFieldElements(field);
  1699. if (f.length > 0) {
  1700. var type = f.attr('type');
  1701. $fields = ('radio' === type || 'checkbox' === type) ? f.eq(0) : f;
  1702. }
  1703. break;
  1704. default:
  1705. $fields = this.$invalidFields;
  1706. break;
  1707. }
  1708. var filter = validator ? '[data-' + ns + '-validator="' + validator + '"]' : '';
  1709. $fields.each(function() {
  1710. messages = messages.concat(
  1711. $(this)
  1712. .data(ns + '.messages')
  1713. .find('.' + that.options.err.clazz + '[data-' + ns + '-for="' + $(this).attr('data-' + ns + '-field') + '"][data-' + ns + '-result="' + that.STATUS_INVALID + '"]' + filter)
  1714. .map(function() {
  1715. var v = $(this).attr('data-' + ns + '-validator'),
  1716. f = $(this).attr('data-' + ns + '-for');
  1717. return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html();
  1718. })
  1719. .get()
  1720. );
  1721. });
  1722. return messages;
  1723. },
  1724. /**
  1725. * Returns the clicked submit button
  1726. *
  1727. * @returns {jQuery}
  1728. */
  1729. getSubmitButton: function() {
  1730. return this.$submitButton;
  1731. },
  1732. /**
  1733. * Remove a given field
  1734. *
  1735. * @param {String|jQuery} field The field name or field element
  1736. * @returns {FormValidation.Base}
  1737. */
  1738. removeField: function(field) {
  1739. var ns = this._namespace,
  1740. fields = $([]);
  1741. switch (typeof field) {
  1742. case 'object':
  1743. fields = field;
  1744. field = field.attr('data-' + ns + '-field') || field.attr('name');
  1745. fields.attr('data-' + ns + '-field', field);
  1746. break;
  1747. case 'string':
  1748. fields = this.getFieldElements(field);
  1749. break;
  1750. default:
  1751. break;
  1752. }
  1753. if (fields.length === 0) {
  1754. return this;
  1755. }
  1756. var type = fields.attr('type'),
  1757. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1758. for (var i = 0; i < total; i++) {
  1759. var $field = fields.eq(i);
  1760. // Remove from the list of invalid fields
  1761. this.$invalidFields = this.$invalidFields.not($field);
  1762. // Update the cache
  1763. this._cacheFields[field] = this._cacheFields[field].not($field);
  1764. }
  1765. if (!this._cacheFields[field] || this._cacheFields[field].length === 0) {
  1766. delete this.options.fields[field];
  1767. }
  1768. if ('checkbox' === type || 'radio' === type) {
  1769. this._initField(field);
  1770. }
  1771. this.disableSubmitButtons(false);
  1772. // Trigger an event
  1773. this.$form.trigger($.Event(this.options.events.fieldRemoved), {
  1774. field: field,
  1775. element: fields
  1776. });
  1777. return this;
  1778. },
  1779. /**
  1780. * Reset given field
  1781. *
  1782. * @param {String|jQuery} field The field name or field element
  1783. * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  1784. * @returns {FormValidation.Base}
  1785. */
  1786. resetField: function(field, resetValue) {
  1787. var ns = this._namespace,
  1788. $fields = $([]);
  1789. switch (typeof field) {
  1790. case 'object':
  1791. $fields = field;
  1792. field = field.attr('data-' + ns + '-field');
  1793. break;
  1794. case 'string':
  1795. $fields = this.getFieldElements(field);
  1796. break;
  1797. default:
  1798. break;
  1799. }
  1800. var total = $fields.length;
  1801. if (this.options.fields[field]) {
  1802. for (var i = 0; i < total; i++) {
  1803. for (var validator in this.options.fields[field].validators) {
  1804. $fields.eq(i).removeData(ns + '.dfs.' + validator);
  1805. }
  1806. }
  1807. }
  1808. if (resetValue) {
  1809. var type = $fields.attr('type');
  1810. ('radio' === type || 'checkbox' === type) ? $fields.prop('checked', false).removeAttr('selected') : $fields.val('');
  1811. }
  1812. // Mark field as not validated yet
  1813. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1814. return this;
  1815. },
  1816. /**
  1817. * Reset the form
  1818. *
  1819. * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  1820. * @returns {FormValidation.Base}
  1821. */
  1822. resetForm: function(resetValue) {
  1823. for (var field in this.options.fields) {
  1824. this.resetField(field, resetValue);
  1825. }
  1826. this.$invalidFields = $([]);
  1827. this.$submitButton = null;
  1828. // Enable submit buttons
  1829. this.disableSubmitButtons(false);
  1830. return this;
  1831. },
  1832. /**
  1833. * Revalidate given field
  1834. * It's used when you need to revalidate the field which its value is updated by other plugin
  1835. *
  1836. * @param {String|jQuery} field The field name of field element
  1837. * @returns {FormValidation.Base}
  1838. */
  1839. revalidateField: function(field) {
  1840. this.updateStatus(field, this.STATUS_NOT_VALIDATED)
  1841. .validateField(field);
  1842. return this;
  1843. },
  1844. /**
  1845. * Set the locale
  1846. *
  1847. * @param {String} locale The locale in format of countrycode_LANGUAGECODE
  1848. * @returns {FormValidation.Base}
  1849. */
  1850. setLocale: function(locale) {
  1851. this.options.locale = locale;
  1852. this.$form.trigger($.Event(this.options.events.localeChanged), {
  1853. locale: locale,
  1854. bv: this, // Support backward
  1855. fv: this
  1856. });
  1857. return this;
  1858. },
  1859. /**
  1860. * Update the option of a specific validator
  1861. *
  1862. * @param {String|jQuery} field The field name or field element
  1863. * @param {String} validator The validator name
  1864. * @param {String} option The option name
  1865. * @param {String} value The value to set
  1866. * @returns {FormValidation.Base}
  1867. */
  1868. updateOption: function(field, validator, option, value) {
  1869. var ns = this._namespace;
  1870. if ('object' === typeof field) {
  1871. field = field.attr('data-' + ns + '-field');
  1872. }
  1873. if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
  1874. this.options.fields[field].validators[validator][option] = value;
  1875. this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
  1876. }
  1877. return this;
  1878. },
  1879. /**
  1880. * Validate given container
  1881. * It can be used with isValidContainer() when you want to work with wizard form
  1882. *
  1883. * @param {String|jQuery} container The container selector or element
  1884. * @returns {FormValidation.Base}
  1885. */
  1886. validateContainer: function(container) {
  1887. var that = this,
  1888. ns = this._namespace,
  1889. fields = [],
  1890. $container = ('string' === typeof container) ? $(container) : container;
  1891. if ($container.length === 0) {
  1892. return this;
  1893. }
  1894. $container.find('[data-' + ns + '-field]').each(function() {
  1895. var $field = $(this);
  1896. if (!that._isExcluded($field)) {
  1897. fields.push($field);
  1898. }
  1899. });
  1900. var total = fields.length;
  1901. for (var i = 0; i < total; i++) {
  1902. this.validateField(fields[i]);
  1903. }
  1904. return this;
  1905. }
  1906. };
  1907. // Plugin definition
  1908. $.fn.formValidation = function(option) {
  1909. var params = arguments;
  1910. return this.each(function() {
  1911. var $this = $(this),
  1912. data = $this.data('formValidation'),
  1913. options = 'object' === typeof option && option;
  1914. if (!data) {
  1915. var framework = (options.framework || $this.attr('data-fv-framework') || 'bootstrap').toLowerCase(),
  1916. clazz = framework.substr(0, 1).toUpperCase() + framework.substr(1);
  1917. if (typeof FormValidation.Framework[clazz] === 'undefined') {
  1918. throw new Error('The class FormValidation.Framework.' + clazz + ' is not implemented');
  1919. }
  1920. data = new FormValidation.Framework[clazz](this, options);
  1921. $this.addClass('fv-form-' + framework)
  1922. .data('formValidation', data);
  1923. }
  1924. // Allow to call plugin method
  1925. if ('string' === typeof option) {
  1926. data[option].apply(data, Array.prototype.slice.call(params, 1));
  1927. }
  1928. });
  1929. };
  1930. $.fn.formValidation.Constructor = FormValidation.Base;
  1931. // The default options
  1932. // Sorted in alphabetical order
  1933. $.fn.formValidation.DEFAULT_OPTIONS = {
  1934. // The first invalid field will be focused automatically
  1935. autoFocus: true,
  1936. // Support declarative usage (setting options via HTML 5 attributes)
  1937. // Setting to false can improve the performance
  1938. declarative: true,
  1939. // The form CSS class
  1940. elementClass: 'fv-form',
  1941. // Use custom event name to avoid window.onerror being invoked by jQuery
  1942. // See #630
  1943. events: {
  1944. // Support backward
  1945. formInit: 'init.form.fv',
  1946. formError: 'err.form.fv',
  1947. formSuccess: 'success.form.fv',
  1948. fieldAdded: 'added.field.fv',
  1949. fieldRemoved: 'removed.field.fv',
  1950. fieldInit: 'init.field.fv',
  1951. fieldError: 'err.field.fv',
  1952. fieldSuccess: 'success.field.fv',
  1953. fieldStatus: 'status.field.fv',
  1954. localeChanged: 'changed.locale.fv',
  1955. validatorError: 'err.validator.fv',
  1956. validatorSuccess: 'success.validator.fv',
  1957. validatorIgnored: 'ignored.validator.fv'
  1958. },
  1959. // Indicate fields which won't be validated
  1960. // By default, the plugin will not validate the following kind of fields:
  1961. // - disabled
  1962. // - hidden
  1963. // - invisible
  1964. //
  1965. // The setting consists of jQuery filters. Accept 3 formats:
  1966. // - A string. Use a comma to separate filter
  1967. // - An array. Each element is a filter
  1968. // - An array. Each element can be a callback function
  1969. // function($field, validator) {
  1970. // $field is jQuery object representing the field element
  1971. // validator is the BootstrapValidator instance
  1972. // return true or false;
  1973. // }
  1974. //
  1975. // The 3 following settings are equivalent:
  1976. //
  1977. // 1) ':disabled, :hidden, :not(:visible)'
  1978. // 2) [':disabled', ':hidden', ':not(:visible)']
  1979. // 3) [':disabled', ':hidden', function($field) {
  1980. // return !$field.is(':visible');
  1981. // }]
  1982. excluded: [':disabled', ':hidden', ':not(:visible)'],
  1983. // Map the field name with validator rules
  1984. fields: null,
  1985. // Live validating option
  1986. // Can be one of 3 values:
  1987. // - enabled: The plugin validates fields as soon as they are changed
  1988. // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
  1989. // - submitted: The live validating is enabled after the form is submitted
  1990. live: 'enabled',
  1991. // Locale in the format of languagecode_COUNTRYCODE
  1992. locale: 'en_US',
  1993. // Default invalid message
  1994. message: 'This value is not valid',
  1995. // The field will not be live validated if its length is less than this number of characters
  1996. threshold: null,
  1997. // Whether to be verbose when validating a field or not.
  1998. // Possible values:
  1999. // - true: when a field has multiple validators, all of them will be checked, and respectively - if errors occur in
  2000. // multiple validators, all of them will be displayed to the user
  2001. // - false: when a field has multiple validators, validation for this field will be terminated upon the first encountered error.
  2002. // Thus, only the very first error message related to this field will be displayed to the user
  2003. verbose: true,
  2004. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2005. // These options mostly are overridden by specific framework
  2006. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2007. button: {
  2008. // The submit buttons selector
  2009. // These buttons will be disabled to prevent the valid form from multiple submissions
  2010. selector: '[type="submit"]',
  2011. // The disabled class
  2012. disabled: ''
  2013. },
  2014. control: {
  2015. // The CSS class for valid control
  2016. valid: '',
  2017. // The CSS class for invalid control
  2018. invalid: ''
  2019. },
  2020. err: {
  2021. // The CSS class of each message element
  2022. clazz: '',
  2023. // The error messages container. It can be:
  2024. // - 'tooltip' if you want to use Bootstrap tooltip to show error messages
  2025. // - 'popover' if you want to use Bootstrap popover to show error messages
  2026. // - a CSS selector indicating the container
  2027. // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
  2028. // You also can define the message container for particular field
  2029. container: null,
  2030. // Used to determine where the messages are placed
  2031. parent: null
  2032. },
  2033. // Shows ok/error/loading icons based on the field validity.
  2034. icon: {
  2035. valid: null,
  2036. invalid: null,
  2037. validating: null,
  2038. feedback: ''
  2039. },
  2040. row: {
  2041. // The CSS selector for indicating the element consists of the field
  2042. // You should adjust this option if your form group consists of many fields which not all of them need to be validated
  2043. selector: null,
  2044. valid: '',
  2045. invalid: '',
  2046. feedback: ''
  2047. }
  2048. };
  2049. }(jQuery));
  2050. ;(function($) {
  2051. // Helper methods, which can be used in validator class
  2052. FormValidation.Helper = {
  2053. /**
  2054. * Execute a callback function
  2055. *
  2056. * @param {String|Function} functionName Can be
  2057. * - name of global function
  2058. * - name of namespace function (such as A.B.C)
  2059. * - a function
  2060. * @param {Array} args The callback arguments
  2061. */
  2062. call: function(functionName, args) {
  2063. if ('function' === typeof functionName) {
  2064. return functionName.apply(this, args);
  2065. } else if ('string' === typeof functionName) {
  2066. if ('()' === functionName.substring(functionName.length - 2)) {
  2067. functionName = functionName.substring(0, functionName.length - 2);
  2068. }
  2069. var ns = functionName.split('.'),
  2070. func = ns.pop(),
  2071. context = window;
  2072. for (var i = 0; i < ns.length; i++) {
  2073. context = context[ns[i]];
  2074. }
  2075. return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
  2076. }
  2077. },
  2078. /**
  2079. * Validate a date
  2080. *
  2081. * @param {Number} year The full year in 4 digits
  2082. * @param {Number} month The month number
  2083. * @param {Number} day The day number
  2084. * @param {Boolean} [notInFuture] If true, the date must not be in the future
  2085. * @returns {Boolean}
  2086. */
  2087. date: function(year, month, day, notInFuture) {
  2088. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  2089. return false;
  2090. }
  2091. if (day.length > 2 || month.length > 2 || year.length > 4) {
  2092. return false;
  2093. }
  2094. day = parseInt(day, 10);
  2095. month = parseInt(month, 10);
  2096. year = parseInt(year, 10);
  2097. if (year < 1000 || year > 9999 || month <= 0 || month > 12) {
  2098. return false;
  2099. }
  2100. var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  2101. // Update the number of days in Feb of leap year
  2102. if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
  2103. numDays[1] = 29;
  2104. }
  2105. // Check the day
  2106. if (day <= 0 || day > numDays[month - 1]) {
  2107. return false;
  2108. }
  2109. if (notInFuture === true) {
  2110. var currentDate = new Date(),
  2111. currentYear = currentDate.getFullYear(),
  2112. currentMonth = currentDate.getMonth(),
  2113. currentDay = currentDate.getDate();
  2114. return (year < currentYear
  2115. || (year === currentYear && month - 1 < currentMonth)
  2116. || (year === currentYear && month - 1 === currentMonth && day < currentDay));
  2117. }
  2118. return true;
  2119. },
  2120. /**
  2121. * Format a string
  2122. * It's used to format the error message
  2123. * format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
  2124. *
  2125. * @param {String} message
  2126. * @param {Array} parameters
  2127. * @returns {String}
  2128. */
  2129. format: function(message, parameters) {
  2130. if (!$.isArray(parameters)) {
  2131. parameters = [parameters];
  2132. }
  2133. for (var i in parameters) {
  2134. message = message.replace('%s', parameters[i]);
  2135. }
  2136. return message;
  2137. },
  2138. /**
  2139. * Implement Luhn validation algorithm
  2140. * Credit to https://gist.github.com/ShirtlessKirk/2134376
  2141. *
  2142. * @see http://en.wikipedia.org/wiki/Luhn
  2143. * @param {String} value
  2144. * @returns {Boolean}
  2145. */
  2146. luhn: function(value) {
  2147. var length = value.length,
  2148. mul = 0,
  2149. prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
  2150. sum = 0;
  2151. while (length--) {
  2152. sum += prodArr[mul][parseInt(value.charAt(length), 10)];
  2153. mul ^= 1;
  2154. }
  2155. return (sum % 10 === 0 && sum > 0);
  2156. },
  2157. /**
  2158. * Implement modulus 11, 10 (ISO 7064) algorithm
  2159. *
  2160. * @param {String} value
  2161. * @returns {Boolean}
  2162. */
  2163. mod11And10: function(value) {
  2164. var check = 5,
  2165. length = value.length;
  2166. for (var i = 0; i < length; i++) {
  2167. check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
  2168. }
  2169. return (check === 1);
  2170. },
  2171. /**
  2172. * Implements Mod 37, 36 (ISO 7064) algorithm
  2173. * Usages:
  2174. * mod37And36('A12425GABC1234002M')
  2175. * mod37And36('002006673085', '0123456789')
  2176. *
  2177. * @param {String} value
  2178. * @param {String} [alphabet]
  2179. * @returns {Boolean}
  2180. */
  2181. mod37And36: function(value, alphabet) {
  2182. alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  2183. var modulus = alphabet.length,
  2184. length = value.length,
  2185. check = Math.floor(modulus / 2);
  2186. for (var i = 0; i < length; i++) {
  2187. check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
  2188. }
  2189. return (check === 1);
  2190. }
  2191. };
  2192. }(jQuery));
  2193. ;(function($) {
  2194. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2195. 'en_US': {
  2196. base64: {
  2197. 'default': 'Please enter a valid base 64 encoded'
  2198. }
  2199. }
  2200. });
  2201. FormValidation.Validator.base64 = {
  2202. /**
  2203. * Return true if the input value is a base 64 encoded string.
  2204. *
  2205. * @param {FormValidation.Base} validator The validator plugin instance
  2206. * @param {jQuery} $field Field element
  2207. * @param {Object} options Can consist of the following keys:
  2208. * - message: The invalid message
  2209. * @returns {Boolean}
  2210. */
  2211. validate: function(validator, $field, options) {
  2212. var value = validator.getFieldValue($field, 'base64');
  2213. if (value === '') {
  2214. return true;
  2215. }
  2216. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  2217. }
  2218. };
  2219. }(jQuery));
  2220. ;(function($) {
  2221. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2222. 'en_US': {
  2223. between: {
  2224. 'default': 'Please enter a value between %s and %s',
  2225. notInclusive: 'Please enter a value between %s and %s strictly'
  2226. }
  2227. }
  2228. });
  2229. FormValidation.Validator.between = {
  2230. html5Attributes: {
  2231. message: 'message',
  2232. min: 'min',
  2233. max: 'max',
  2234. inclusive: 'inclusive'
  2235. },
  2236. enableByHtml5: function($field) {
  2237. if ('range' === $field.attr('type')) {
  2238. return {
  2239. min: $field.attr('min'),
  2240. max: $field.attr('max')
  2241. };
  2242. }
  2243. return false;
  2244. },
  2245. /**
  2246. * Return true if the input value is between (strictly or not) two given numbers
  2247. *
  2248. * @param {FormValidation.Base} validator The validator plugin instance
  2249. * @param {jQuery} $field Field element
  2250. * @param {Object} options Can consist of the following keys:
  2251. * - min
  2252. * - max
  2253. *
  2254. * The min, max keys define the number which the field value compares to. min, max can be
  2255. * - A number
  2256. * - Name of field which its value defines the number
  2257. * - Name of callback function that returns the number
  2258. * - A callback function that returns the number
  2259. *
  2260. * - inclusive [optional]: Can be true or false. Default is true
  2261. * - message: The invalid message
  2262. * @returns {Boolean|Object}
  2263. */
  2264. validate: function(validator, $field, options) {
  2265. var value = validator.getFieldValue($field, 'between');
  2266. if (value === '') {
  2267. return true;
  2268. }
  2269. value = this._format(value);
  2270. if (!$.isNumeric(value)) {
  2271. return false;
  2272. }
  2273. var locale = validator.getLocale(),
  2274. min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  2275. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  2276. minValue = this._format(min),
  2277. maxValue = this._format(max);
  2278. value = parseFloat(value);
  2279. return (options.inclusive === true || options.inclusive === undefined)
  2280. ? {
  2281. valid: value >= minValue && value <= maxValue,
  2282. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].between['default'], [min, max])
  2283. }
  2284. : {
  2285. valid: value > minValue && value < maxValue,
  2286. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].between.notInclusive, [min, max])
  2287. };
  2288. },
  2289. _format: function(value) {
  2290. return (value + '').replace(',', '.');
  2291. }
  2292. };
  2293. }(jQuery));
  2294. ;(function($) {
  2295. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2296. 'en_US': {
  2297. bic: {
  2298. 'default': 'Please enter a valid BIC number'
  2299. }
  2300. }
  2301. });
  2302. FormValidation.Validator.bic = {
  2303. /**
  2304. * Validate an Business Identifier Code (BIC), also known as ISO 9362, SWIFT-BIC, SWIFT ID or SWIFT code
  2305. *
  2306. * For more information see http://en.wikipedia.org/wiki/ISO_9362
  2307. *
  2308. * @todo The 5 and 6 characters are an ISO 3166-1 country code, this could also be validated
  2309. * @param {FormValidation.Base} validator The validator plugin instance
  2310. * @param {jQuery} $field Field element
  2311. * @param {Object} options Can consist of the following keys:
  2312. * - message: The invalid message
  2313. * @returns {Object}
  2314. */
  2315. validate: function(validator, $field, options) {
  2316. var value = validator.getFieldValue($field, 'bic');
  2317. if (value === '') {
  2318. return true;
  2319. }
  2320. return /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value);
  2321. }
  2322. };
  2323. }(jQuery));
  2324. ;(function($) {
  2325. FormValidation.Validator.blank = {
  2326. /**
  2327. * Placeholder validator that can be used to display a custom validation message
  2328. * returned from the server
  2329. * Example:
  2330. *
  2331. * (1) a "blank" validator is applied to an input field.
  2332. * (2) data is entered via the UI that is unable to be validated client-side.
  2333. * (3) server returns a 400 with JSON data that contains the field that failed
  2334. * validation and an associated message.
  2335. * (4) ajax 400 call handler does the following:
  2336. *
  2337. * bv.updateMessage(field, 'blank', errorMessage);
  2338. * bv.updateStatus(field, 'INVALID');
  2339. *
  2340. * @see https://github.com/formvalidation/formvalidation/issues/542
  2341. * @see https://github.com/formvalidation/formvalidation/pull/666
  2342. * @param {FormValidation.Base} validator The validator plugin instance
  2343. * @param {jQuery} $field Field element
  2344. * @param {Object} options Can consist of the following keys:
  2345. * - message: The invalid message
  2346. * @returns {Boolean}
  2347. */
  2348. validate: function(validator, $field, options) {
  2349. return true;
  2350. }
  2351. };
  2352. }(jQuery));
  2353. ;(function($) {
  2354. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2355. 'en_US': {
  2356. callback: {
  2357. 'default': 'Please enter a valid value'
  2358. }
  2359. }
  2360. });
  2361. FormValidation.Validator.callback = {
  2362. html5Attributes: {
  2363. message: 'message',
  2364. callback: 'callback'
  2365. },
  2366. /**
  2367. * Return result from the callback method
  2368. *
  2369. * @param {FormValidation.Base} validator The validator plugin instance
  2370. * @param {jQuery} $field Field element
  2371. * @param {Object} options Can consist of the following keys:
  2372. * - callback: The callback method that passes 2 parameters:
  2373. * callback: function(fieldValue, validator, $field) {
  2374. * // fieldValue is the value of field
  2375. * // validator is instance of BootstrapValidator
  2376. * // $field is the field element
  2377. * }
  2378. * - message: The invalid message
  2379. * @returns {Deferred}
  2380. */
  2381. validate: function(validator, $field, options) {
  2382. var value = validator.getFieldValue($field, 'callback'),
  2383. dfd = new $.Deferred(),
  2384. result = { valid: true };
  2385. if (options.callback) {
  2386. var response = FormValidation.Helper.call(options.callback, [value, validator, $field]);
  2387. result = ('boolean' === typeof response || null === response) ? { valid: response } : response;
  2388. }
  2389. dfd.resolve($field, 'callback', result);
  2390. return dfd;
  2391. }
  2392. };
  2393. }(jQuery));
  2394. ;(function($) {
  2395. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2396. 'en_US': {
  2397. choice: {
  2398. 'default': 'Please enter a valid value',
  2399. less: 'Please choose %s options at minimum',
  2400. more: 'Please choose %s options at maximum',
  2401. between: 'Please choose %s - %s options'
  2402. }
  2403. }
  2404. });
  2405. FormValidation.Validator.choice = {
  2406. html5Attributes: {
  2407. message: 'message',
  2408. min: 'min',
  2409. max: 'max'
  2410. },
  2411. /**
  2412. * Check if the number of checked boxes are less or more than a given number
  2413. *
  2414. * @param {FormValidation.Base} validator The validator plugin instance
  2415. * @param {jQuery} $field Field element
  2416. * @param {Object} options Consists of following keys:
  2417. * - min
  2418. * - max
  2419. *
  2420. * At least one of two keys is required
  2421. * The min, max keys define the number which the field value compares to. min, max can be
  2422. * - A number
  2423. * - Name of field which its value defines the number
  2424. * - Name of callback function that returns the number
  2425. * - A callback function that returns the number
  2426. *
  2427. * - message: The invalid message
  2428. * @returns {Object}
  2429. */
  2430. validate: function(validator, $field, options) {
  2431. var locale = validator.getLocale(),
  2432. ns = validator.getNamespace(),
  2433. numChoices = $field.is('select')
  2434. ? validator.getFieldElements($field.attr('data-' + ns + '-field')).find('option').filter(':selected').length
  2435. : validator.getFieldElements($field.attr('data-' + ns + '-field')).filter(':checked').length,
  2436. min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
  2437. max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
  2438. isValid = true,
  2439. message = options.message || FormValidation.I18n[locale].choice['default'];
  2440. if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
  2441. isValid = false;
  2442. }
  2443. switch (true) {
  2444. case (!!min && !!max):
  2445. message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.between, [parseInt(min, 10), parseInt(max, 10)]);
  2446. break;
  2447. case (!!min):
  2448. message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.less, parseInt(min, 10));
  2449. break;
  2450. case (!!max):
  2451. message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].choice.more, parseInt(max, 10));
  2452. break;
  2453. default:
  2454. break;
  2455. }
  2456. return { valid: isValid, message: message };
  2457. }
  2458. };
  2459. }(jQuery));
  2460. ;(function($) {
  2461. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2462. 'en_US': {
  2463. color: {
  2464. 'default': 'Please enter a valid color'
  2465. }
  2466. }
  2467. });
  2468. FormValidation.Validator.color = {
  2469. html5Attributes: {
  2470. message: 'message',
  2471. type: 'type'
  2472. },
  2473. enableByHtml5: function($field) {
  2474. return ('color' === $field.attr('type'));
  2475. },
  2476. SUPPORTED_TYPES: [
  2477. 'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'keyword'
  2478. ],
  2479. KEYWORD_COLORS: [
  2480. // Colors start with A
  2481. 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure',
  2482. // B
  2483. 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood',
  2484. // C
  2485. 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan',
  2486. // D
  2487. 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta',
  2488. 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue',
  2489. 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray',
  2490. 'dimgrey', 'dodgerblue',
  2491. // F
  2492. 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia',
  2493. // G
  2494. 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey',
  2495. // H
  2496. 'honeydew', 'hotpink',
  2497. // I
  2498. 'indianred', 'indigo', 'ivory',
  2499. // K
  2500. 'khaki',
  2501. // L
  2502. 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan',
  2503. 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
  2504. 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen',
  2505. 'linen',
  2506. // M
  2507. 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen',
  2508. 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream',
  2509. 'mistyrose', 'moccasin',
  2510. // N
  2511. 'navajowhite', 'navy',
  2512. // O
  2513. 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid',
  2514. // P
  2515. 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink',
  2516. 'plum', 'powderblue', 'purple',
  2517. // R
  2518. 'red', 'rosybrown', 'royalblue',
  2519. // S
  2520. 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue',
  2521. 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue',
  2522. // T
  2523. 'tan', 'teal', 'thistle', 'tomato', 'transparent', 'turquoise',
  2524. // V
  2525. 'violet',
  2526. // W
  2527. 'wheat', 'white', 'whitesmoke',
  2528. // Y
  2529. 'yellow', 'yellowgreen'
  2530. ],
  2531. /**
  2532. * Return true if the input value is a valid color
  2533. *
  2534. * @param {FormValidation.Base} validator The validator plugin instance
  2535. * @param {jQuery} $field Field element
  2536. * @param {Object} options Can consist of the following keys:
  2537. * - message: The invalid message
  2538. * - type: The array of valid color types
  2539. * @returns {Boolean}
  2540. */
  2541. validate: function(validator, $field, options) {
  2542. var value = validator.getFieldValue($field, 'color');
  2543. if (value === '') {
  2544. return true;
  2545. }
  2546. // Only accept 6 hex character values due to the HTML 5 spec
  2547. // See http://www.w3.org/TR/html-markup/input.color.html#input.color.attrs.value
  2548. if (this.enableByHtml5($field)) {
  2549. return /^#[0-9A-F]{6}$/i.test(value);
  2550. }
  2551. var types = options.type || this.SUPPORTED_TYPES;
  2552. if (!$.isArray(types)) {
  2553. types = types.replace(/s/g, '').split(',');
  2554. }
  2555. var method,
  2556. type,
  2557. isValid = false;
  2558. for (var i = 0; i < types.length; i++) {
  2559. type = types[i];
  2560. method = '_' + type.toLowerCase();
  2561. isValid = isValid || this[method](value);
  2562. if (isValid) {
  2563. return true;
  2564. }
  2565. }
  2566. return false;
  2567. },
  2568. _hex: function(value) {
  2569. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2570. },
  2571. _hsl: function(value) {
  2572. return /^hsl\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/.test(value);
  2573. },
  2574. _hsla: function(value) {
  2575. return /^hsla\((\s*(-?\d+)\s*,)(\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/.test(value);
  2576. },
  2577. _keyword: function(value) {
  2578. return $.inArray(value, this.KEYWORD_COLORS) >= 0;
  2579. },
  2580. _rgb: function(value) {
  2581. var regexInteger = /^rgb\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){2}(\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*)\)$/,
  2582. regexPercent = /^rgb\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/;
  2583. return regexInteger.test(value) || regexPercent.test(value);
  2584. },
  2585. _rgba: function(value) {
  2586. var regexInteger = /^rgba\((\s*(\b([01]?\d{1,2}|2[0-4]\d|25[0-5])\b)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/,
  2587. regexPercent = /^rgba\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/;
  2588. return regexInteger.test(value) || regexPercent.test(value);
  2589. }
  2590. };
  2591. }(jQuery));
  2592. ;(function($) {
  2593. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2594. 'en_US': {
  2595. creditCard: {
  2596. 'default': 'Please enter a valid credit card number'
  2597. }
  2598. }
  2599. });
  2600. FormValidation.Validator.creditCard = {
  2601. /**
  2602. * Return true if the input value is valid credit card number
  2603. * Based on https://gist.github.com/DiegoSalazar/4075533
  2604. *
  2605. * @param {FormValidation.Base} validator The validator plugin instance
  2606. * @param {jQuery} $field Field element
  2607. * @param {Object} [options] Can consist of the following key:
  2608. * - message: The invalid message
  2609. * @returns {Boolean|Object}
  2610. */
  2611. validate: function(validator, $field, options) {
  2612. var value = validator.getFieldValue($field, 'creditCard');
  2613. if (value === '') {
  2614. return true;
  2615. }
  2616. // Accept only digits, dashes or spaces
  2617. if (/[^0-9-\s]+/.test(value)) {
  2618. return false;
  2619. }
  2620. value = value.replace(/\D/g, '');
  2621. if (!FormValidation.Helper.luhn(value)) {
  2622. return false;
  2623. }
  2624. // Validate the card number based on prefix (IIN ranges) and length
  2625. var cards = {
  2626. AMERICAN_EXPRESS: {
  2627. length: [15],
  2628. prefix: ['34', '37']
  2629. },
  2630. DINERS_CLUB: {
  2631. length: [14],
  2632. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2633. },
  2634. DINERS_CLUB_US: {
  2635. length: [16],
  2636. prefix: ['54', '55']
  2637. },
  2638. DISCOVER: {
  2639. length: [16],
  2640. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2641. '62214', '62215', '62216', '62217', '62218', '62219',
  2642. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2643. '62290', '62291', '622920', '622921', '622922', '622923',
  2644. '622924', '622925', '644', '645', '646', '647', '648',
  2645. '649', '65']
  2646. },
  2647. JCB: {
  2648. length: [16],
  2649. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2650. },
  2651. LASER: {
  2652. length: [16, 17, 18, 19],
  2653. prefix: ['6304', '6706', '6771', '6709']
  2654. },
  2655. MAESTRO: {
  2656. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2657. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2658. },
  2659. MASTERCARD: {
  2660. length: [16],
  2661. prefix: ['51', '52', '53', '54', '55']
  2662. },
  2663. SOLO: {
  2664. length: [16, 18, 19],
  2665. prefix: ['6334', '6767']
  2666. },
  2667. UNIONPAY: {
  2668. length: [16, 17, 18, 19],
  2669. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2670. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2671. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2672. '622920', '622921', '622922', '622923', '622924', '622925']
  2673. },
  2674. VISA: {
  2675. length: [16],
  2676. prefix: ['4']
  2677. }
  2678. };
  2679. var type, i;
  2680. for (type in cards) {
  2681. for (i in cards[type].prefix) {
  2682. if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2683. && $.inArray(value.length, cards[type].length) !== -1) // and length
  2684. {
  2685. return {
  2686. valid: true,
  2687. type: type
  2688. };
  2689. }
  2690. }
  2691. }
  2692. return false;
  2693. }
  2694. };
  2695. }(jQuery));
  2696. ;(function($) {
  2697. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2698. 'en_US': {
  2699. cusip: {
  2700. 'default': 'Please enter a valid CUSIP number'
  2701. }
  2702. }
  2703. });
  2704. FormValidation.Validator.cusip = {
  2705. /**
  2706. * Validate a CUSIP number
  2707. * Examples:
  2708. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  2709. * - Invalid: 31430F200, 022615AC2
  2710. *
  2711. * @see http://en.wikipedia.org/wiki/CUSIP
  2712. * @param {FormValidation.Base} validator The validator plugin instance
  2713. * @param {jQuery} $field Field element
  2714. * @param {Object} [options] Can consist of the following keys:
  2715. * - message: The invalid message
  2716. * @returns {Boolean}
  2717. */
  2718. validate: function(validator, $field, options) {
  2719. var value = validator.getFieldValue($field, 'cusip');
  2720. if (value === '') {
  2721. return true;
  2722. }
  2723. value = value.toUpperCase();
  2724. if (!/^[0-9A-Z]{9}$/.test(value)) {
  2725. return false;
  2726. }
  2727. var converted = $.map(value.split(''), function(item) {
  2728. var code = item.charCodeAt(0);
  2729. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2730. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2731. ? (code - 'A'.charCodeAt(0) + 10)
  2732. : item;
  2733. }),
  2734. length = converted.length,
  2735. sum = 0;
  2736. for (var i = 0; i < length - 1; i++) {
  2737. var num = parseInt(converted[i], 10);
  2738. if (i % 2 !== 0) {
  2739. num *= 2;
  2740. }
  2741. if (num > 9) {
  2742. num -= 9;
  2743. }
  2744. sum += num;
  2745. }
  2746. sum = (10 - (sum % 10)) % 10;
  2747. return sum === parseInt(converted[length - 1], 10);
  2748. }
  2749. };
  2750. }(jQuery));
  2751. ;(function($) {
  2752. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2753. 'en_US': {
  2754. cvv: {
  2755. 'default': 'Please enter a valid CVV number'
  2756. }
  2757. }
  2758. });
  2759. FormValidation.Validator.cvv = {
  2760. html5Attributes: {
  2761. message: 'message',
  2762. ccfield: 'creditCardField'
  2763. },
  2764. /**
  2765. * Bind the validator on the live change of the credit card field
  2766. *
  2767. * @param {FormValidation.Base} validator The validator plugin instance
  2768. * @param {jQuery} $field Field element
  2769. * @param {Object} options Consists of the following key:
  2770. * - creditCardField: The credit card number field
  2771. */
  2772. init: function(validator, $field, options) {
  2773. if (options.creditCardField) {
  2774. var creditCardField = validator.getFieldElements(options.creditCardField);
  2775. validator.onLiveChange(creditCardField, 'live_cvv', function() {
  2776. var status = validator.getStatus($field, 'cvv');
  2777. if (status !== validator.STATUS_NOT_VALIDATED) {
  2778. validator.revalidateField($field);
  2779. }
  2780. });
  2781. }
  2782. },
  2783. /**
  2784. * Unbind the validator on the live change of the credit card field
  2785. *
  2786. * @param {FormValidation.Base} validator The validator plugin instance
  2787. * @param {jQuery} $field Field element
  2788. * @param {Object} options Consists of the following key:
  2789. * - creditCardField: The credit card number field
  2790. */
  2791. destroy: function(validator, $field, options) {
  2792. if (options.creditCardField) {
  2793. var creditCardField = validator.getFieldElements(options.creditCardField);
  2794. validator.offLiveChange(creditCardField, 'live_cvv');
  2795. }
  2796. },
  2797. /**
  2798. * Return true if the input value is a valid CVV number.
  2799. *
  2800. * @param {FormValidation.Base} validator The validator plugin instance
  2801. * @param {jQuery} $field Field element
  2802. * @param {Object} options Can consist of the following keys:
  2803. * - creditCardField: The credit card number field. It can be null
  2804. * - message: The invalid message
  2805. * @returns {Boolean}
  2806. */
  2807. validate: function(validator, $field, options) {
  2808. var value = validator.getFieldValue($field, 'cvv');
  2809. if (value === '') {
  2810. return true;
  2811. }
  2812. if (!/^[0-9]{3,4}$/.test(value)) {
  2813. return false;
  2814. }
  2815. if (!options.creditCardField) {
  2816. return true;
  2817. }
  2818. // Get the credit card number
  2819. var creditCard = validator.getFieldElements(options.creditCardField).val();
  2820. if (creditCard === '') {
  2821. return true;
  2822. }
  2823. creditCard = creditCard.replace(/\D/g, '');
  2824. // Supported credit card types
  2825. var cards = {
  2826. AMERICAN_EXPRESS: {
  2827. length: [15],
  2828. prefix: ['34', '37']
  2829. },
  2830. DINERS_CLUB: {
  2831. length: [14],
  2832. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2833. },
  2834. DINERS_CLUB_US: {
  2835. length: [16],
  2836. prefix: ['54', '55']
  2837. },
  2838. DISCOVER: {
  2839. length: [16],
  2840. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2841. '62214', '62215', '62216', '62217', '62218', '62219',
  2842. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2843. '62290', '62291', '622920', '622921', '622922', '622923',
  2844. '622924', '622925', '644', '645', '646', '647', '648',
  2845. '649', '65']
  2846. },
  2847. JCB: {
  2848. length: [16],
  2849. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2850. },
  2851. LASER: {
  2852. length: [16, 17, 18, 19],
  2853. prefix: ['6304', '6706', '6771', '6709']
  2854. },
  2855. MAESTRO: {
  2856. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2857. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2858. },
  2859. MASTERCARD: {
  2860. length: [16],
  2861. prefix: ['51', '52', '53', '54', '55']
  2862. },
  2863. SOLO: {
  2864. length: [16, 18, 19],
  2865. prefix: ['6334', '6767']
  2866. },
  2867. UNIONPAY: {
  2868. length: [16, 17, 18, 19],
  2869. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2870. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2871. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2872. '622920', '622921', '622922', '622923', '622924', '622925']
  2873. },
  2874. VISA: {
  2875. length: [16],
  2876. prefix: ['4']
  2877. }
  2878. };
  2879. var type, i, creditCardType = null;
  2880. for (type in cards) {
  2881. for (i in cards[type].prefix) {
  2882. if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2883. && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
  2884. {
  2885. creditCardType = type;
  2886. break;
  2887. }
  2888. }
  2889. }
  2890. return (creditCardType === null)
  2891. ? false
  2892. : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  2893. }
  2894. };
  2895. }(jQuery));
  2896. ;(function($) {
  2897. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  2898. 'en_US': {
  2899. date: {
  2900. 'default': 'Please enter a valid date',
  2901. min: 'Please enter a date after %s',
  2902. max: 'Please enter a date before %s',
  2903. range: 'Please enter a date in the range %s - %s'
  2904. }
  2905. }
  2906. });
  2907. FormValidation.Validator.date = {
  2908. html5Attributes: {
  2909. message: 'message',
  2910. format: 'format',
  2911. min: 'min',
  2912. max: 'max',
  2913. separator: 'separator'
  2914. },
  2915. /**
  2916. * Return true if the input value is valid date
  2917. *
  2918. * @param {FormValidation.Base} validator The validator plugin instance
  2919. * @param {jQuery} $field Field element
  2920. * @param {Object} options Can consist of the following keys:
  2921. * - message: The invalid message
  2922. * - min: the minimum date
  2923. * - max: the maximum date
  2924. * - separator: Use to separate the date, month, and year.
  2925. * By default, it is /
  2926. * - format: The date format. Default is MM/DD/YYYY
  2927. * The format can be:
  2928. *
  2929. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2930. * ii) date and time:
  2931. * The time can consist of h, m, s parts which are separated by :
  2932. * ii) date, time and A (indicating AM or PM)
  2933. * @returns {Boolean|Object}
  2934. */
  2935. validate: function(validator, $field, options) {
  2936. var value = validator.getFieldValue($field, 'date');
  2937. if (value === '') {
  2938. return true;
  2939. }
  2940. options.format = options.format || 'MM/DD/YYYY';
  2941. // #683: Force the format to YYYY-MM-DD as the default browser behaviour when using type="date" attribute
  2942. if ($field.attr('type') === 'date') {
  2943. options.format = 'YYYY-MM-DD';
  2944. }
  2945. var locale = validator.getLocale(),
  2946. message = options.message || FormValidation.I18n[locale].date['default'],
  2947. formats = options.format.split(' '),
  2948. dateFormat = formats[0],
  2949. timeFormat = (formats.length > 1) ? formats[1] : null,
  2950. amOrPm = (formats.length > 2) ? formats[2] : null,
  2951. sections = value.split(' '),
  2952. date = sections[0],
  2953. time = (sections.length > 1) ? sections[1] : null;
  2954. if (formats.length !== sections.length) {
  2955. return {
  2956. valid: false,
  2957. message: message
  2958. };
  2959. }
  2960. // Determine the separator
  2961. var separator = options.separator;
  2962. if (!separator) {
  2963. separator = (date.indexOf('/') !== -1)
  2964. ? '/'
  2965. : ((date.indexOf('-') !== -1) ? '-' : ((date.indexOf('.') !== -1) ? '.' : null));
  2966. }
  2967. if (separator === null || date.indexOf(separator) === -1) {
  2968. return {
  2969. valid: false,
  2970. message: message
  2971. };
  2972. }
  2973. // Determine the date
  2974. date = date.split(separator);
  2975. dateFormat = dateFormat.split(separator);
  2976. if (date.length !== dateFormat.length) {
  2977. return {
  2978. valid: false,
  2979. message: message
  2980. };
  2981. }
  2982. var year = date[$.inArray('YYYY', dateFormat)],
  2983. month = date[$.inArray('MM', dateFormat)],
  2984. day = date[$.inArray('DD', dateFormat)];
  2985. if (!year || !month || !day || year.length !== 4) {
  2986. return {
  2987. valid: false,
  2988. message: message
  2989. };
  2990. }
  2991. // Determine the time
  2992. var minutes = null, hours = null, seconds = null;
  2993. if (timeFormat) {
  2994. timeFormat = timeFormat.split(':');
  2995. time = time.split(':');
  2996. if (timeFormat.length !== time.length) {
  2997. return {
  2998. valid: false,
  2999. message: message
  3000. };
  3001. }
  3002. hours = time.length > 0 ? time[0] : null;
  3003. minutes = time.length > 1 ? time[1] : null;
  3004. seconds = time.length > 2 ? time[2] : null;
  3005. if (hours === '' || minutes === '' || seconds === '') {
  3006. return {
  3007. valid: false,
  3008. message: message
  3009. };
  3010. }
  3011. // Validate seconds
  3012. if (seconds) {
  3013. if (isNaN(seconds) || seconds.length > 2) {
  3014. return {
  3015. valid: false,
  3016. message: message
  3017. };
  3018. }
  3019. seconds = parseInt(seconds, 10);
  3020. if (seconds < 0 || seconds > 60) {
  3021. return {
  3022. valid: false,
  3023. message: message
  3024. };
  3025. }
  3026. }
  3027. // Validate hours
  3028. if (hours) {
  3029. if (isNaN(hours) || hours.length > 2) {
  3030. return {
  3031. valid: false,
  3032. message: message
  3033. };
  3034. }
  3035. hours = parseInt(hours, 10);
  3036. if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  3037. return {
  3038. valid: false,
  3039. message: message
  3040. };
  3041. }
  3042. }
  3043. // Validate minutes
  3044. if (minutes) {
  3045. if (isNaN(minutes) || minutes.length > 2) {
  3046. return {
  3047. valid: false,
  3048. message: message
  3049. };
  3050. }
  3051. minutes = parseInt(minutes, 10);
  3052. if (minutes < 0 || minutes > 59) {
  3053. return {
  3054. valid: false,
  3055. message: message
  3056. };
  3057. }
  3058. }
  3059. }
  3060. // Validate day, month, and year
  3061. var valid = FormValidation.Helper.date(year, month, day),
  3062. // declare the date, min and max objects
  3063. min = null,
  3064. max = null,
  3065. minOption = options.min,
  3066. maxOption = options.max;
  3067. if (minOption) {
  3068. if (isNaN(Date.parse(minOption))) {
  3069. minOption = validator.getDynamicOption($field, minOption);
  3070. }
  3071. min = minOption instanceof Date ? minOption : this._parseDate(minOption, dateFormat, separator);
  3072. // In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)"
  3073. minOption = minOption instanceof Date ? this._formatDate(minOption, options.format) : minOption;
  3074. }
  3075. if (maxOption) {
  3076. if (isNaN(Date.parse(maxOption))) {
  3077. maxOption = validator.getDynamicOption($field, maxOption);
  3078. }
  3079. max = maxOption instanceof Date ? maxOption : this._parseDate(maxOption, dateFormat, separator);
  3080. // In order to avoid displaying a date string like "Mon Dec 08 2014 19:14:12 GMT+0000 (WET)"
  3081. maxOption = maxOption instanceof Date ? this._formatDate(maxOption, options.format) : maxOption;
  3082. }
  3083. date = new Date(year, month -1, day, hours, minutes, seconds);
  3084. switch (true) {
  3085. case (minOption && !maxOption && valid):
  3086. valid = date.getTime() >= min.getTime();
  3087. message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.min, minOption);
  3088. break;
  3089. case (maxOption && !minOption && valid):
  3090. valid = date.getTime() <= max.getTime();
  3091. message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.max, maxOption);
  3092. break;
  3093. case (maxOption && minOption && valid):
  3094. valid = date.getTime() <= max.getTime() && date.getTime() >= min.getTime();
  3095. message = options.message || FormValidation.Helper.format(FormValidation.I18n[locale].date.range, [minOption, maxOption]);
  3096. break;
  3097. default:
  3098. break;
  3099. }
  3100. return {
  3101. valid: valid,
  3102. message: message
  3103. };
  3104. },
  3105. /**
  3106. * Return a date object after parsing the date string
  3107. *
  3108. * @param {String} date The date string to parse
  3109. * @param {String} format The date format
  3110. * The format can be:
  3111. * - date: Consist of DD, MM, YYYY parts which are separated by the separator option
  3112. * - date and time:
  3113. * The time can consist of h, m, s parts which are separated by :
  3114. * @param {String} separator The separator used to separate the date, month, and year
  3115. * @returns {Date}
  3116. */
  3117. _parseDate: function(date, format, separator) {
  3118. var minutes = 0, hours = 0, seconds = 0,
  3119. sections = date.split(' '),
  3120. dateSection = sections[0],
  3121. timeSection = (sections.length > 1) ? sections[1] : null;
  3122. dateSection = dateSection.split(separator);
  3123. var year = dateSection[$.inArray('YYYY', format)],
  3124. month = dateSection[$.inArray('MM', format)],
  3125. day = dateSection[$.inArray('DD', format)];
  3126. if (timeSection) {
  3127. timeSection = timeSection.split(':');
  3128. hours = timeSection.length > 0 ? timeSection[0] : null;
  3129. minutes = timeSection.length > 1 ? timeSection[1] : null;
  3130. seconds = timeSection.length > 2 ? timeSection[2] : null;
  3131. }
  3132. return new Date(year, month -1, day, hours, minutes, seconds);
  3133. },
  3134. /**
  3135. * Format date
  3136. *
  3137. * @param {Date} date The date object to format
  3138. * @param {String} format The date format
  3139. * The format can consist of the following tokens:
  3140. * d Day of the month without leading zeros (1 through 31)
  3141. * dd Day of the month with leading zeros (01 through 31)
  3142. * m Month without leading zeros (1 through 12)
  3143. * mm Month with leading zeros (01 through 12)
  3144. * yy Last two digits of year (for example: 14)
  3145. * yyyy Full four digits of year (for example: 2014)
  3146. * h Hours without leading zeros (1 through 12)
  3147. * hh Hours with leading zeros (01 through 12)
  3148. * H Hours without leading zeros (0 through 23)
  3149. * HH Hours with leading zeros (00 through 23)
  3150. * M Minutes without leading zeros (0 through 59)
  3151. * MM Minutes with leading zeros (00 through 59)
  3152. * s Seconds without leading zeros (0 through 59)
  3153. * ss Seconds with leading zeros (00 through 59)
  3154. * @returns {String}
  3155. */
  3156. _formatDate: function(date, format) {
  3157. format = format
  3158. .replace(/Y/g, 'y')
  3159. .replace(/M/g, 'm')
  3160. .replace(/D/g, 'd')
  3161. .replace(/:m/g, ':M')
  3162. .replace(/:mm/g, ':MM')
  3163. .replace(/:S/, ':s')
  3164. .replace(/:SS/, ':ss');
  3165. var replacer = {
  3166. d: function(date) {
  3167. return date.getDate();
  3168. },
  3169. dd: function(date) {
  3170. var d = date.getDate();
  3171. return (d < 10) ? '0' + d : d;
  3172. },
  3173. m: function(date) {
  3174. return date.getMonth() + 1;
  3175. },
  3176. mm: function(date) {
  3177. var m = date.getMonth() + 1;
  3178. return m < 10 ? '0' + m : m;
  3179. },
  3180. yy: function(date) {
  3181. return ('' + date.getFullYear()).substr(2);
  3182. },
  3183. yyyy: function(date) {
  3184. return date.getFullYear();
  3185. },
  3186. h: function(date) {
  3187. return date.getHours() % 12 || 12;
  3188. },
  3189. hh: function(date) {
  3190. var h = date.getHours() % 12 || 12;
  3191. return h < 10 ? '0' + h : h;
  3192. },
  3193. H: function(date) {
  3194. return date.getHours();
  3195. },
  3196. HH: function(date) {
  3197. var H = date.getHours();
  3198. return H < 10 ? '0' + H : H;
  3199. },
  3200. M: function(date) {
  3201. return date.getMinutes();
  3202. },
  3203. MM: function(date) {
  3204. var M = date.getMinutes();
  3205. return M < 10 ? '0' + M : M;
  3206. },
  3207. s: function(date) {
  3208. return date.getSeconds();
  3209. },
  3210. ss: function(date) {
  3211. var s = date.getSeconds();
  3212. return s < 10 ? '0' + s : s;
  3213. }
  3214. };
  3215. return format.replace(/d{1,4}|m{1,4}|yy(?:yy)?|([HhMs])\1?|"[^"]*"|'[^']*'/g, function(match) {
  3216. return replacer[match] ? replacer[match](date) : match.slice(1, match.length - 1);
  3217. });
  3218. }
  3219. };
  3220. }(jQuery));
  3221. ;(function($) {
  3222. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3223. 'en_US': {
  3224. different: {
  3225. 'default': 'Please enter a different value'
  3226. }
  3227. }
  3228. });
  3229. FormValidation.Validator.different = {
  3230. html5Attributes: {
  3231. message: 'message',
  3232. field: 'field'
  3233. },
  3234. /**
  3235. * Bind the validator on the live change of the field to compare with current one
  3236. *
  3237. * @param {FormValidation.Base} validator The validator plugin instance
  3238. * @param {jQuery} $field Field element
  3239. * @param {Object} options Consists of the following key:
  3240. * - field: The name of field that will be used to compare with current one
  3241. */
  3242. init: function(validator, $field, options) {
  3243. var fields = options.field.split(',');
  3244. for (var i = 0; i < fields.length; i++) {
  3245. var compareWith = validator.getFieldElements(fields[i]);
  3246. validator.onLiveChange(compareWith, 'live_different', function() {
  3247. var status = validator.getStatus($field, 'different');
  3248. if (status !== validator.STATUS_NOT_VALIDATED) {
  3249. validator.revalidateField($field);
  3250. }
  3251. });
  3252. }
  3253. },
  3254. /**
  3255. * Unbind the validator on the live change of the field to compare with current one
  3256. *
  3257. * @param {FormValidation.Base} validator The validator plugin instance
  3258. * @param {jQuery} $field Field element
  3259. * @param {Object} options Consists of the following key:
  3260. * - field: The name of field that will be used to compare with current one
  3261. */
  3262. destroy: function(validator, $field, options) {
  3263. var fields = options.field.split(',');
  3264. for (var i = 0; i < fields.length; i++) {
  3265. var compareWith = validator.getFieldElements(fields[i]);
  3266. validator.offLiveChange(compareWith, 'live_different');
  3267. }
  3268. },
  3269. /**
  3270. * Return true if the input value is different with given field's value
  3271. *
  3272. * @param {FormValidation.Base} validator The validator plugin instance
  3273. * @param {jQuery} $field Field element
  3274. * @param {Object} options Consists of the following key:
  3275. * - field: The name of field that will be used to compare with current one
  3276. * - message: The invalid message
  3277. * @returns {Boolean}
  3278. */
  3279. validate: function(validator, $field, options) {
  3280. var value = validator.getFieldValue($field, 'different');
  3281. if (value === '') {
  3282. return true;
  3283. }
  3284. var fields = options.field.split(','),
  3285. isValid = true;
  3286. for (var i = 0; i < fields.length; i++) {
  3287. var compareWith = validator.getFieldElements(fields[i]);
  3288. if (compareWith == null || compareWith.length === 0) {
  3289. continue;
  3290. }
  3291. var compareValue = validator.getFieldValue(compareWith, 'different');
  3292. if (value === compareValue) {
  3293. isValid = false;
  3294. } else if (compareValue !== '') {
  3295. validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
  3296. }
  3297. }
  3298. return isValid;
  3299. }
  3300. };
  3301. }(jQuery));
  3302. ;(function($) {
  3303. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3304. 'en_US': {
  3305. digits: {
  3306. 'default': 'Please enter only digits'
  3307. }
  3308. }
  3309. });
  3310. FormValidation.Validator.digits = {
  3311. /**
  3312. * Return true if the input value contains digits only
  3313. *
  3314. * @param {FormValidation.Base} validator Validate plugin instance
  3315. * @param {jQuery} $field Field element
  3316. * @param {Object} [options]
  3317. * @returns {Boolean}
  3318. */
  3319. validate: function(validator, $field, options) {
  3320. var value = validator.getFieldValue($field, 'digits');
  3321. if (value === '') {
  3322. return true;
  3323. }
  3324. return /^\d+$/.test(value);
  3325. }
  3326. };
  3327. }(jQuery));
  3328. ;(function($) {
  3329. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3330. 'en_US': {
  3331. ean: {
  3332. 'default': 'Please enter a valid EAN number'
  3333. }
  3334. }
  3335. });
  3336. FormValidation.Validator.ean = {
  3337. /**
  3338. * Validate EAN (International Article Number)
  3339. * Examples:
  3340. * - Valid: 73513537, 9780471117094, 4006381333931
  3341. * - Invalid: 73513536
  3342. *
  3343. * @see http://en.wikipedia.org/wiki/European_Article_Number
  3344. * @param {FormValidation.Base} validator The validator plugin instance
  3345. * @param {jQuery} $field Field element
  3346. * @param {Object} options Can consist of the following keys:
  3347. * - message: The invalid message
  3348. * @returns {Boolean}
  3349. */
  3350. validate: function(validator, $field, options) {
  3351. var value = validator.getFieldValue($field, 'ean');
  3352. if (value === '') {
  3353. return true;
  3354. }
  3355. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  3356. return false;
  3357. }
  3358. var length = value.length,
  3359. sum = 0,
  3360. weight = (length === 8) ? [3, 1] : [1, 3];
  3361. for (var i = 0; i < length - 1; i++) {
  3362. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3363. }
  3364. sum = (10 - sum % 10) % 10;
  3365. return (sum + '' === value.charAt(length - 1));
  3366. }
  3367. };
  3368. }(jQuery));
  3369. ;(function($) {
  3370. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3371. 'en_US': {
  3372. ein: {
  3373. 'default': 'Please enter a valid EIN number'
  3374. }
  3375. }
  3376. });
  3377. FormValidation.Validator.ein = {
  3378. // The first two digits are called campus
  3379. // See http://en.wikipedia.org/wiki/Employer_Identification_Number
  3380. // http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes
  3381. CAMPUS: {
  3382. ANDOVER: ['10', '12'],
  3383. ATLANTA: ['60', '67'],
  3384. AUSTIN: ['50', '53'],
  3385. 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'],
  3386. CINCINNATI: ['30', '32', '35', '36', '37', '38', '61'],
  3387. FRESNO: ['15', '24'],
  3388. KANSAS_CITY: ['40', '44'],
  3389. MEMPHIS: ['94', '95'],
  3390. OGDEN: ['80', '90'],
  3391. 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'],
  3392. INTERNET: ['20', '26', '27', '45', '46'],
  3393. SMALL_BUSINESS_ADMINISTRATION: ['31']
  3394. },
  3395. /**
  3396. * Validate EIN (Employer Identification Number) which is also known as
  3397. * Federal Employer Identification Number (FEIN) or Federal Tax Identification Number
  3398. *
  3399. * @param {FormValidation.Base} validator The validator plugin instance
  3400. * @param {jQuery} $field Field element
  3401. * @param {Object} options Can consist of the following keys:
  3402. * - message: The invalid message
  3403. * @returns {Object|Boolean}
  3404. */
  3405. validate: function(validator, $field, options) {
  3406. var value = validator.getFieldValue($field, 'ein');
  3407. if (value === '') {
  3408. return true;
  3409. }
  3410. if (!/^[0-9]{2}-?[0-9]{7}$/.test(value)) {
  3411. return false;
  3412. }
  3413. // Check the first two digits
  3414. var campus = value.substr(0, 2) + '';
  3415. for (var key in this.CAMPUS) {
  3416. if ($.inArray(campus, this.CAMPUS[key]) !== -1) {
  3417. return {
  3418. valid: true,
  3419. campus: key
  3420. };
  3421. }
  3422. }
  3423. return false;
  3424. }
  3425. };
  3426. }(jQuery));
  3427. ;(function($) {
  3428. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3429. 'en_US': {
  3430. emailAddress: {
  3431. 'default': 'Please enter a valid email address'
  3432. }
  3433. }
  3434. });
  3435. FormValidation.Validator.emailAddress = {
  3436. html5Attributes: {
  3437. message: 'message',
  3438. multiple: 'multiple',
  3439. separator: 'separator'
  3440. },
  3441. enableByHtml5: function($field) {
  3442. return ('email' === $field.attr('type'));
  3443. },
  3444. /**
  3445. * Return true if and only if the input value is a valid email address
  3446. *
  3447. * @param {FormValidation.Base} validator Validate plugin instance
  3448. * @param {jQuery} $field Field element
  3449. * @param {Object} [options]
  3450. * - multiple: Allow multiple email addresses, separated by a comma or semicolon; default is false.
  3451. * - separator: Regex for character or characters expected as separator between addresses; default is comma /[,;]/, i.e. comma or semicolon.
  3452. * @returns {Boolean}
  3453. */
  3454. validate: function(validator, $field, options) {
  3455. var value = validator.getFieldValue($field, 'emailAddress');
  3456. if (value === '') {
  3457. return true;
  3458. }
  3459. // Email address regular expression
  3460. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  3461. var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
  3462. allowMultiple = options.multiple === true || options.multiple === 'true';
  3463. if (allowMultiple) {
  3464. var separator = options.separator || /[,;]/,
  3465. addresses = this._splitEmailAddresses(value, separator);
  3466. for (var i = 0; i < addresses.length; i++) {
  3467. if (!emailRegExp.test(addresses[i])) {
  3468. return false;
  3469. }
  3470. }
  3471. return true;
  3472. } else {
  3473. return emailRegExp.test(value);
  3474. }
  3475. },
  3476. _splitEmailAddresses: function(emailAddresses, separator) {
  3477. var quotedFragments = emailAddresses.split(/"/),
  3478. quotedFragmentCount = quotedFragments.length,
  3479. emailAddressArray = [],
  3480. nextEmailAddress = '';
  3481. for (var i = 0; i < quotedFragmentCount; i++) {
  3482. if (i % 2 === 0) {
  3483. var splitEmailAddressFragments = quotedFragments[i].split(separator),
  3484. splitEmailAddressFragmentCount = splitEmailAddressFragments.length;
  3485. if (splitEmailAddressFragmentCount === 1) {
  3486. nextEmailAddress += splitEmailAddressFragments[0];
  3487. } else {
  3488. emailAddressArray.push(nextEmailAddress + splitEmailAddressFragments[0]);
  3489. for (var j = 1; j < splitEmailAddressFragmentCount - 1; j++) {
  3490. emailAddressArray.push(splitEmailAddressFragments[j]);
  3491. }
  3492. nextEmailAddress = splitEmailAddressFragments[splitEmailAddressFragmentCount - 1];
  3493. }
  3494. } else {
  3495. nextEmailAddress += '"' + quotedFragments[i];
  3496. if (i < quotedFragmentCount - 1) {
  3497. nextEmailAddress += '"';
  3498. }
  3499. }
  3500. }
  3501. emailAddressArray.push(nextEmailAddress);
  3502. return emailAddressArray;
  3503. }
  3504. };
  3505. }(jQuery));
  3506. ;(function($) {
  3507. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3508. 'en_US': {
  3509. file: {
  3510. 'default': 'Please choose a valid file'
  3511. }
  3512. }
  3513. });
  3514. FormValidation.Validator.file = {
  3515. html5Attributes: {
  3516. extension: 'extension',
  3517. maxfiles: 'maxFiles',
  3518. minfiles: 'minFiles',
  3519. maxsize: 'maxSize',
  3520. minsize: 'minSize',
  3521. maxtotalsize: 'maxTotalSize',
  3522. mintotalsize: 'minTotalSize',
  3523. message: 'message',
  3524. type: 'type'
  3525. },
  3526. /**
  3527. * Validate upload file. Use HTML 5 API if the browser supports
  3528. *
  3529. * @param {FormValidation.Base} validator The validator plugin instance
  3530. * @param {jQuery} $field Field element
  3531. * @param {Object} options Can consist of the following keys:
  3532. * - extension: The allowed extensions, separated by a comma
  3533. * - maxFiles: The maximum number of files
  3534. * - minFiles: The minimum number of files
  3535. * - maxSize: The maximum size in bytes
  3536. * - minSize: The minimum size in bytes
  3537. * - maxTotalSize: The maximum size in bytes for all files
  3538. * - minTotalSize: The minimum size in bytes for all files
  3539. * - message: The invalid message
  3540. * - type: The allowed MIME type, separated by a comma
  3541. * @returns {Boolean}
  3542. */
  3543. validate: function(validator, $field, options) {
  3544. var value = validator.getFieldValue($field, 'file');
  3545. if (value === '') {
  3546. return true;
  3547. }
  3548. var ext,
  3549. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  3550. types = options.type ? options.type.toLowerCase().split(',') : null,
  3551. html5 = (window.File && window.FileList && window.FileReader);
  3552. if (html5) {
  3553. // Get FileList instance
  3554. var files = $field.get(0).files,
  3555. total = files.length,
  3556. totalSize = 0;
  3557. if ((options.maxFiles && total > parseInt(options.maxFiles, 10)) // Check the maxFiles
  3558. || (options.minFiles && total < parseInt(options.minFiles, 10))) // Check the minFiles
  3559. {
  3560. return false;
  3561. }
  3562. for (var i = 0; i < total; i++) {
  3563. totalSize += files[i].size;
  3564. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  3565. if ((options.minSize && files[i].size < parseInt(options.minSize, 10)) // Check the minSize
  3566. || (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) // Check the maxSize
  3567. || (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) // Check file extension
  3568. || (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1)) // Check file type
  3569. {
  3570. return false;
  3571. }
  3572. }
  3573. if ((options.maxTotalSize && totalSize > parseInt(options.maxTotalSize, 10)) // Check the maxTotalSize
  3574. || (options.minTotalSize && totalSize < parseInt(options.minTotalSize, 10))) // Check the minTotalSize
  3575. {
  3576. return false;
  3577. }
  3578. } else {
  3579. // Check file extension
  3580. ext = value.substr(value.lastIndexOf('.') + 1);
  3581. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  3582. return false;
  3583. }
  3584. }
  3585. return true;
  3586. }
  3587. };
  3588. }(jQuery));
  3589. ;(function($) {
  3590. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3591. 'en_US': {
  3592. greaterThan: {
  3593. 'default': 'Please enter a value greater than or equal to %s',
  3594. notInclusive: 'Please enter a value greater than %s'
  3595. }
  3596. }
  3597. });
  3598. FormValidation.Validator.greaterThan = {
  3599. html5Attributes: {
  3600. message: 'message',
  3601. value: 'value',
  3602. inclusive: 'inclusive'
  3603. },
  3604. enableByHtml5: function($field) {
  3605. var type = $field.attr('type'),
  3606. min = $field.attr('min');
  3607. if (min && type !== 'date') {
  3608. return {
  3609. value: min
  3610. };
  3611. }
  3612. return false;
  3613. },
  3614. /**
  3615. * Return true if the input value is greater than or equals to given number
  3616. *
  3617. * @param {FormValidation.Base} validator Validate plugin instance
  3618. * @param {jQuery} $field Field element
  3619. * @param {Object} options Can consist of the following keys:
  3620. * - value: Define the number to compare with. It can be
  3621. * - A number
  3622. * - Name of field which its value defines the number
  3623. * - Name of callback function that returns the number
  3624. * - A callback function that returns the number
  3625. *
  3626. * - inclusive [optional]: Can be true or false. Default is true
  3627. * - message: The invalid message
  3628. * @returns {Boolean|Object}
  3629. */
  3630. validate: function(validator, $field, options) {
  3631. var value = validator.getFieldValue($field, 'greaterThan');
  3632. if (value === '') {
  3633. return true;
  3634. }
  3635. value = this._format(value);
  3636. if (!$.isNumeric(value)) {
  3637. return false;
  3638. }
  3639. var locale = validator.getLocale(),
  3640. compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
  3641. compareToValue = this._format(compareTo);
  3642. value = parseFloat(value);
  3643. return (options.inclusive === true || options.inclusive === undefined)
  3644. ? {
  3645. valid: value >= compareToValue,
  3646. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].greaterThan['default'], compareTo)
  3647. }
  3648. : {
  3649. valid: value > compareToValue,
  3650. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].greaterThan.notInclusive, compareTo)
  3651. };
  3652. },
  3653. _format: function(value) {
  3654. return (value + '').replace(',', '.');
  3655. }
  3656. };
  3657. }(jQuery));
  3658. ;(function($) {
  3659. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3660. 'en_US': {
  3661. grid: {
  3662. 'default': 'Please enter a valid GRId number'
  3663. }
  3664. }
  3665. });
  3666. FormValidation.Validator.grid = {
  3667. /**
  3668. * Validate GRId (Global Release Identifier)
  3669. * Examples:
  3670. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  3671. * - Invalid: A1-2425G-ABC1234002-Q
  3672. *
  3673. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  3674. * @param {FormValidation.Base} validator The validator plugin instance
  3675. * @param {jQuery} $field Field element
  3676. * @param {Object} options Can consist of the following keys:
  3677. * - message: The invalid message
  3678. * @returns {Boolean}
  3679. */
  3680. validate: function(validator, $field, options) {
  3681. var value = validator.getFieldValue($field, 'grid');
  3682. if (value === '') {
  3683. return true;
  3684. }
  3685. value = value.toUpperCase();
  3686. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  3687. return false;
  3688. }
  3689. value = value.replace(/\s/g, '').replace(/-/g, '');
  3690. if ('GRID:' === value.substr(0, 5)) {
  3691. value = value.substr(5);
  3692. }
  3693. return FormValidation.Helper.mod37And36(value);
  3694. }
  3695. };
  3696. }(jQuery));
  3697. ;(function($) {
  3698. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3699. 'en_US': {
  3700. hex: {
  3701. 'default': 'Please enter a valid hexadecimal number'
  3702. }
  3703. }
  3704. });
  3705. FormValidation.Validator.hex = {
  3706. /**
  3707. * Return true if and only if the input value is a valid hexadecimal number
  3708. *
  3709. * @param {FormValidation.Base} validator The validator plugin instance
  3710. * @param {jQuery} $field Field element
  3711. * @param {Object} options Consist of key:
  3712. * - message: The invalid message
  3713. * @returns {Boolean}
  3714. */
  3715. validate: function(validator, $field, options) {
  3716. var value = validator.getFieldValue($field, 'hex');
  3717. if (value === '') {
  3718. return true;
  3719. }
  3720. return /^[0-9a-fA-F]+$/.test(value);
  3721. }
  3722. };
  3723. }(jQuery));
  3724. ;(function($) {
  3725. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3726. 'en_US': {
  3727. iban: {
  3728. 'default': 'Please enter a valid IBAN number',
  3729. country: 'Please enter a valid IBAN number in %s',
  3730. countries: {
  3731. AD: 'Andorra',
  3732. AE: 'United Arab Emirates',
  3733. AL: 'Albania',
  3734. AO: 'Angola',
  3735. AT: 'Austria',
  3736. AZ: 'Azerbaijan',
  3737. BA: 'Bosnia and Herzegovina',
  3738. BE: 'Belgium',
  3739. BF: 'Burkina Faso',
  3740. BG: 'Bulgaria',
  3741. BH: 'Bahrain',
  3742. BI: 'Burundi',
  3743. BJ: 'Benin',
  3744. BR: 'Brazil',
  3745. CH: 'Switzerland',
  3746. CI: 'Ivory Coast',
  3747. CM: 'Cameroon',
  3748. CR: 'Costa Rica',
  3749. CV: 'Cape Verde',
  3750. CY: 'Cyprus',
  3751. CZ: 'Czech Republic',
  3752. DE: 'Germany',
  3753. DK: 'Denmark',
  3754. DO: 'Dominican Republic',
  3755. DZ: 'Algeria',
  3756. EE: 'Estonia',
  3757. ES: 'Spain',
  3758. FI: 'Finland',
  3759. FO: 'Faroe Islands',
  3760. FR: 'France',
  3761. GB: 'United Kingdom',
  3762. GE: 'Georgia',
  3763. GI: 'Gibraltar',
  3764. GL: 'Greenland',
  3765. GR: 'Greece',
  3766. GT: 'Guatemala',
  3767. HR: 'Croatia',
  3768. HU: 'Hungary',
  3769. IE: 'Ireland',
  3770. IL: 'Israel',
  3771. IR: 'Iran',
  3772. IS: 'Iceland',
  3773. IT: 'Italy',
  3774. JO: 'Jordan',
  3775. KW: 'Kuwait',
  3776. KZ: 'Kazakhstan',
  3777. LB: 'Lebanon',
  3778. LI: 'Liechtenstein',
  3779. LT: 'Lithuania',
  3780. LU: 'Luxembourg',
  3781. LV: 'Latvia',
  3782. MC: 'Monaco',
  3783. MD: 'Moldova',
  3784. ME: 'Montenegro',
  3785. MG: 'Madagascar',
  3786. MK: 'Macedonia',
  3787. ML: 'Mali',
  3788. MR: 'Mauritania',
  3789. MT: 'Malta',
  3790. MU: 'Mauritius',
  3791. MZ: 'Mozambique',
  3792. NL: 'Netherlands',
  3793. NO: 'Norway',
  3794. PK: 'Pakistan',
  3795. PL: 'Poland',
  3796. PS: 'Palestine',
  3797. PT: 'Portugal',
  3798. QA: 'Qatar',
  3799. RO: 'Romania',
  3800. RS: 'Serbia',
  3801. SA: 'Saudi Arabia',
  3802. SE: 'Sweden',
  3803. SI: 'Slovenia',
  3804. SK: 'Slovakia',
  3805. SM: 'San Marino',
  3806. SN: 'Senegal',
  3807. TN: 'Tunisia',
  3808. TR: 'Turkey',
  3809. VG: 'Virgin Islands, British'
  3810. }
  3811. }
  3812. }
  3813. });
  3814. FormValidation.Validator.iban = {
  3815. html5Attributes: {
  3816. message: 'message',
  3817. country: 'country'
  3818. },
  3819. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  3820. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  3821. REGEX: {
  3822. AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  3823. AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  3824. AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  3825. AO: 'AO[0-9]{2}[0-9]{21}', // Angola
  3826. AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  3827. AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  3828. BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  3829. BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  3830. BF: 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  3831. BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  3832. BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  3833. BI: 'BI[0-9]{2}[0-9]{12}', // Burundi
  3834. BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  3835. BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  3836. CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  3837. CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  3838. CM: 'CM[0-9]{2}[0-9]{23}', // Cameroon
  3839. CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  3840. CV: 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  3841. CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  3842. CZ: 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  3843. DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  3844. DK: 'DK[0-9]{2}[0-9]{14}', // Denmark
  3845. DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  3846. DZ: 'DZ[0-9]{2}[0-9]{20}', // Algeria
  3847. EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  3848. ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  3849. FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  3850. FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  3851. FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  3852. GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  3853. GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  3854. GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  3855. GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland
  3856. GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  3857. GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  3858. HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  3859. HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  3860. IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  3861. IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  3862. IR: 'IR[0-9]{2}[0-9]{22}', // Iran
  3863. IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  3864. IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  3865. JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  3866. KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  3867. KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  3868. LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  3869. LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  3870. LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  3871. LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  3872. LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  3873. MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  3874. MD: 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  3875. ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  3876. MG: 'MG[0-9]{2}[0-9]{23}', // Madagascar
  3877. MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  3878. ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  3879. MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  3880. MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  3881. MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}', // Mauritius
  3882. MZ: 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  3883. NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  3884. NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  3885. PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  3886. PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  3887. PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  3888. PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  3889. QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  3890. RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  3891. RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  3892. SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  3893. SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  3894. SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  3895. SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  3896. SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  3897. SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  3898. TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  3899. TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  3900. VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  3901. },
  3902. /**
  3903. * Validate an International Bank Account Number (IBAN)
  3904. * To test it, take the sample IBAN from
  3905. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  3906. *
  3907. * @param {FormValidation.Base} validator The validator plugin instance
  3908. * @param {jQuery} $field Field element
  3909. * @param {Object} options Can consist of the following keys:
  3910. * - message: The invalid message
  3911. * - country: The ISO 3166-1 country code. It can be
  3912. * - A country code
  3913. * - Name of field which its value defines the country code
  3914. * - Name of callback function that returns the country code
  3915. * - A callback function that returns the country code
  3916. * @returns {Boolean|Object}
  3917. */
  3918. validate: function(validator, $field, options) {
  3919. var value = validator.getFieldValue($field, 'iban');
  3920. if (value === '') {
  3921. return true;
  3922. }
  3923. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  3924. var country = options.country;
  3925. if (!country) {
  3926. country = value.substr(0, 2);
  3927. } else if (typeof country !== 'string' || !this.REGEX[country]) {
  3928. // Determine the country code
  3929. country = validator.getDynamicOption($field, country);
  3930. }
  3931. var locale = validator.getLocale();
  3932. if (!this.REGEX[country]) {
  3933. return true;
  3934. }
  3935. if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  3936. return {
  3937. valid: false,
  3938. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].iban.country, FormValidation.I18n[locale].iban.countries[country])
  3939. };
  3940. }
  3941. value = value.substr(4) + value.substr(0, 4);
  3942. value = $.map(value.split(''), function(n) {
  3943. var code = n.charCodeAt(0);
  3944. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  3945. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  3946. ? (code - 'A'.charCodeAt(0) + 10)
  3947. : n;
  3948. });
  3949. value = value.join('');
  3950. var temp = parseInt(value.substr(0, 1), 10),
  3951. length = value.length;
  3952. for (var i = 1; i < length; ++i) {
  3953. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  3954. }
  3955. return {
  3956. valid: (temp === 1),
  3957. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].iban.country, FormValidation.I18n[locale].iban.countries[country])
  3958. };
  3959. }
  3960. };
  3961. }(jQuery));
  3962. ;(function($) {
  3963. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  3964. 'en_US': {
  3965. id: {
  3966. 'default': 'Please enter a valid identification number',
  3967. country: 'Please enter a valid identification number in %s',
  3968. countries: {
  3969. BA: 'Bosnia and Herzegovina',
  3970. BG: 'Bulgaria',
  3971. BR: 'Brazil',
  3972. CH: 'Switzerland',
  3973. CL: 'Chile',
  3974. CN: 'China',
  3975. CZ: 'Czech Republic',
  3976. DK: 'Denmark',
  3977. EE: 'Estonia',
  3978. ES: 'Spain',
  3979. FI: 'Finland',
  3980. HR: 'Croatia',
  3981. IE: 'Ireland',
  3982. IS: 'Iceland',
  3983. LT: 'Lithuania',
  3984. LV: 'Latvia',
  3985. ME: 'Montenegro',
  3986. MK: 'Macedonia',
  3987. NL: 'Netherlands',
  3988. PL: 'Poland',
  3989. RO: 'Romania',
  3990. RS: 'Serbia',
  3991. SE: 'Sweden',
  3992. SI: 'Slovenia',
  3993. SK: 'Slovakia',
  3994. SM: 'San Marino',
  3995. TH: 'Thailand',
  3996. ZA: 'South Africa'
  3997. }
  3998. }
  3999. }
  4000. });
  4001. FormValidation.Validator.id = {
  4002. html5Attributes: {
  4003. message: 'message',
  4004. country: 'country'
  4005. },
  4006. // Supported country codes
  4007. COUNTRY_CODES: [
  4008. 'BA', 'BG', 'BR', 'CH', 'CL', 'CN', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
  4009. 'PL', 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TH', 'ZA'
  4010. ],
  4011. /**
  4012. * Validate identification number in different countries
  4013. *
  4014. * @see http://en.wikipedia.org/wiki/National_identification_number
  4015. * @param {FormValidation.Base} validator The validator plugin instance
  4016. * @param {jQuery} $field Field element
  4017. * @param {Object} options Consist of key:
  4018. * - message: The invalid message
  4019. * - country: The ISO 3166-1 country code. It can be
  4020. * - One of country code defined in COUNTRY_CODES
  4021. * - Name of field which its value defines the country code
  4022. * - Name of callback function that returns the country code
  4023. * - A callback function that returns the country code
  4024. * @returns {Boolean|Object}
  4025. */
  4026. validate: function(validator, $field, options) {
  4027. var value = validator.getFieldValue($field, 'id');
  4028. if (value === '') {
  4029. return true;
  4030. }
  4031. var locale = validator.getLocale(),
  4032. country = options.country;
  4033. if (!country) {
  4034. country = value.substr(0, 2);
  4035. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  4036. // Determine the country code
  4037. country = validator.getDynamicOption($field, country);
  4038. }
  4039. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  4040. return true;
  4041. }
  4042. var method = ['_', country.toLowerCase()].join('');
  4043. return this[method](value)
  4044. ? true
  4045. : {
  4046. valid: false,
  4047. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].id.country, FormValidation.I18n[locale].id.countries[country.toUpperCase()])
  4048. };
  4049. },
  4050. /**
  4051. * Validate Unique Master Citizen Number which uses in
  4052. * - Bosnia and Herzegovina (country code: BA)
  4053. * - Macedonia (MK)
  4054. * - Montenegro (ME)
  4055. * - Serbia (RS)
  4056. * - Slovenia (SI)
  4057. *
  4058. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  4059. * @param {String} value The ID
  4060. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  4061. * @returns {Boolean}
  4062. */
  4063. _validateJMBG: function(value, countryCode) {
  4064. if (!/^\d{13}$/.test(value)) {
  4065. return false;
  4066. }
  4067. var day = parseInt(value.substr(0, 2), 10),
  4068. month = parseInt(value.substr(2, 2), 10),
  4069. year = parseInt(value.substr(4, 3), 10),
  4070. rr = parseInt(value.substr(7, 2), 10),
  4071. k = parseInt(value.substr(12, 1), 10);
  4072. // Validate date of birth
  4073. // FIXME: Validate the year of birth
  4074. if (day > 31 || month > 12) {
  4075. return false;
  4076. }
  4077. // Validate checksum
  4078. var sum = 0;
  4079. for (var i = 0; i < 6; i++) {
  4080. sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  4081. }
  4082. sum = 11 - sum % 11;
  4083. if (sum === 10 || sum === 11) {
  4084. sum = 0;
  4085. }
  4086. if (sum !== k) {
  4087. return false;
  4088. }
  4089. // Validate political region
  4090. // rr is the political region of birth, which can be in ranges:
  4091. // 10-19: Bosnia and Herzegovina
  4092. // 20-29: Montenegro
  4093. // 30-39: Croatia (not used anymore)
  4094. // 41-49: Macedonia
  4095. // 50-59: Slovenia (only 50 is used)
  4096. // 70-79: Central Serbia
  4097. // 80-89: Serbian province of Vojvodina
  4098. // 90-99: Kosovo
  4099. switch (countryCode.toUpperCase()) {
  4100. case 'BA':
  4101. return (10 <= rr && rr <= 19);
  4102. case 'MK':
  4103. return (41 <= rr && rr <= 49);
  4104. case 'ME':
  4105. return (20 <= rr && rr <= 29);
  4106. case 'RS':
  4107. return (70 <= rr && rr <= 99);
  4108. case 'SI':
  4109. return (50 <= rr && rr <= 59);
  4110. default:
  4111. return true;
  4112. }
  4113. },
  4114. _ba: function(value) {
  4115. return this._validateJMBG(value, 'BA');
  4116. },
  4117. _mk: function(value) {
  4118. return this._validateJMBG(value, 'MK');
  4119. },
  4120. _me: function(value) {
  4121. return this._validateJMBG(value, 'ME');
  4122. },
  4123. _rs: function(value) {
  4124. return this._validateJMBG(value, 'RS');
  4125. },
  4126. /**
  4127. * Examples: 0101006500006
  4128. */
  4129. _si: function(value) {
  4130. return this._validateJMBG(value, 'SI');
  4131. },
  4132. /**
  4133. * Validate Bulgarian national identification number (EGN)
  4134. * Examples:
  4135. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  4136. * - Invalid: 8019010008
  4137. *
  4138. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  4139. * @param {String} value The ID
  4140. * @returns {Boolean}
  4141. */
  4142. _bg: function(value) {
  4143. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  4144. return false;
  4145. }
  4146. value = value.replace(/\s/g, '');
  4147. // Check the birth date
  4148. var year = parseInt(value.substr(0, 2), 10) + 1900,
  4149. month = parseInt(value.substr(2, 2), 10),
  4150. day = parseInt(value.substr(4, 2), 10);
  4151. if (month > 40) {
  4152. year += 100;
  4153. month -= 40;
  4154. } else if (month > 20) {
  4155. year -= 100;
  4156. month -= 20;
  4157. }
  4158. if (!FormValidation.Helper.date(year, month, day)) {
  4159. return false;
  4160. }
  4161. var sum = 0,
  4162. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  4163. for (var i = 0; i < 9; i++) {
  4164. sum += parseInt(value.charAt(i), 10) * weight[i];
  4165. }
  4166. sum = (sum % 11) % 10;
  4167. return (sum + '' === value.substr(9, 1));
  4168. },
  4169. /**
  4170. * Validate Brazilian national identification number (CPF)
  4171. * Examples:
  4172. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  4173. * - Invalid: 231.002.999-00
  4174. *
  4175. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  4176. * @param {String} value The ID
  4177. * @returns {Boolean}
  4178. */
  4179. _br: function(value) {
  4180. value = value.replace(/\D/g, '');
  4181. if (!/^\d{11}$/.test(value) || /^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  4182. return false;
  4183. }
  4184. var d1 = 0;
  4185. for (var i = 0; i < 9; i++) {
  4186. d1 += (10 - i) * parseInt(value.charAt(i), 10);
  4187. }
  4188. d1 = 11 - d1 % 11;
  4189. if (d1 === 10 || d1 === 11) {
  4190. d1 = 0;
  4191. }
  4192. if (d1 + '' !== value.charAt(9)) {
  4193. return false;
  4194. }
  4195. var d2 = 0;
  4196. for (i = 0; i < 10; i++) {
  4197. d2 += (11 - i) * parseInt(value.charAt(i), 10);
  4198. }
  4199. d2 = 11 - d2 % 11;
  4200. if (d2 === 10 || d2 === 11) {
  4201. d2 = 0;
  4202. }
  4203. return (d2 + '' === value.charAt(10));
  4204. },
  4205. /**
  4206. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  4207. * Examples:
  4208. * - Valid: 756.1234.5678.95, 7561234567895
  4209. *
  4210. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  4211. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  4212. * @param {String} value The ID
  4213. * @returns {Boolean}
  4214. */
  4215. _ch: function(value) {
  4216. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  4217. return false;
  4218. }
  4219. value = value.replace(/\D/g, '').substr(3);
  4220. var length = value.length,
  4221. sum = 0,
  4222. weight = (length === 8) ? [3, 1] : [1, 3];
  4223. for (var i = 0; i < length - 1; i++) {
  4224. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  4225. }
  4226. sum = 10 - sum % 10;
  4227. return (sum + '' === value.charAt(length - 1));
  4228. },
  4229. /**
  4230. * Validate Chilean national identification number (RUN/RUT)
  4231. * Examples:
  4232. * - Valid: 76086428-5, 22060449-7, 12531909-2
  4233. *
  4234. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  4235. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  4236. * @param {String} value The ID
  4237. * @returns {Boolean}
  4238. */
  4239. _cl: function(value) {
  4240. if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
  4241. return false;
  4242. }
  4243. value = value.replace(/\-/g, '');
  4244. while (value.length < 9) {
  4245. value = '0' + value;
  4246. }
  4247. var sum = 0,
  4248. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  4249. for (var i = 0; i < 8; i++) {
  4250. sum += parseInt(value.charAt(i), 10) * weight[i];
  4251. }
  4252. sum = 11 - sum % 11;
  4253. if (sum === 11) {
  4254. sum = 0;
  4255. } else if (sum === 10) {
  4256. sum = 'K';
  4257. }
  4258. return sum + '' === value.charAt(8).toUpperCase();
  4259. },
  4260. /**
  4261. * Validate Chinese citizen identification number
  4262. *
  4263. * Rules:
  4264. * - For current 18-digit system (since 1st Oct 1999, defined by GB11643—1999 national standard):
  4265. * - Digit 0-5: Must be a valid administrative division code of China PR.
  4266. * - Digit 6-13: Must be a valid YYYYMMDD date of birth. A future date is tolerated.
  4267. * - Digit 14-16: Order code, any integer.
  4268. * - Digit 17: An ISO 7064:1983, MOD 11-2 checksum.
  4269. * Both upper/lower case of X are tolerated.
  4270. * - For deprecated 15-digit system:
  4271. * - Digit 0-5: Must be a valid administrative division code of China PR.
  4272. * - Digit 6-11: Must be a valid YYMMDD date of birth, indicating the year of 19XX.
  4273. * - Digit 12-14: Order code, any integer.
  4274. * Lists of valid administrative division codes of China PR can be seen here:
  4275. * <http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/>
  4276. * Published and maintained by National Bureau of Statistics of China PR.
  4277. * NOTE: Current and deprecated codes MUST BOTH be considered valid.
  4278. * Many Chinese citizens born in once existed administrative divisions!
  4279. *
  4280. * @see http://en.wikipedia.org/wiki/Resident_Identity_Card#Identity_card_number
  4281. * @param {String} value The ID
  4282. * @returns {Boolean}
  4283. */
  4284. _cn: function(value) {
  4285. // Basic format check (18 or 15 digits, considering X in checksum)
  4286. value = value.trim();
  4287. if (!/^\d{15}$/.test(value) && !/^\d{17}[\dXx]{1}$/.test(value)) {
  4288. return false;
  4289. }
  4290. // Check China PR Administrative division code
  4291. var adminDivisionCodes = {
  4292. 11: {
  4293. 0: [0],
  4294. 1: [[0, 9], [11, 17]],
  4295. 2: [0, 28, 29]
  4296. },
  4297. 12: {
  4298. 0: [0],
  4299. 1: [[0, 16]],
  4300. 2: [0, 21, 23, 25]
  4301. },
  4302. 13: {
  4303. 0: [0],
  4304. 1: [[0, 5], 7, 8, 21, [23, 33], [81, 85]],
  4305. 2: [[0, 5], [7, 9], [23, 25], 27, 29, 30, 81, 83],
  4306. 3: [[0, 4], [21, 24]],
  4307. 4: [[0, 4], 6, 21, [23, 35], 81],
  4308. 5: [[0, 3], [21, 35], 81, 82],
  4309. 6: [[0, 4], [21, 38], [81, 84]],
  4310. 7: [[0, 3], 5, 6, [21, 33]],
  4311. 8: [[0, 4], [21, 28]],
  4312. 9: [[0, 3], [21, 30], [81, 84]],
  4313. 10: [[0, 3], [22, 26], 28, 81, 82],
  4314. 11: [[0, 2], [21, 28], 81, 82]
  4315. },
  4316. 14: {
  4317. 0: [0],
  4318. 1: [0, 1, [5, 10], [21, 23], 81],
  4319. 2: [[0, 3], 11, 12, [21, 27]],
  4320. 3: [[0, 3], 11, 21, 22],
  4321. 4: [[0, 2], 11, 21, [23, 31], 81],
  4322. 5: [[0, 2], 21, 22, 24, 25, 81],
  4323. 6: [[0, 3], [21, 24]],
  4324. 7: [[0, 2], [21, 29], 81],
  4325. 8: [[0, 2], [21, 30], 81, 82],
  4326. 9: [[0, 2], [21, 32], 81],
  4327. 10: [[0, 2], [21, 34], 81, 82],
  4328. 11: [[0, 2], [21, 30], 81, 82],
  4329. 23: [[0, 3], 22, 23, [25, 30], 32, 33]
  4330. },
  4331. 15: {
  4332. 0: [0],
  4333. 1: [[0, 5], [21, 25]],
  4334. 2: [[0, 7], [21, 23]],
  4335. 3: [[0, 4]],
  4336. 4: [[0, 4], [21, 26], [28, 30]],
  4337. 5: [[0, 2], [21, 26], 81],
  4338. 6: [[0, 2], [21, 27]],
  4339. 7: [[0, 3], [21, 27], [81, 85]],
  4340. 8: [[0, 2], [21, 26]],
  4341. 9: [[0, 2], [21, 29], 81],
  4342. 22: [[0, 2], [21, 24]],
  4343. 25: [[0, 2], [22, 31]],
  4344. 26: [[0, 2], [24, 27], [29, 32], 34],
  4345. 28: [0, 1, [22, 27]],
  4346. 29: [0, [21, 23]]
  4347. },
  4348. 21: {
  4349. 0: [0],
  4350. 1: [[0, 6], [11, 14], [22, 24], 81],
  4351. 2: [[0, 4], [11, 13], 24, [81, 83]],
  4352. 3: [[0, 4], 11, 21, 23, 81],
  4353. 4: [[0, 4], 11, [21, 23]],
  4354. 5: [[0, 5], 21, 22],
  4355. 6: [[0, 4], 24, 81, 82],
  4356. 7: [[0, 3], 11, 26, 27, 81, 82],
  4357. 8: [[0, 4], 11, 81, 82],
  4358. 9: [[0, 5], 11, 21, 22],
  4359. 10: [[0, 5], 11, 21, 81],
  4360. 11: [[0, 3], 21, 22],
  4361. 12: [[0, 2], 4, 21, 23, 24, 81, 82],
  4362. 13: [[0, 3], 21, 22, 24, 81, 82],
  4363. 14: [[0, 4], 21, 22, 81]
  4364. },
  4365. 22: {
  4366. 0: [0],
  4367. 1: [[0, 6], 12, 22, [81, 83]],
  4368. 2: [[0, 4], 11, 21, [81, 84]],
  4369. 3: [[0, 3], 22, 23, 81, 82],
  4370. 4: [[0, 3], 21, 22],
  4371. 5: [[0, 3], 21, 23, 24, 81, 82],
  4372. 6: [[0, 2], 4, 5, [21, 23], 25, 81],
  4373. 7: [[0, 2], [21, 24], 81],
  4374. 8: [[0, 2], 21, 22, 81, 82],
  4375. 24: [[0, 6], 24, 26]
  4376. },
  4377. 23: {
  4378. 0: [0],
  4379. 1: [[0, 12], 21, [23, 29], [81, 84]],
  4380. 2: [[0, 8], 21, [23, 25], 27, [29, 31], 81],
  4381. 3: [[0, 7], 21, 81, 82],
  4382. 4: [[0, 7], 21, 22],
  4383. 5: [[0, 3], 5, 6, [21, 24]],
  4384. 6: [[0, 6], [21, 24]],
  4385. 7: [[0, 16], 22, 81],
  4386. 8: [[0, 5], 11, 22, 26, 28, 33, 81, 82],
  4387. 9: [[0, 4], 21],
  4388. 10: [[0, 5], 24, 25, 81, [83, 85]],
  4389. 11: [[0, 2], 21, 23, 24, 81, 82],
  4390. 12: [[0, 2], [21, 26], [81, 83]],
  4391. 27: [[0, 4], [21, 23]]
  4392. },
  4393. 31: {
  4394. 0: [0],
  4395. 1: [0, 1, [3, 10], [12, 20]],
  4396. 2: [0, 30]
  4397. },
  4398. 32: {
  4399. 0: [0],
  4400. 1: [[0, 7], 11, [13, 18], 24, 25],
  4401. 2: [[0, 6], 11, 81, 82],
  4402. 3: [[0, 5], 11, 12, [21, 24], 81, 82],
  4403. 4: [[0, 2], 4, 5, 11, 12, 81, 82],
  4404. 5: [[0, 9], [81, 85]],
  4405. 6: [[0, 2], 11, 12, 21, 23, [81, 84]],
  4406. 7: [0, 1, 3, 5, 6, [21, 24]],
  4407. 8: [[0, 4], 11, 26, [29, 31]],
  4408. 9: [[0, 3], [21, 25], 28, 81, 82],
  4409. 10: [[0, 3], 11, 12, 23, 81, 84, 88],
  4410. 11: [[0, 2], 11, 12, [81, 83]],
  4411. 12: [[0, 4], [81, 84]],
  4412. 13: [[0, 2], 11, [21, 24]]
  4413. },
  4414. 33: {
  4415. 0: [0],
  4416. 1: [[0, 6], [8, 10], 22, 27, 82, 83, 85],
  4417. 2: [0, 1, [3, 6], 11, 12, 25, 26, [81, 83]],
  4418. 3: [[0, 4], 22, 24, [26, 29], 81, 82],
  4419. 4: [[0, 2], 11, 21, 24, [81, 83]],
  4420. 5: [[0, 3], [21, 23]],
  4421. 6: [[0, 2], 21, 24, [81, 83]],
  4422. 7: [[0, 3], 23, 26, 27, [81, 84]],
  4423. 8: [[0, 3], 22, 24, 25, 81],
  4424. 9: [[0, 3], 21, 22],
  4425. 10: [[0, 4], [21, 24], 81, 82],
  4426. 11: [[0, 2], [21, 27], 81]
  4427. },
  4428. 34: {
  4429. 0: [0],
  4430. 1: [[0, 4], 11, [21, 24], 81],
  4431. 2: [[0, 4], 7, 8, [21, 23], 25],
  4432. 3: [[0, 4], 11, [21, 23]],
  4433. 4: [[0, 6], 21],
  4434. 5: [[0, 4], 6, [21, 23]],
  4435. 6: [[0, 4], 21],
  4436. 7: [[0, 3], 11, 21],
  4437. 8: [[0, 3], 11, [22, 28], 81],
  4438. 10: [[0, 4], [21, 24]],
  4439. 11: [[0, 3], 22, [24, 26], 81, 82],
  4440. 12: [[0, 4], 21, 22, 25, 26, 82],
  4441. 13: [[0, 2], [21, 24]],
  4442. 14: [[0, 2], [21, 24]],
  4443. 15: [[0, 3], [21, 25]],
  4444. 16: [[0, 2], [21, 23]],
  4445. 17: [[0, 2], [21, 23]],
  4446. 18: [[0, 2], [21, 25], 81]
  4447. },
  4448. 35: {
  4449. 0: [0],
  4450. 1: [[0, 5], 11, [21, 25], 28, 81, 82],
  4451. 2: [[0, 6], [11, 13]],
  4452. 3: [[0, 5], 22],
  4453. 4: [[0, 3], 21, [23, 30], 81],
  4454. 5: [[0, 5], 21, [24, 27], [81, 83]],
  4455. 6: [[0, 3], [22, 29], 81],
  4456. 7: [[0, 2], [21, 25], [81, 84]],
  4457. 8: [[0, 2], [21, 25], 81],
  4458. 9: [[0, 2], [21, 26], 81, 82]
  4459. },
  4460. 36: {
  4461. 0: [0],
  4462. 1: [[0, 5], 11, [21, 24]],
  4463. 2: [[0, 3], 22, 81],
  4464. 3: [[0, 2], 13, [21, 23]],
  4465. 4: [[0, 3], 21, [23, 30], 81, 82],
  4466. 5: [[0, 2], 21],
  4467. 6: [[0, 2], 22, 81],
  4468. 7: [[0, 2], [21, 35], 81, 82],
  4469. 8: [[0, 3], [21, 30], 81],
  4470. 9: [[0, 2], [21, 26], [81, 83]],
  4471. 10: [[0, 2], [21, 30]],
  4472. 11: [[0, 2], [21, 30], 81]
  4473. },
  4474. 37: {
  4475. 0: [0],
  4476. 1: [[0, 5], 12, 13, [24, 26], 81],
  4477. 2: [[0, 3], 5, [11, 14], [81, 85]],
  4478. 3: [[0, 6], [21, 23]],
  4479. 4: [[0, 6], 81],
  4480. 5: [[0, 3], [21, 23]],
  4481. 6: [[0, 2], [11, 13], 34, [81, 87]],
  4482. 7: [[0, 5], 24, 25, [81, 86]],
  4483. 8: [[0, 2], 11, [26, 32], [81, 83]],
  4484. 9: [[0, 3], 11, 21, 23, 82, 83],
  4485. 10: [[0, 2], [81, 83]],
  4486. 11: [[0, 3], 21, 22],
  4487. 12: [[0, 3]],
  4488. 13: [[0, 2], 11, 12, [21, 29]],
  4489. 14: [[0, 2], [21, 28], 81, 82],
  4490. 15: [[0, 2], [21, 26], 81],
  4491. 16: [[0, 2], [21, 26]],
  4492. 17: [[0, 2], [21, 28]]
  4493. },
  4494. 41: {
  4495. 0: [0],
  4496. 1: [[0, 6], 8, 22, [81, 85]],
  4497. 2: [[0, 5], 11, [21, 25]],
  4498. 3: [[0, 7], 11, [22, 29], 81],
  4499. 4: [[0, 4], 11, [21, 23], 25, 81, 82],
  4500. 5: [[0, 3], 5, 6, 22, 23, 26, 27, 81],
  4501. 6: [[0, 3], 11, 21, 22],
  4502. 7: [[0, 4], 11, 21, [24, 28], 81, 82],
  4503. 8: [[0, 4], 11, [21, 23], 25, [81, 83]],
  4504. 9: [[0, 2], 22, 23, [26, 28]],
  4505. 10: [[0, 2], [23, 25], 81, 82],
  4506. 11: [[0, 4], [21, 23]],
  4507. 12: [[0, 2], 21, 22, 24, 81, 82],
  4508. 13: [[0, 3], [21, 30], 81],
  4509. 14: [[0, 3], [21, 26], 81],
  4510. 15: [[0, 3], [21, 28]],
  4511. 16: [[0, 2], [21, 28], 81],
  4512. 17: [[0, 2], [21, 29]],
  4513. 90: [0, 1]
  4514. },
  4515. 42: {
  4516. 0: [0],
  4517. 1: [[0, 7], [11, 17]],
  4518. 2: [[0, 5], 22, 81],
  4519. 3: [[0, 3], [21, 25], 81],
  4520. 5: [[0, 6], [25, 29], [81, 83]],
  4521. 6: [[0, 2], 6, 7, [24, 26], [82, 84]],
  4522. 7: [[0, 4]],
  4523. 8: [[0, 2], 4, 21, 22, 81],
  4524. 9: [[0, 2], [21, 23], 81, 82, 84],
  4525. 10: [[0, 3], [22, 24], 81, 83, 87],
  4526. 11: [[0, 2], [21, 27], 81, 82],
  4527. 12: [[0, 2], [21, 24], 81],
  4528. 13: [[0, 3], 21, 81],
  4529. 28: [[0, 2], 22, 23, [25, 28]],
  4530. 90: [0, [4, 6], 21]
  4531. },
  4532. 43: {
  4533. 0: [0],
  4534. 1: [[0, 5], 11, 12, 21, 22, 24, 81],
  4535. 2: [[0, 4], 11, 21, [23, 25], 81],
  4536. 3: [[0, 2], 4, 21, 81, 82],
  4537. 4: [0, 1, [5, 8], 12, [21, 24], 26, 81, 82],
  4538. 5: [[0, 3], 11, [21, 25], [27, 29], 81],
  4539. 6: [[0, 3], 11, 21, 23, 24, 26, 81, 82],
  4540. 7: [[0, 3], [21, 26], 81],
  4541. 8: [[0, 2], 11, 21, 22],
  4542. 9: [[0, 3], [21, 23], 81],
  4543. 10: [[0, 3], [21, 28], 81],
  4544. 11: [[0, 3], [21, 29]],
  4545. 12: [[0, 2], [21, 30], 81],
  4546. 13: [[0, 2], 21, 22, 81, 82],
  4547. 31: [0, 1, [22, 27], 30]
  4548. },
  4549. 44: {
  4550. 0: [0],
  4551. 1: [[0, 7], [11, 16], 83, 84],
  4552. 2: [[0, 5], 21, 22, 24, 29, 32, 33, 81, 82],
  4553. 3: [0, 1, [3, 8]],
  4554. 4: [[0, 4]],
  4555. 5: [0, 1, [6, 15], 23, 82, 83],
  4556. 6: [0, 1, [4, 8]],
  4557. 7: [0, 1, [3, 5], 81, [83, 85]],
  4558. 8: [[0, 4], 11, 23, 25, [81, 83]],
  4559. 9: [[0, 3], 23, [81, 83]],
  4560. 12: [[0, 3], [23, 26], 83, 84],
  4561. 13: [[0, 3], [22, 24], 81],
  4562. 14: [[0, 2], [21, 24], 26, 27, 81],
  4563. 15: [[0, 2], 21, 23, 81],
  4564. 16: [[0, 2], [21, 25]],
  4565. 17: [[0, 2], 21, 23, 81],
  4566. 18: [[0, 3], 21, 23, [25, 27], 81, 82],
  4567. 19: [0],
  4568. 20: [0],
  4569. 51: [[0, 3], 21, 22],
  4570. 52: [[0, 3], 21, 22, 24, 81],
  4571. 53: [[0, 2], [21, 23], 81]
  4572. },
  4573. 45: {
  4574. 0: [0],
  4575. 1: [[0, 9], [21, 27]],
  4576. 2: [[0, 5], [21, 26]],
  4577. 3: [[0, 5], 11, 12, [21, 32]],
  4578. 4: [0, 1, [3, 6], 11, [21, 23], 81],
  4579. 5: [[0, 3], 12, 21],
  4580. 6: [[0, 3], 21, 81],
  4581. 7: [[0, 3], 21, 22],
  4582. 8: [[0, 4], 21, 81],
  4583. 9: [[0, 3], [21, 24], 81],
  4584. 10: [[0, 2], [21, 31]],
  4585. 11: [[0, 2], [21, 23]],
  4586. 12: [[0, 2], [21, 29], 81],
  4587. 13: [[0, 2], [21, 24], 81],
  4588. 14: [[0, 2], [21, 25], 81]
  4589. },
  4590. 46: {
  4591. 0: [0],
  4592. 1: [0, 1, [5, 8]],
  4593. 2: [0, 1],
  4594. 3: [0, [21, 23]],
  4595. 90: [[0, 3], [5, 7], [21, 39]]
  4596. },
  4597. 50: {
  4598. 0: [0],
  4599. 1: [[0, 19]],
  4600. 2: [0, [22, 38], [40, 43]],
  4601. 3: [0, [81, 84]]
  4602. },
  4603. 51: {
  4604. 0: [0],
  4605. 1: [0, 1, [4, 8], [12, 15], [21, 24], 29, 31, 32, [81, 84]],
  4606. 3: [[0, 4], 11, 21, 22],
  4607. 4: [[0, 3], 11, 21, 22],
  4608. 5: [[0, 4], 21, 22, 24, 25],
  4609. 6: [0, 1, 3, 23, 26, [81, 83]],
  4610. 7: [0, 1, 3, 4, [22, 27], 81],
  4611. 8: [[0, 2], 11, 12, [21, 24]],
  4612. 9: [[0, 4], [21, 23]],
  4613. 10: [[0, 2], 11, 24, 25, 28],
  4614. 11: [[0, 2], [11, 13], 23, 24, 26, 29, 32, 33, 81],
  4615. 13: [[0, 4], [21, 25], 81],
  4616. 14: [[0, 2], [21, 25]],
  4617. 15: [[0, 3], [21, 29]],
  4618. 16: [[0, 3], [21, 23], 81],
  4619. 17: [[0, 3], [21, 25], 81],
  4620. 18: [[0, 3], [21, 27]],
  4621. 19: [[0, 3], [21, 23]],
  4622. 20: [[0, 2], 21, 22, 81],
  4623. 32: [0, [21, 33]],
  4624. 33: [0, [21, 38]],
  4625. 34: [0, 1, [22, 37]]
  4626. },
  4627. 52: {
  4628. 0: [0],
  4629. 1: [[0, 3], [11, 15], [21, 23], 81],
  4630. 2: [0, 1, 3, 21, 22],
  4631. 3: [[0, 3], [21, 30], 81, 82],
  4632. 4: [[0, 2], [21, 25]],
  4633. 5: [[0, 2], [21, 27]],
  4634. 6: [[0, 3], [21, 28]],
  4635. 22: [0, 1, [22, 30]],
  4636. 23: [0, 1, [22, 28]],
  4637. 24: [0, 1, [22, 28]],
  4638. 26: [0, 1, [22, 36]],
  4639. 27: [[0, 2], 22, 23, [25, 32]]
  4640. },
  4641. 53: {
  4642. 0: [0],
  4643. 1: [[0, 3], [11, 14], 21, 22, [24, 29], 81],
  4644. 3: [[0, 2], [21, 26], 28, 81],
  4645. 4: [[0, 2], [21, 28]],
  4646. 5: [[0, 2], [21, 24]],
  4647. 6: [[0, 2], [21, 30]],
  4648. 7: [[0, 2], [21, 24]],
  4649. 8: [[0, 2], [21, 29]],
  4650. 9: [[0, 2], [21, 27]],
  4651. 23: [0, 1, [22, 29], 31],
  4652. 25: [[0, 4], [22, 32]],
  4653. 26: [0, 1, [21, 28]],
  4654. 27: [0, 1, [22, 30]], 28: [0, 1, 22, 23],
  4655. 29: [0, 1, [22, 32]],
  4656. 31: [0, 2, 3, [22, 24]],
  4657. 34: [0, [21, 23]],
  4658. 33: [0, 21, [23, 25]],
  4659. 35: [0, [21, 28]]
  4660. },
  4661. 54: {
  4662. 0: [0],
  4663. 1: [[0, 2], [21, 27]],
  4664. 21: [0, [21, 29], 32, 33],
  4665. 22: [0, [21, 29], [31, 33]],
  4666. 23: [0, 1, [22, 38]],
  4667. 24: [0, [21, 31]],
  4668. 25: [0, [21, 27]],
  4669. 26: [0, [21, 27]]
  4670. },
  4671. 61: {
  4672. 0: [0],
  4673. 1: [[0, 4], [11, 16], 22, [24, 26]],
  4674. 2: [[0, 4], 22],
  4675. 3: [[0, 4], [21, 24], [26, 31]],
  4676. 4: [[0, 4], [22, 31], 81],
  4677. 5: [[0, 2], [21, 28], 81, 82],
  4678. 6: [[0, 2], [21, 32]],
  4679. 7: [[0, 2], [21, 30]],
  4680. 8: [[0, 2], [21, 31]],
  4681. 9: [[0, 2], [21, 29]],
  4682. 10: [[0, 2], [21, 26]]
  4683. },
  4684. 62: {
  4685. 0: [0],
  4686. 1: [[0, 5], 11, [21, 23]],
  4687. 2: [0, 1],
  4688. 3: [[0, 2], 21],
  4689. 4: [[0, 3], [21, 23]],
  4690. 5: [[0, 3], [21, 25]],
  4691. 6: [[0, 2], [21, 23]],
  4692. 7: [[0, 2], [21, 25]],
  4693. 8: [[0, 2], [21, 26]],
  4694. 9: [[0, 2], [21, 24], 81, 82],
  4695. 10: [[0, 2], [21, 27]],
  4696. 11: [[0, 2], [21, 26]],
  4697. 12: [[0, 2], [21, 28]],
  4698. 24: [0, 21, [24, 29]],
  4699. 26: [0, 21, [23, 30]],
  4700. 29: [0, 1, [21, 27]],
  4701. 30: [0, 1, [21, 27]]
  4702. },
  4703. 63: {
  4704. 0: [0],
  4705. 1: [[0, 5], [21, 23]],
  4706. 2: [0, 2, [21, 25]],
  4707. 21: [0, [21, 23], [26, 28]],
  4708. 22: [0, [21, 24]],
  4709. 23: [0, [21, 24]],
  4710. 25: [0, [21, 25]],
  4711. 26: [0, [21, 26]],
  4712. 27: [0, 1, [21, 26]],
  4713. 28: [[0, 2], [21, 23]]
  4714. },
  4715. 64: {
  4716. 0: [0],
  4717. 1: [0, 1, [4, 6], 21, 22, 81],
  4718. 2: [[0, 3], 5, [21, 23]],
  4719. 3: [[0, 3], [21, 24], 81],
  4720. 4: [[0, 2], [21, 25]],
  4721. 5: [[0, 2], 21, 22]
  4722. },
  4723. 65: {
  4724. 0: [0],
  4725. 1: [[0, 9], 21],
  4726. 2: [[0, 5]],
  4727. 21: [0, 1, 22, 23],
  4728. 22: [0, 1, 22, 23],
  4729. 23: [[0, 3], [23, 25], 27, 28],
  4730. 28: [0, 1, [22, 29]],
  4731. 29: [0, 1, [22, 29]],
  4732. 30: [0, 1, [22, 24]], 31: [0, 1, [21, 31]],
  4733. 32: [0, 1, [21, 27]],
  4734. 40: [0, 2, 3, [21, 28]],
  4735. 42: [[0, 2], 21, [23, 26]],
  4736. 43: [0, 1, [21, 26]],
  4737. 90: [[0, 4]], 27: [[0, 2], 22, 23]
  4738. },
  4739. 71: { 0: [0] },
  4740. 81: { 0: [0] },
  4741. 82: { 0: [0] }
  4742. };
  4743. var provincial = parseInt(value.substr(0, 2), 10),
  4744. prefectural = parseInt(value.substr(2, 2), 10),
  4745. county = parseInt(value.substr(4, 2), 10);
  4746. if (!adminDivisionCodes[provincial] || !adminDivisionCodes[provincial][prefectural]) {
  4747. return false;
  4748. }
  4749. var inRange = false,
  4750. rangeDef = adminDivisionCodes[provincial][prefectural];
  4751. for (var i = 0; i < rangeDef.length; i++) {
  4752. if (($.isArray(rangeDef[i]) && rangeDef[i][0] <= county && county <= rangeDef[i][1])
  4753. || (!$.isArray(rangeDef[i]) && county === rangeDef[i]))
  4754. {
  4755. inRange = true;
  4756. break;
  4757. }
  4758. }
  4759. if (!inRange) {
  4760. return false;
  4761. }
  4762. // Check date of birth
  4763. var dob;
  4764. if (value.length === 18) {
  4765. dob = value.substr(6, 8);
  4766. } else /* length == 15 */ {
  4767. dob = '19' + value.substr(6, 6);
  4768. }
  4769. var year = parseInt(dob.substr(0, 4), 10),
  4770. month = parseInt(dob.substr(4, 2), 10),
  4771. day = parseInt(dob.substr(6, 2), 10);
  4772. if (!FormValidation.Helper.date(year, month, day)) {
  4773. return false;
  4774. }
  4775. // Check checksum (18-digit system only)
  4776. if (value.length === 18) {
  4777. var sum = 0,
  4778. weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  4779. for (i = 0; i < 17; i++) {
  4780. sum += parseInt(value.charAt(i), 10) * weight[i];
  4781. }
  4782. sum = (12 - (sum % 11)) % 11;
  4783. var checksum = (value.charAt(17).toUpperCase() !== 'X') ? parseInt(value.charAt(17), 10) : 10;
  4784. return checksum === sum;
  4785. }
  4786. return true;
  4787. },
  4788. /**
  4789. * Validate Czech national identification number (RC)
  4790. * Examples:
  4791. * - Valid: 7103192745, 991231123
  4792. * - Invalid: 1103492745, 590312123
  4793. *
  4794. * @param {String} value The ID
  4795. * @returns {Boolean}
  4796. */
  4797. _cz: function(value) {
  4798. if (!/^\d{9,10}$/.test(value)) {
  4799. return false;
  4800. }
  4801. var year = 1900 + parseInt(value.substr(0, 2), 10),
  4802. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  4803. day = parseInt(value.substr(4, 2), 10);
  4804. if (value.length === 9) {
  4805. if (year >= 1980) {
  4806. year -= 100;
  4807. }
  4808. if (year > 1953) {
  4809. return false;
  4810. }
  4811. } else if (year < 1954) {
  4812. year += 100;
  4813. }
  4814. if (!FormValidation.Helper.date(year, month, day)) {
  4815. return false;
  4816. }
  4817. // Check that the birth date is not in the future
  4818. if (value.length === 10) {
  4819. var check = parseInt(value.substr(0, 9), 10) % 11;
  4820. if (year < 1985) {
  4821. check = check % 10;
  4822. }
  4823. return (check + '' === value.substr(9, 1));
  4824. }
  4825. return true;
  4826. },
  4827. /**
  4828. * Validate Danish Personal Identification number (CPR)
  4829. * Examples:
  4830. * - Valid: 2110625629, 211062-5629
  4831. * - Invalid: 511062-5629
  4832. *
  4833. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  4834. * @param {String} value The ID
  4835. * @returns {Boolean}
  4836. */
  4837. _dk: function(value) {
  4838. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  4839. return false;
  4840. }
  4841. value = value.replace(/-/g, '');
  4842. var day = parseInt(value.substr(0, 2), 10),
  4843. month = parseInt(value.substr(2, 2), 10),
  4844. year = parseInt(value.substr(4, 2), 10);
  4845. switch (true) {
  4846. case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  4847. year += 1800;
  4848. break;
  4849. case ('0123'.indexOf(value.charAt(6)) !== -1):
  4850. case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  4851. year += 1900;
  4852. break;
  4853. default:
  4854. year += 2000;
  4855. break;
  4856. }
  4857. return FormValidation.Helper.date(year, month, day);
  4858. },
  4859. /**
  4860. * Validate Estonian Personal Identification Code (isikukood)
  4861. * Examples:
  4862. * - Valid: 37605030299
  4863. *
  4864. * @see http://et.wikipedia.org/wiki/Isikukood
  4865. * @param {String} value The ID
  4866. * @returns {Boolean}
  4867. */
  4868. _ee: function(value) {
  4869. // Use the same format as Lithuanian Personal Code
  4870. return this._lt(value);
  4871. },
  4872. /**
  4873. * Validate Spanish personal identity code (DNI)
  4874. * Support i) DNI (for Spanish citizens), ii) NIE (for foreign people)
  4875. * and iii) CIF (for legal entities)
  4876. *
  4877. * Examples:
  4878. * - Valid:
  4879. * i) 54362315K, 54362315-K
  4880. * ii) X2482300W, X-2482300W, X-2482300-W
  4881. * iii) A58818501, A-58818501
  4882. * - Invalid:
  4883. * i) 54362315Z
  4884. * ii) X-2482300A
  4885. * iii) K58818501, G58818507
  4886. *
  4887. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  4888. * @param {String} value The ID
  4889. * @returns {Boolean}
  4890. */
  4891. _es: function(value) {
  4892. var isDNI = /^[0-9]{8}[-]{0,1}[A-HJ-NP-TV-Z]$/.test(value),
  4893. isNIE = /^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[A-HJ-NP-TV-Z]$/.test(value),
  4894. isCIF = /^[A-HNPQS][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-J]$/.test(value);
  4895. if (!isDNI && !isNIE && !isCIF) {
  4896. return false;
  4897. }
  4898. value = value.replace(/-/g, '');
  4899. var check;
  4900. if (isDNI || isNIE) {
  4901. var index = 'XYZ'.indexOf(value.charAt(0));
  4902. if (index !== -1) {
  4903. // It is NIE number
  4904. value = index + value.substr(1) + '';
  4905. }
  4906. check = parseInt(value.substr(0, 8), 10);
  4907. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4908. return (check === value.substr(8, 1));
  4909. } else {
  4910. check = value.substr(1, 7);
  4911. var letter = value[0],
  4912. control = value.substr(-1),
  4913. sum = 0;
  4914. // The digits in the even positions are added to the sum directly.
  4915. // The ones in the odd positions are multiplied by 2 and then added to the sum.
  4916. // If the result of multiplying by 2 is 10 or higher, add the two digits
  4917. // together and add that to the sum instead
  4918. for (var i = 0; i < check.length; i++) {
  4919. if (i % 2 !== 0) {
  4920. sum += parseInt(check[i], 10);
  4921. } else {
  4922. var tmp = '' + (parseInt(check[i], 10) * 2);
  4923. sum += parseInt(tmp[0], 10);
  4924. if (tmp.length === 2) {
  4925. sum += parseInt(tmp[1], 10);
  4926. }
  4927. }
  4928. }
  4929. // The control digit is calculated from the last digit of the sum.
  4930. // If that last digit is not 0, subtract it from 10
  4931. var lastDigit = sum - (Math.floor(sum / 10) * 10);
  4932. if (lastDigit !== 0) {
  4933. lastDigit = 10 - lastDigit;
  4934. }
  4935. if ('KQS'.indexOf(letter) !== -1) {
  4936. // If the CIF starts with a K, Q or S, the control digit must be a letter
  4937. return (control === 'JABCDEFGHI'[lastDigit]);
  4938. } else if ('ABEH'.indexOf(letter) !== -1) {
  4939. // If it starts with A, B, E or H, it has to be a number
  4940. return (control === ('' + lastDigit));
  4941. } else {
  4942. // In any other case, it doesn't matter
  4943. return (control === ('' + lastDigit) || control === 'JABCDEFGHI'[lastDigit]);
  4944. }
  4945. }
  4946. },
  4947. /**
  4948. * Validate Finnish Personal Identity Code (HETU)
  4949. * Examples:
  4950. * - Valid: 311280-888Y, 131052-308T
  4951. * - Invalid: 131052-308U, 310252-308Y
  4952. *
  4953. * @param {String} value The ID
  4954. * @returns {Boolean}
  4955. */
  4956. _fi: function(value) {
  4957. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  4958. return false;
  4959. }
  4960. var day = parseInt(value.substr(0, 2), 10),
  4961. month = parseInt(value.substr(2, 2), 10),
  4962. year = parseInt(value.substr(4, 2), 10),
  4963. centuries = {
  4964. '+': 1800,
  4965. '-': 1900,
  4966. 'A': 2000
  4967. };
  4968. year = centuries[value.charAt(6)] + year;
  4969. if (!FormValidation.Helper.date(year, month, day)) {
  4970. return false;
  4971. }
  4972. var individual = parseInt(value.substr(7, 3), 10);
  4973. if (individual < 2) {
  4974. return false;
  4975. }
  4976. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  4977. n = parseInt(n, 10);
  4978. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  4979. },
  4980. /**
  4981. * Validate Croatian personal identification number (OIB)
  4982. * Examples:
  4983. * - Valid: 33392005961
  4984. * - Invalid: 33392005962
  4985. *
  4986. * @param {String} value The ID
  4987. * @returns {Boolean}
  4988. */
  4989. _hr: function(value) {
  4990. if (!/^[0-9]{11}$/.test(value)) {
  4991. return false;
  4992. }
  4993. return FormValidation.Helper.mod11And10(value);
  4994. },
  4995. /**
  4996. * Validate Irish Personal Public Service Number (PPS)
  4997. * Examples:
  4998. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  4999. * - Invalid: 6433435E, 6433435VH
  5000. *
  5001. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  5002. * @param {String} value The ID
  5003. * @returns {Boolean}
  5004. */
  5005. _ie: function(value) {
  5006. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  5007. return false;
  5008. }
  5009. var getCheckDigit = function(value) {
  5010. while (value.length < 7) {
  5011. value = '0' + value;
  5012. }
  5013. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  5014. sum = 0;
  5015. for (var i = 0; i < 7; i++) {
  5016. sum += parseInt(value.charAt(i), 10) * (8 - i);
  5017. }
  5018. sum += 9 * alphabet.indexOf(value.substr(7));
  5019. return alphabet[sum % 23];
  5020. };
  5021. // 2013 format
  5022. if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  5023. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  5024. }
  5025. // The old format
  5026. else {
  5027. return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  5028. }
  5029. },
  5030. /**
  5031. * Validate Iceland national identification number (Kennitala)
  5032. * Examples:
  5033. * - Valid: 120174-3399, 1201743399, 0902862349
  5034. *
  5035. * @see http://en.wikipedia.org/wiki/Kennitala
  5036. * @param {String} value The ID
  5037. * @returns {Boolean}
  5038. */
  5039. _is: function(value) {
  5040. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  5041. return false;
  5042. }
  5043. value = value.replace(/-/g, '');
  5044. var day = parseInt(value.substr(0, 2), 10),
  5045. month = parseInt(value.substr(2, 2), 10),
  5046. year = parseInt(value.substr(4, 2), 10),
  5047. century = parseInt(value.charAt(9), 10);
  5048. year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  5049. if (!FormValidation.Helper.date(year, month, day, true)) {
  5050. return false;
  5051. }
  5052. // Validate the check digit
  5053. var sum = 0,
  5054. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  5055. for (var i = 0; i < 8; i++) {
  5056. sum += parseInt(value.charAt(i), 10) * weight[i];
  5057. }
  5058. sum = 11 - sum % 11;
  5059. return (sum + '' === value.charAt(8));
  5060. },
  5061. /**
  5062. * Validate Lithuanian Personal Code (Asmens kodas)
  5063. * Examples:
  5064. * - Valid: 38703181745
  5065. * - Invalid: 38703181746, 78703181745, 38703421745
  5066. *
  5067. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  5068. * @see http://www.adomas.org/midi2007/pcode.html
  5069. * @param {String} value The ID
  5070. * @returns {Boolean}
  5071. */
  5072. _lt: function(value) {
  5073. if (!/^[0-9]{11}$/.test(value)) {
  5074. return false;
  5075. }
  5076. var gender = parseInt(value.charAt(0), 10),
  5077. year = parseInt(value.substr(1, 2), 10),
  5078. month = parseInt(value.substr(3, 2), 10),
  5079. day = parseInt(value.substr(5, 2), 10),
  5080. century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  5081. year = century * 100 + year;
  5082. if (!FormValidation.Helper.date(year, month, day, true)) {
  5083. return false;
  5084. }
  5085. // Validate the check digit
  5086. var sum = 0,
  5087. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  5088. for (var i = 0; i < 10; i++) {
  5089. sum += parseInt(value.charAt(i), 10) * weight[i];
  5090. }
  5091. sum = sum % 11;
  5092. if (sum !== 10) {
  5093. return sum + '' === value.charAt(10);
  5094. }
  5095. // Re-calculate the check digit
  5096. sum = 0;
  5097. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  5098. for (i = 0; i < 10; i++) {
  5099. sum += parseInt(value.charAt(i), 10) * weight[i];
  5100. }
  5101. sum = sum % 11;
  5102. if (sum === 10) {
  5103. sum = 0;
  5104. }
  5105. return (sum + '' === value.charAt(10));
  5106. },
  5107. /**
  5108. * Validate Latvian Personal Code (Personas kods)
  5109. * Examples:
  5110. * - Valid: 161175-19997, 16117519997
  5111. * - Invalid: 161375-19997
  5112. *
  5113. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  5114. * @param {String} value The ID
  5115. * @returns {Boolean}
  5116. */
  5117. _lv: function(value) {
  5118. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  5119. return false;
  5120. }
  5121. value = value.replace(/\D/g, '');
  5122. // Check birth date
  5123. var day = parseInt(value.substr(0, 2), 10),
  5124. month = parseInt(value.substr(2, 2), 10),
  5125. year = parseInt(value.substr(4, 2), 10);
  5126. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  5127. if (!FormValidation.Helper.date(year, month, day, true)) {
  5128. return false;
  5129. }
  5130. // Check personal code
  5131. var sum = 0,
  5132. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  5133. for (var i = 0; i < 10; i++) {
  5134. sum += parseInt(value.charAt(i), 10) * weight[i];
  5135. }
  5136. sum = (sum + 1) % 11 % 10;
  5137. return (sum + '' === value.charAt(10));
  5138. },
  5139. /**
  5140. * Validate Dutch national identification number (BSN)
  5141. * Examples:
  5142. * - Valid: 111222333, 941331490, 9413.31.490
  5143. * - Invalid: 111252333
  5144. *
  5145. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  5146. * @param {String} value The ID
  5147. * @returns {Boolean}
  5148. */
  5149. _nl: function(value) {
  5150. while (value.length < 9) {
  5151. value = '0' + value;
  5152. }
  5153. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  5154. return false;
  5155. }
  5156. value = value.replace(/\./g, '');
  5157. if (parseInt(value, 10) === 0) {
  5158. return false;
  5159. }
  5160. var sum = 0,
  5161. length = value.length;
  5162. for (var i = 0; i < length - 1; i++) {
  5163. sum += (9 - i) * parseInt(value.charAt(i), 10);
  5164. }
  5165. sum = sum % 11;
  5166. if (sum === 10) {
  5167. sum = 0;
  5168. }
  5169. return (sum + '' === value.charAt(length - 1));
  5170. },
  5171. /**
  5172. * Validate Poland citizen number (PESEL)
  5173. *
  5174. * @see http://en.wikipedia.org/wiki/National_identification_number#Poland
  5175. * @see http://en.wikipedia.org/wiki/PESEL
  5176. * @param {String} value The ID
  5177. * @returns {Boolean}
  5178. */
  5179. _pl: function(value) {
  5180. if (!/^[0-9]{11}$/.test(value)) {
  5181. return false;
  5182. }
  5183. var sum = 0,
  5184. length = value.length,
  5185. weight = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 7];
  5186. for (var i = 0; i < length - 1; i++) {
  5187. sum += weight[i] * parseInt(value.charAt(i), 10);
  5188. }
  5189. sum = sum % 10;
  5190. if (sum === 0) {
  5191. sum = 10;
  5192. }
  5193. sum = 10 - sum;
  5194. return (sum + '' === value.charAt(length - 1));
  5195. },
  5196. /**
  5197. * Validate Romanian numerical personal code (CNP)
  5198. * Examples:
  5199. * - Valid: 1630615123457, 1800101221144
  5200. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  5201. *
  5202. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  5203. * @param {String} value The ID
  5204. * @returns {Boolean}
  5205. */
  5206. _ro: function(value) {
  5207. if (!/^[0-9]{13}$/.test(value)) {
  5208. return false;
  5209. }
  5210. var gender = parseInt(value.charAt(0), 10);
  5211. if (gender === 0 || gender === 7 || gender === 8) {
  5212. return false;
  5213. }
  5214. // Determine the date of birth
  5215. var year = parseInt(value.substr(1, 2), 10),
  5216. month = parseInt(value.substr(3, 2), 10),
  5217. day = parseInt(value.substr(5, 2), 10),
  5218. // The year of date is determined base on the gender
  5219. centuries = {
  5220. '1': 1900, // Male born between 1900 and 1999
  5221. '2': 1900, // Female born between 1900 and 1999
  5222. '3': 1800, // Male born between 1800 and 1899
  5223. '4': 1800, // Female born between 1800 and 1899
  5224. '5': 2000, // Male born after 2000
  5225. '6': 2000 // Female born after 2000
  5226. };
  5227. if (day > 31 && month > 12) {
  5228. return false;
  5229. }
  5230. if (gender !== 9) {
  5231. year = centuries[gender + ''] + year;
  5232. if (!FormValidation.Helper.date(year, month, day)) {
  5233. return false;
  5234. }
  5235. }
  5236. // Validate the check digit
  5237. var sum = 0,
  5238. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  5239. length = value.length;
  5240. for (var i = 0; i < length - 1; i++) {
  5241. sum += parseInt(value.charAt(i), 10) * weight[i];
  5242. }
  5243. sum = sum % 11;
  5244. if (sum === 10) {
  5245. sum = 1;
  5246. }
  5247. return (sum + '' === value.charAt(length - 1));
  5248. },
  5249. /**
  5250. * Validate Swedish personal identity number (personnummer)
  5251. * Examples:
  5252. * - Valid: 8112289874, 811228-9874, 811228+9874
  5253. * - Invalid: 811228-9873
  5254. *
  5255. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  5256. * @param {String} value The ID
  5257. * @returns {Boolean}
  5258. */
  5259. _se: function(value) {
  5260. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  5261. return false;
  5262. }
  5263. value = value.replace(/[^0-9]/g, '');
  5264. var year = parseInt(value.substr(0, 2), 10) + 1900,
  5265. month = parseInt(value.substr(2, 2), 10),
  5266. day = parseInt(value.substr(4, 2), 10);
  5267. if (!FormValidation.Helper.date(year, month, day)) {
  5268. return false;
  5269. }
  5270. // Validate the last check digit
  5271. return FormValidation.Helper.luhn(value);
  5272. },
  5273. /**
  5274. * Validate Slovak national identifier number (RC)
  5275. * Examples:
  5276. * - Valid: 7103192745, 991231123
  5277. * - Invalid: 7103192746, 1103492745
  5278. *
  5279. * @param {String} value The ID
  5280. * @returns {Boolean}
  5281. */
  5282. _sk: function(value) {
  5283. // Slovakia uses the same format as Czech Republic
  5284. return this._cz(value);
  5285. },
  5286. /**
  5287. * Validate San Marino citizen number
  5288. *
  5289. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  5290. * @param {String} value The ID
  5291. * @returns {Boolean}
  5292. */
  5293. _sm: function(value) {
  5294. return /^\d{5}$/.test(value);
  5295. },
  5296. /**
  5297. * Validate Thailand citizen number
  5298. * Examples:
  5299. * - Valid: 7145620509547, 3688699975685, 2368719339716
  5300. * - Invalid: 1100800092310
  5301. *
  5302. * @see http://en.wikipedia.org/wiki/National_identification_number#Thailand
  5303. * @param {String} value The ID
  5304. * @returns {Boolean}
  5305. */
  5306. _th: function(value) {
  5307. if (value.length !== 13) {
  5308. return false;
  5309. }
  5310. var sum = 0;
  5311. for (var i = 0; i < 12; i++) {
  5312. sum += parseInt(value.charAt(i), 10) * (13 - i);
  5313. }
  5314. return (11 - sum % 11) % 10 === parseInt(value.charAt(12), 10);
  5315. },
  5316. /**
  5317. * Validate South African ID
  5318. * Example:
  5319. * - Valid: 8001015009087
  5320. * - Invalid: 8001015009287, 8001015009086
  5321. *
  5322. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  5323. * @param {String} value The ID
  5324. * @returns {Boolean}
  5325. */
  5326. _za: function(value) {
  5327. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  5328. return false;
  5329. }
  5330. var year = parseInt(value.substr(0, 2), 10),
  5331. currentYear = new Date().getFullYear() % 100,
  5332. month = parseInt(value.substr(2, 2), 10),
  5333. day = parseInt(value.substr(4, 2), 10);
  5334. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  5335. if (!FormValidation.Helper.date(year, month, day)) {
  5336. return false;
  5337. }
  5338. // Validate the last check digit
  5339. return FormValidation.Helper.luhn(value);
  5340. }
  5341. };
  5342. }(jQuery));
  5343. ;(function($) {
  5344. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5345. 'en_US': {
  5346. identical: {
  5347. 'default': 'Please enter the same value'
  5348. }
  5349. }
  5350. });
  5351. FormValidation.Validator.identical = {
  5352. html5Attributes: {
  5353. message: 'message',
  5354. field: 'field'
  5355. },
  5356. /**
  5357. * Bind the validator on the live change of the field to compare with current one
  5358. *
  5359. * @param {FormValidation.Base} validator The validator plugin instance
  5360. * @param {jQuery} $field Field element
  5361. * @param {Object} options Consists of the following key:
  5362. * - field: The name of field that will be used to compare with current one
  5363. */
  5364. init: function(validator, $field, options) {
  5365. var compareWith = validator.getFieldElements(options.field);
  5366. validator.onLiveChange(compareWith, 'live_identical', function() {
  5367. var status = validator.getStatus($field, 'identical');
  5368. if (status !== validator.STATUS_NOT_VALIDATED) {
  5369. validator.revalidateField($field);
  5370. }
  5371. });
  5372. },
  5373. /**
  5374. * Unbind the validator on the live change of the field to compare with current one
  5375. *
  5376. * @param {FormValidation.Base} validator The validator plugin instance
  5377. * @param {jQuery} $field Field element
  5378. * @param {Object} options Consists of the following key:
  5379. * - field: The name of field that will be used to compare with current one
  5380. */
  5381. destroy: function(validator, $field, options) {
  5382. var compareWith = validator.getFieldElements(options.field);
  5383. validator.offLiveChange(compareWith, 'live_identical');
  5384. },
  5385. /**
  5386. * Check if input value equals to value of particular one
  5387. *
  5388. * @param {FormValidation.Base} validator The validator plugin instance
  5389. * @param {jQuery} $field Field element
  5390. * @param {Object} options Consists of the following key:
  5391. * - field: The name of field that will be used to compare with current one
  5392. * @returns {Boolean}
  5393. */
  5394. validate: function(validator, $field, options) {
  5395. var value = validator.getFieldValue($field, 'identical'),
  5396. compareWith = validator.getFieldElements(options.field);
  5397. if (compareWith === null || compareWith.length === 0) {
  5398. return true;
  5399. }
  5400. var compareValue = validator.getFieldValue(compareWith, 'identical');
  5401. if (value === compareValue) {
  5402. validator.updateStatus(compareWith, validator.STATUS_VALID, 'identical');
  5403. return true;
  5404. }
  5405. return false;
  5406. }
  5407. };
  5408. }(jQuery));
  5409. ;(function($) {
  5410. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5411. 'en_US': {
  5412. imei: {
  5413. 'default': 'Please enter a valid IMEI number'
  5414. }
  5415. }
  5416. });
  5417. FormValidation.Validator.imei = {
  5418. /**
  5419. * Validate IMEI (International Mobile Station Equipment Identity)
  5420. * Examples:
  5421. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  5422. * - Invalid: 490154203237517
  5423. *
  5424. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  5425. * @param {FormValidation.Base} validator The validator plugin instance
  5426. * @param {jQuery} $field Field element
  5427. * @param {Object} options Can consist of the following keys:
  5428. * - message: The invalid message
  5429. * @returns {Boolean}
  5430. */
  5431. validate: function(validator, $field, options) {
  5432. var value = validator.getFieldValue($field, 'imei');
  5433. if (value === '') {
  5434. return true;
  5435. }
  5436. switch (true) {
  5437. case /^\d{15}$/.test(value):
  5438. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  5439. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  5440. value = value.replace(/[^0-9]/g, '');
  5441. return FormValidation.Helper.luhn(value);
  5442. case /^\d{14}$/.test(value):
  5443. case /^\d{16}$/.test(value):
  5444. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  5445. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  5446. return true;
  5447. default:
  5448. return false;
  5449. }
  5450. }
  5451. };
  5452. }(jQuery));
  5453. ;(function($) {
  5454. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5455. 'en_US': {
  5456. imo: {
  5457. 'default': 'Please enter a valid IMO number'
  5458. }
  5459. }
  5460. });
  5461. FormValidation.Validator.imo = {
  5462. /**
  5463. * Validate IMO (International Maritime Organization)
  5464. * Examples:
  5465. * - Valid: IMO 8814275, IMO 9176187
  5466. * - Invalid: IMO 8814274
  5467. *
  5468. * @see http://en.wikipedia.org/wiki/IMO_Number
  5469. * @param {FormValidation.Base} validator The validator plugin instance
  5470. * @param {jQuery} $field Field element
  5471. * @param {Object} options Can consist of the following keys:
  5472. * - message: The invalid message
  5473. * @returns {Boolean}
  5474. */
  5475. validate: function(validator, $field, options) {
  5476. var value = validator.getFieldValue($field, 'imo');
  5477. if (value === '') {
  5478. return true;
  5479. }
  5480. if (!/^IMO \d{7}$/i.test(value)) {
  5481. return false;
  5482. }
  5483. // Grab just the digits
  5484. var sum = 0,
  5485. digits = value.replace(/^.*(\d{7})$/, '$1');
  5486. // Go over each char, multiplying by the inverse of it's position
  5487. // IMO 9176187
  5488. // (9 * 7) + (1 * 6) + (7 * 5) + (6 * 4) + (1 * 3) + (8 * 2) = 147
  5489. // Take the last digit of that, that's the check digit (7)
  5490. for (var i = 6; i >= 1; i--) {
  5491. sum += (digits.slice((6 - i), -i) * (i + 1));
  5492. }
  5493. return sum % 10 === parseInt(digits.charAt(6), 10);
  5494. }
  5495. };
  5496. }(jQuery));
  5497. ;(function($) {
  5498. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5499. 'en_US': {
  5500. integer: {
  5501. 'default': 'Please enter a valid number'
  5502. }
  5503. }
  5504. });
  5505. FormValidation.Validator.integer = {
  5506. enableByHtml5: function($field) {
  5507. return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
  5508. },
  5509. /**
  5510. * Return true if the input value is an integer
  5511. *
  5512. * @param {FormValidation.Base} validator The validator plugin instance
  5513. * @param {jQuery} $field Field element
  5514. * @param {Object} options Can consist of the following key:
  5515. * - message: The invalid message
  5516. * @returns {Boolean}
  5517. */
  5518. validate: function(validator, $field, options) {
  5519. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  5520. return false;
  5521. }
  5522. var value = validator.getFieldValue($field, 'integer');
  5523. if (value === '') {
  5524. return true;
  5525. }
  5526. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  5527. }
  5528. };
  5529. }(jQuery));
  5530. ;(function($) {
  5531. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5532. 'en_US': {
  5533. ip: {
  5534. 'default': 'Please enter a valid IP address',
  5535. ipv4: 'Please enter a valid IPv4 address',
  5536. ipv6: 'Please enter a valid IPv6 address'
  5537. }
  5538. }
  5539. });
  5540. FormValidation.Validator.ip = {
  5541. html5Attributes: {
  5542. message: 'message',
  5543. ipv4: 'ipv4',
  5544. ipv6: 'ipv6'
  5545. },
  5546. /**
  5547. * Return true if the input value is a IP address.
  5548. *
  5549. * @param {FormValidation.Base} validator The validator plugin instance
  5550. * @param {jQuery} $field Field element
  5551. * @param {Object} options Can consist of the following keys:
  5552. * - ipv4: Enable IPv4 validator, default to true
  5553. * - ipv6: Enable IPv6 validator, default to true
  5554. * - message: The invalid message
  5555. * @returns {Boolean|Object}
  5556. */
  5557. validate: function(validator, $field, options) {
  5558. var value = validator.getFieldValue($field, 'ip');
  5559. if (value === '') {
  5560. return true;
  5561. }
  5562. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  5563. var locale = validator.getLocale(),
  5564. ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
  5565. ipv6Regex = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,
  5566. valid = false,
  5567. message;
  5568. switch (true) {
  5569. case (options.ipv4 && !options.ipv6):
  5570. valid = ipv4Regex.test(value);
  5571. message = options.message || FormValidation.I18n[locale].ip.ipv4;
  5572. break;
  5573. case (!options.ipv4 && options.ipv6):
  5574. valid = ipv6Regex.test(value);
  5575. message = options.message || FormValidation.I18n[locale].ip.ipv6;
  5576. break;
  5577. case (options.ipv4 && options.ipv6):
  5578. /* falls through */
  5579. default:
  5580. valid = ipv4Regex.test(value) || ipv6Regex.test(value);
  5581. message = options.message || FormValidation.I18n[locale].ip['default'];
  5582. break;
  5583. }
  5584. return {
  5585. valid: valid,
  5586. message: message
  5587. };
  5588. }
  5589. };
  5590. }(jQuery));
  5591. ;(function($) {
  5592. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5593. 'en_US': {
  5594. isbn: {
  5595. 'default': 'Please enter a valid ISBN number'
  5596. }
  5597. }
  5598. });
  5599. FormValidation.Validator.isbn = {
  5600. /**
  5601. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  5602. * Examples:
  5603. * - Valid:
  5604. * ISBN 10: 99921-58-10-7, 9971-5-0210-0, 960-425-059-0, 80-902734-1-6, 85-359-0277-5, 1-84356-028-3, 0-684-84328-5, 0-8044-2957-X, 0-85131-041-9, 0-943396-04-2, 0-9752298-0-X
  5605. * ISBN 13: 978-0-306-40615-7
  5606. * - Invalid:
  5607. * ISBN 10: 99921-58-10-6
  5608. * ISBN 13: 978-0-306-40615-6
  5609. *
  5610. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  5611. * @param {FormValidation.Base} validator The validator plugin instance
  5612. * @param {jQuery} $field Field element
  5613. * @param {Object} [options] Can consist of the following keys:
  5614. * - message: The invalid message
  5615. * @returns {Boolean}
  5616. */
  5617. validate: function(validator, $field, options) {
  5618. var value = validator.getFieldValue($field, 'isbn');
  5619. if (value === '') {
  5620. return true;
  5621. }
  5622. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  5623. // Groups are separated by a hyphen or a space
  5624. var type;
  5625. switch (true) {
  5626. case /^\d{9}[\dX]$/.test(value):
  5627. case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  5628. case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  5629. type = 'ISBN10';
  5630. break;
  5631. case /^(978|979)\d{9}[\dX]$/.test(value):
  5632. case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  5633. case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  5634. type = 'ISBN13';
  5635. break;
  5636. default:
  5637. return false;
  5638. }
  5639. // Replace all special characters except digits and X
  5640. value = value.replace(/[^0-9X]/gi, '');
  5641. var chars = value.split(''),
  5642. length = chars.length,
  5643. sum = 0,
  5644. i,
  5645. checksum;
  5646. switch (type) {
  5647. case 'ISBN10':
  5648. sum = 0;
  5649. for (i = 0; i < length - 1; i++) {
  5650. sum += parseInt(chars[i], 10) * (10 - i);
  5651. }
  5652. checksum = 11 - (sum % 11);
  5653. if (checksum === 11) {
  5654. checksum = 0;
  5655. } else if (checksum === 10) {
  5656. checksum = 'X';
  5657. }
  5658. return (checksum + '' === chars[length - 1]);
  5659. case 'ISBN13':
  5660. sum = 0;
  5661. for (i = 0; i < length - 1; i++) {
  5662. sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  5663. }
  5664. checksum = 10 - (sum % 10);
  5665. if (checksum === 10) {
  5666. checksum = '0';
  5667. }
  5668. return (checksum + '' === chars[length - 1]);
  5669. default:
  5670. return false;
  5671. }
  5672. }
  5673. };
  5674. }(jQuery));
  5675. ;(function($) {
  5676. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5677. 'en_US': {
  5678. isin: {
  5679. 'default': 'Please enter a valid ISIN number'
  5680. }
  5681. }
  5682. });
  5683. FormValidation.Validator.isin = {
  5684. // Available country codes
  5685. // See http://isin.net/country-codes/
  5686. COUNTRY_CODES: 'AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW',
  5687. /**
  5688. * Validate an ISIN (International Securities Identification Number)
  5689. * Examples:
  5690. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  5691. * - Invalid: US0378331004, AA0000XVGZA3
  5692. *
  5693. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  5694. * @param {FormValidation.Base} validator The validator plugin instance
  5695. * @param {jQuery} $field Field element
  5696. * @param {Object} options Can consist of the following keys:
  5697. * - message: The invalid message
  5698. * @returns {Boolean}
  5699. */
  5700. validate: function(validator, $field, options) {
  5701. var value = validator.getFieldValue($field, 'isin');
  5702. if (value === '') {
  5703. return true;
  5704. }
  5705. value = value.toUpperCase();
  5706. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  5707. if (!regex.test(value)) {
  5708. return false;
  5709. }
  5710. var converted = '',
  5711. length = value.length;
  5712. // Convert letters to number
  5713. for (var i = 0; i < length - 1; i++) {
  5714. var c = value.charCodeAt(i);
  5715. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  5716. }
  5717. var digits = '',
  5718. n = converted.length,
  5719. group = (n % 2 !== 0) ? 0 : 1;
  5720. for (i = 0; i < n; i++) {
  5721. digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  5722. }
  5723. var sum = 0;
  5724. for (i = 0; i < digits.length; i++) {
  5725. sum += parseInt(digits.charAt(i), 10);
  5726. }
  5727. sum = (10 - (sum % 10)) % 10;
  5728. return sum + '' === value.charAt(length - 1);
  5729. }
  5730. };
  5731. }(jQuery));
  5732. ;(function($) {
  5733. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5734. 'en_US': {
  5735. ismn: {
  5736. 'default': 'Please enter a valid ISMN number'
  5737. }
  5738. }
  5739. });
  5740. FormValidation.Validator.ismn = {
  5741. /**
  5742. * Validate ISMN (International Standard Music Number)
  5743. * Examples:
  5744. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  5745. * - Invalid: 9790060115614
  5746. *
  5747. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  5748. * @param {FormValidation.Base} validator The validator plugin instance
  5749. * @param {jQuery} $field Field element
  5750. * @param {Object} options Can consist of the following keys:
  5751. * - message: The invalid message
  5752. * @returns {Boolean}
  5753. */
  5754. validate: function(validator, $field, options) {
  5755. var value = validator.getFieldValue($field, 'ismn');
  5756. if (value === '') {
  5757. return true;
  5758. }
  5759. // Groups are separated by a hyphen or a space
  5760. var type;
  5761. switch (true) {
  5762. case /^M\d{9}$/.test(value):
  5763. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  5764. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  5765. type = 'ISMN10';
  5766. break;
  5767. case /^9790\d{9}$/.test(value):
  5768. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  5769. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  5770. type = 'ISMN13';
  5771. break;
  5772. default:
  5773. return false;
  5774. }
  5775. if ('ISMN10' === type) {
  5776. value = '9790' + value.substr(1);
  5777. }
  5778. // Replace all special characters except digits
  5779. value = value.replace(/[^0-9]/gi, '');
  5780. var length = value.length,
  5781. sum = 0,
  5782. weight = [1, 3];
  5783. for (var i = 0; i < length - 1; i++) {
  5784. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  5785. }
  5786. sum = 10 - sum % 10;
  5787. return (sum + '' === value.charAt(length - 1));
  5788. }
  5789. };
  5790. }(jQuery));
  5791. ;(function($) {
  5792. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5793. 'en_US': {
  5794. issn: {
  5795. 'default': 'Please enter a valid ISSN number'
  5796. }
  5797. }
  5798. });
  5799. FormValidation.Validator.issn = {
  5800. /**
  5801. * Validate ISSN (International Standard Serial Number)
  5802. * Examples:
  5803. * - Valid: 0378-5955, 0024-9319, 0032-1478
  5804. * - Invalid: 0032-147X
  5805. *
  5806. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  5807. * @param {FormValidation.Base} validator The validator plugin instance
  5808. * @param {jQuery} $field Field element
  5809. * @param {Object} options Can consist of the following keys:
  5810. * - message: The invalid message
  5811. * @returns {Boolean}
  5812. */
  5813. validate: function(validator, $field, options) {
  5814. var value = validator.getFieldValue($field, 'issn');
  5815. if (value === '') {
  5816. return true;
  5817. }
  5818. // Groups are separated by a hyphen or a space
  5819. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  5820. return false;
  5821. }
  5822. // Replace all special characters except digits and X
  5823. value = value.replace(/[^0-9X]/gi, '');
  5824. var chars = value.split(''),
  5825. length = chars.length,
  5826. sum = 0;
  5827. if (chars[7] === 'X') {
  5828. chars[7] = 10;
  5829. }
  5830. for (var i = 0; i < length; i++) {
  5831. sum += parseInt(chars[i], 10) * (8 - i);
  5832. }
  5833. return (sum % 11 === 0);
  5834. }
  5835. };
  5836. }(jQuery));
  5837. ;(function($) {
  5838. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5839. 'en_US': {
  5840. lessThan: {
  5841. 'default': 'Please enter a value less than or equal to %s',
  5842. notInclusive: 'Please enter a value less than %s'
  5843. }
  5844. }
  5845. });
  5846. FormValidation.Validator.lessThan = {
  5847. html5Attributes: {
  5848. message: 'message',
  5849. value: 'value',
  5850. inclusive: 'inclusive'
  5851. },
  5852. enableByHtml5: function($field) {
  5853. var type = $field.attr('type'),
  5854. max = $field.attr('max');
  5855. if (max && type !== 'date') {
  5856. return {
  5857. value: max
  5858. };
  5859. }
  5860. return false;
  5861. },
  5862. /**
  5863. * Return true if the input value is less than or equal to given number
  5864. *
  5865. * @param {FormValidation.Base} validator The validator plugin instance
  5866. * @param {jQuery} $field Field element
  5867. * @param {Object} options Can consist of the following keys:
  5868. * - value: The number used to compare to. It can be
  5869. * - A number
  5870. * - Name of field which its value defines the number
  5871. * - Name of callback function that returns the number
  5872. * - A callback function that returns the number
  5873. *
  5874. * - inclusive [optional]: Can be true or false. Default is true
  5875. * - message: The invalid message
  5876. * @returns {Boolean|Object}
  5877. */
  5878. validate: function(validator, $field, options) {
  5879. var value = validator.getFieldValue($field, 'lessThan');
  5880. if (value === '') {
  5881. return true;
  5882. }
  5883. value = this._format(value);
  5884. if (!$.isNumeric(value)) {
  5885. return false;
  5886. }
  5887. var locale = validator.getLocale(),
  5888. compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value),
  5889. compareToValue = this._format(compareTo);
  5890. value = parseFloat(value);
  5891. return (options.inclusive === true || options.inclusive === undefined)
  5892. ? {
  5893. valid: value <= compareToValue,
  5894. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].lessThan['default'], compareTo)
  5895. }
  5896. : {
  5897. valid: value < compareToValue,
  5898. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].lessThan.notInclusive, compareTo)
  5899. };
  5900. },
  5901. _format: function(value) {
  5902. return (value + '').replace(',', '.');
  5903. }
  5904. };
  5905. }(jQuery));
  5906. ;(function($) {
  5907. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5908. 'en_US': {
  5909. mac: {
  5910. 'default': 'Please enter a valid MAC address'
  5911. }
  5912. }
  5913. });
  5914. FormValidation.Validator.mac = {
  5915. /**
  5916. * Return true if the input value is a MAC address.
  5917. *
  5918. * @param {FormValidation.Base} validator The validator plugin instance
  5919. * @param {jQuery} $field Field element
  5920. * @param {Object} options Can consist of the following keys:
  5921. * - message: The invalid message
  5922. * @returns {Boolean}
  5923. */
  5924. validate: function(validator, $field, options) {
  5925. var value = validator.getFieldValue($field, 'mac');
  5926. if (value === '') {
  5927. return true;
  5928. }
  5929. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  5930. }
  5931. };
  5932. }(jQuery));
  5933. ;(function($) {
  5934. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  5935. 'en_US': {
  5936. meid: {
  5937. 'default': 'Please enter a valid MEID number'
  5938. }
  5939. }
  5940. });
  5941. FormValidation.Validator.meid = {
  5942. /**
  5943. * Validate MEID (Mobile Equipment Identifier)
  5944. * Examples:
  5945. * - Valid: 293608736500703710, 29360-87365-0070-3710, AF0123450ABCDE, AF-012345-0ABCDE
  5946. * - Invalid: 2936087365007037101
  5947. *
  5948. * @see http://en.wikipedia.org/wiki/Mobile_equipment_identifier
  5949. * @param {FormValidation.Base} validator The validator plugin instance
  5950. * @param {jQuery} $field Field element
  5951. * @param {Object} options Can consist of the following keys:
  5952. * - message: The invalid message
  5953. * @returns {Boolean}
  5954. */
  5955. validate: function(validator, $field, options) {
  5956. var value = validator.getFieldValue($field, 'meid');
  5957. if (value === '') {
  5958. return true;
  5959. }
  5960. switch (true) {
  5961. // 14 digit hex representation (no check digit)
  5962. case /^[0-9A-F]{15}$/i.test(value):
  5963. // 14 digit hex representation + dashes or spaces (no check digit)
  5964. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}[- ][0-9A-F]$/i.test(value):
  5965. // 18 digit decimal representation (no check digit)
  5966. case /^\d{19}$/.test(value):
  5967. // 18 digit decimal representation + dashes or spaces (no check digit)
  5968. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}[- ]\d$/.test(value):
  5969. // Grab the check digit
  5970. var cd = value.charAt(value.length - 1);
  5971. // Strip any non-hex chars
  5972. value = value.replace(/[- ]/g, '');
  5973. // If it's all digits, luhn base 10 is used
  5974. if (value.match(/^\d*$/i)) {
  5975. return FormValidation.Helper.luhn(value);
  5976. }
  5977. // Strip the check digit
  5978. value = value.slice(0, -1);
  5979. // Get every other char, and double it
  5980. var cdCalc = '';
  5981. for (var i = 1; i <= 13; i += 2) {
  5982. cdCalc += (parseInt(value.charAt(i), 16) * 2).toString(16);
  5983. }
  5984. // Get the sum of each char in the string
  5985. var sum = 0;
  5986. for (i = 0; i < cdCalc.length; i++) {
  5987. sum += parseInt(cdCalc.charAt(i), 16);
  5988. }
  5989. // If the last digit of the calc is 0, the check digit is 0
  5990. return (sum % 10 === 0)
  5991. ? (cd === '0')
  5992. // Subtract it from the next highest 10s number (64 goes to 70) and subtract the sum
  5993. // Double it and turn it into a hex char
  5994. : (cd === ((Math.floor((sum + 10) / 10) * 10 - sum) * 2).toString(16));
  5995. // 14 digit hex representation (no check digit)
  5996. case /^[0-9A-F]{14}$/i.test(value):
  5997. // 14 digit hex representation + dashes or spaces (no check digit)
  5998. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}$/i.test(value):
  5999. // 18 digit decimal representation (no check digit)
  6000. case /^\d{18}$/.test(value):
  6001. // 18 digit decimal representation + dashes or spaces (no check digit)
  6002. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}$/.test(value):
  6003. return true;
  6004. default:
  6005. return false;
  6006. }
  6007. }
  6008. };
  6009. }(jQuery));
  6010. ;(function($) {
  6011. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6012. 'en_US': {
  6013. notEmpty: {
  6014. 'default': 'Please enter a value'
  6015. }
  6016. }
  6017. });
  6018. FormValidation.Validator.notEmpty = {
  6019. enableByHtml5: function($field) {
  6020. var required = $field.attr('required') + '';
  6021. return ('required' === required || 'true' === required);
  6022. },
  6023. /**
  6024. * Check if input value is empty or not
  6025. *
  6026. * @param {FormValidation.Base} validator The validator plugin instance
  6027. * @param {jQuery} $field Field element
  6028. * @param {Object} options
  6029. * @returns {Boolean}
  6030. */
  6031. validate: function(validator, $field, options) {
  6032. var type = $field.attr('type');
  6033. if ('radio' === type || 'checkbox' === type) {
  6034. var ns = validator.getNamespace();
  6035. return validator
  6036. .getFieldElements($field.attr('data-' + ns + '-field'))
  6037. .filter(':checked')
  6038. .length > 0;
  6039. }
  6040. if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  6041. return true;
  6042. }
  6043. var value = validator.getFieldValue($field, 'notEmpty');
  6044. return $.trim(value) !== '';
  6045. }
  6046. };
  6047. }(jQuery));
  6048. ;(function($) {
  6049. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6050. 'en_US': {
  6051. numeric: {
  6052. 'default': 'Please enter a valid float number'
  6053. }
  6054. }
  6055. });
  6056. FormValidation.Validator.numeric = {
  6057. html5Attributes: {
  6058. message: 'message',
  6059. separator: 'separator'
  6060. },
  6061. enableByHtml5: function($field) {
  6062. return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
  6063. },
  6064. /**
  6065. * Validate decimal number
  6066. *
  6067. * @param {FormValidation.Base} validator The validator plugin instance
  6068. * @param {jQuery} $field Field element
  6069. * @param {Object} options Consist of key:
  6070. * - message: The invalid message
  6071. * - separator: The decimal separator. Can be "." (default), ","
  6072. * @returns {Boolean}
  6073. */
  6074. validate: function(validator, $field, options) {
  6075. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  6076. return false;
  6077. }
  6078. var value = validator.getFieldValue($field, 'numeric');
  6079. if (value === '') {
  6080. return true;
  6081. }
  6082. var separator = options.separator || '.';
  6083. if (separator !== '.') {
  6084. value = value.replace(separator, '.');
  6085. }
  6086. return !isNaN(parseFloat(value)) && isFinite(value);
  6087. }
  6088. };
  6089. }(jQuery));
  6090. ;(function($) {
  6091. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6092. 'en_US': {
  6093. phone: {
  6094. 'default': 'Please enter a valid phone number',
  6095. country: 'Please enter a valid phone number in %s',
  6096. countries: {
  6097. AE: 'United Arab Emirates',
  6098. BG: 'Bulgaria',
  6099. BR: 'Brazil',
  6100. CN: 'China',
  6101. CZ: 'Czech Republic',
  6102. DE: 'Germany',
  6103. DK: 'Denmark',
  6104. ES: 'Spain',
  6105. FR: 'France',
  6106. GB: 'United Kingdom',
  6107. IN: 'India',
  6108. MA: 'Morocco',
  6109. NL: 'Netherlands',
  6110. PK: 'Pakistan',
  6111. RO: 'Romania',
  6112. RU: 'Russia',
  6113. SK: 'Slovakia',
  6114. TH: 'Thailand',
  6115. US: 'USA',
  6116. VE: 'Venezuela'
  6117. }
  6118. }
  6119. }
  6120. });
  6121. FormValidation.Validator.phone = {
  6122. html5Attributes: {
  6123. message: 'message',
  6124. country: 'country'
  6125. },
  6126. // The supported countries
  6127. COUNTRY_CODES: ['AE', 'BG', 'BR', 'CN', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'IN', 'MA', 'NL', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
  6128. /**
  6129. * Return true if the input value contains a valid phone number for the country
  6130. * selected in the options
  6131. *
  6132. * @param {FormValidation.Base} validator Validate plugin instance
  6133. * @param {jQuery} $field Field element
  6134. * @param {Object} options Consist of key:
  6135. * - message: The invalid message
  6136. * - country: The ISO-3166 country code. It can be
  6137. * - A country code
  6138. * - Name of field which its value defines the country code
  6139. * - Name of callback function that returns the country code
  6140. * - A callback function that returns the country code
  6141. *
  6142. * @returns {Boolean|Object}
  6143. */
  6144. validate: function(validator, $field, options) {
  6145. var value = validator.getFieldValue($field, 'phone');
  6146. if (value === '') {
  6147. return true;
  6148. }
  6149. var locale = validator.getLocale(),
  6150. country = options.country;
  6151. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  6152. // Try to determine the country
  6153. country = validator.getDynamicOption($field, country);
  6154. }
  6155. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  6156. return true;
  6157. }
  6158. var isValid = true;
  6159. switch (country.toUpperCase()) {
  6160. case 'AE':
  6161. // http://regexr.com/39tak
  6162. value = $.trim(value);
  6163. isValid = (/^(((\+|00)?971[\s\.-]?(\(0\)[\s\.-]?)?|0)(\(5(0|2|5|6)\)|5(0|2|5|6)|2|3|4|6|7|9)|60)([\s\.-]?[0-9]){7}$/).test(value);
  6164. break;
  6165. case 'BG':
  6166. // https://regex101.com/r/yE6vN4/1
  6167. // See http://en.wikipedia.org/wiki/Telephone_numbers_in_Bulgaria
  6168. value = value.replace(/\+|\s|-|\/|\(|\)/gi,'');
  6169. isValid = (/^(0|359|00)(((700|900)[0-9]{5}|((800)[0-9]{5}|(800)[0-9]{4}))|(87|88|89)([0-9]{7})|((2[0-9]{7})|(([3-9][0-9])(([0-9]{6})|([0-9]{5})))))$/).test(value);
  6170. break;
  6171. case 'BR':
  6172. // http://regexr.com/399m1
  6173. value = $.trim(value);
  6174. isValid = (/^(([\d]{4}[-.\s]{1}[\d]{2,3}[-.\s]{1}[\d]{2}[-.\s]{1}[\d]{2})|([\d]{4}[-.\s]{1}[\d]{3}[-.\s]{1}[\d]{4})|((\(?\+?[0-9]{2}\)?\s?)?(\(?\d{2}\)?\s?)?\d{4,5}[-.\s]?\d{4}))$/).test(value);
  6175. break;
  6176. case 'CN':
  6177. // http://regexr.com/39dq4
  6178. value = $.trim(value);
  6179. isValid = (/^((00|\+)?(86(?:-| )))?((\d{11})|(\d{3}[- ]{1}\d{4}[- ]{1}\d{4})|((\d{2,4}[- ]){1}(\d{7,8}|(\d{3,4}[- ]{1}\d{4}))([- ]{1}\d{1,4})?))$/).test(value);
  6180. break;
  6181. case 'CZ':
  6182. // http://regexr.com/39hhl
  6183. isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  6184. break;
  6185. case 'DE':
  6186. // http://regexr.com/39pkg
  6187. value = $.trim(value);
  6188. isValid = (/^(((((((00|\+)49[ \-/]?)|0)[1-9][0-9]{1,4})[ \-/]?)|((((00|\+)49\()|\(0)[1-9][0-9]{1,4}\)[ \-/]?))[0-9]{1,7}([ \-/]?[0-9]{1,5})?)$/).test(value);
  6189. break;
  6190. case 'DK':
  6191. // Mathing DK phone numbers with country code in 1 of 3 formats and an
  6192. // 8 digit phone number not starting with a 0 or 1. Can have 1 space
  6193. // between each character except inside the country code.
  6194. // http://regex101.com/r/sS8fO4/1
  6195. value = $.trim(value);
  6196. isValid = (/^(\+45|0045|\(45\))?\s?[2-9](\s?\d){7}$/).test(value);
  6197. break;
  6198. case 'ES':
  6199. // http://regex101.com/r/rB9mA9/1
  6200. // Telephone numbers in Spain go like this:
  6201. // 9: Landline phones and special prefixes.
  6202. // 6, 7: Mobile phones.
  6203. // 5: VoIP lines.
  6204. // 8: Premium-rate services.
  6205. // There are also special 5-digit and 3-digit numbers, but
  6206. // maybe it would be overkill to include them all.
  6207. value = $.trim(value);
  6208. isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:5|6|7|8|9)(?:\d\D?){8}$/).test(value);
  6209. break;
  6210. case 'FR':
  6211. // http://regexr.com/39a2p
  6212. value = $.trim(value);
  6213. isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
  6214. break;
  6215. case 'GB':
  6216. // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  6217. // http://regexr.com/38uhv
  6218. value = $.trim(value);
  6219. isValid = (/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/).test(value);
  6220. break;
  6221. case 'IN':
  6222. // http://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number
  6223. // http://regex101.com/r/qL6eZ5/1
  6224. // May begin with +91. Supports mobile and land line numbers
  6225. value = $.trim(value);
  6226. isValid = (/((\+?)((0[ -]+)*|(91 )*)(\d{12}|\d{10}))|\d{5}([- ]*)\d{6}/).test(value);
  6227. break;
  6228. case 'MA':
  6229. // http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
  6230. // http://regexr.com/399n8
  6231. value = $.trim(value);
  6232. isValid = (/^(?:(?:(?:\+|00)212[\s]?(?:[\s]?\(0\)[\s]?)?)|0){1}(?:5[\s.-]?[2-3]|6[\s.-]?[13-9]){1}[0-9]{1}(?:[\s.-]?\d{2}){3}$/).test(value);
  6233. break;
  6234. case 'NL':
  6235. // http://en.wikipedia.org/wiki/Telephone_numbers_in_the_Netherlands
  6236. // http://regexr.com/3aevr
  6237. value = $.trim(value);
  6238. isValid = (/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9])((\s|\s?-\s?)?[0-9])((\s|\s?-\s?)?[0-9])\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]\s?[0-9]$/gm).test(value);
  6239. break;
  6240. case 'PK':
  6241. // http://regex101.com/r/yH8aV9/2
  6242. value = $.trim(value);
  6243. isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
  6244. break;
  6245. case 'RO':
  6246. // All mobile network and land line
  6247. // http://regexr.com/39fv1
  6248. isValid = (/^(\+4|)?(07[0-8]{1}[0-9]{1}|02[0-9]{2}|03[0-9]{2}){1}?(\s|\.|\-)?([0-9]{3}(\s|\.|\-|)){2}$/g).test(value);
  6249. break;
  6250. case 'RU':
  6251. // http://regex101.com/r/gW7yT5/5
  6252. isValid = (/^((8|\+7|007)[\-\.\/ ]?)?([\(\/\.]?\d{3}[\)\/\.]?[\-\.\/ ]?)?[\d\-\.\/ ]{7,10}$/g).test(value);
  6253. break;
  6254. case 'SK':
  6255. // http://regexr.com/3a95f
  6256. isValid = /^(((00)([- ]?)|\+)(421)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  6257. break;
  6258. case 'TH':
  6259. // http://regex101.com/r/vM5mZ4/2
  6260. isValid = (/^0\(?([6|8-9]{2})*-([0-9]{3})*-([0-9]{4})$/).test(value);
  6261. break;
  6262. case 'VE':
  6263. // http://regex101.com/r/eM2yY0/6
  6264. value = $.trim(value);
  6265. isValid = (/^0(?:2(?:12|4[0-9]|5[1-9]|6[0-9]|7[0-8]|8[1-35-8]|9[1-5]|3[45789])|4(?:1[246]|2[46]))\d{7}$/).test(value);
  6266. break;
  6267. case 'US':
  6268. /* falls through */
  6269. default:
  6270. // Make sure US phone numbers have 10 digits
  6271. // May start with 1, +1, or 1-; should discard
  6272. // Area code may be delimited with (), & sections may be delimited with . or -
  6273. // http://regexr.com/38mqi
  6274. isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
  6275. break;
  6276. }
  6277. return {
  6278. valid: isValid,
  6279. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].phone.country, FormValidation.I18n[locale].phone.countries[country])
  6280. };
  6281. }
  6282. };
  6283. }(jQuery));
  6284. ;(function($) {
  6285. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6286. 'en_US': {
  6287. regexp: {
  6288. 'default': 'Please enter a value matching the pattern'
  6289. }
  6290. }
  6291. });
  6292. FormValidation.Validator.regexp = {
  6293. html5Attributes: {
  6294. message: 'message',
  6295. regexp: 'regexp'
  6296. },
  6297. enableByHtml5: function($field) {
  6298. var pattern = $field.attr('pattern');
  6299. if (pattern) {
  6300. return {
  6301. regexp: pattern
  6302. };
  6303. }
  6304. return false;
  6305. },
  6306. /**
  6307. * Check if the element value matches given regular expression
  6308. *
  6309. * @param {FormValidation.Base} validator The validator plugin instance
  6310. * @param {jQuery} $field Field element
  6311. * @param {Object} options Consists of the following key:
  6312. * - regexp: The regular expression you need to check
  6313. * @returns {Boolean}
  6314. */
  6315. validate: function(validator, $field, options) {
  6316. var value = validator.getFieldValue($field, 'regexp');
  6317. if (value === '') {
  6318. return true;
  6319. }
  6320. var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  6321. return regexp.test(value);
  6322. }
  6323. };
  6324. }(jQuery));
  6325. ;(function($) {
  6326. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6327. 'en_US': {
  6328. remote: {
  6329. 'default': 'Please enter a valid value'
  6330. }
  6331. }
  6332. });
  6333. FormValidation.Validator.remote = {
  6334. html5Attributes: {
  6335. crossdomain: 'crossDomain',
  6336. data: 'data',
  6337. datatype: 'dataType',
  6338. delay: 'delay',
  6339. message: 'message',
  6340. name: 'name',
  6341. type: 'type',
  6342. url: 'url',
  6343. validkey: 'validKey'
  6344. },
  6345. /**
  6346. * Destroy the timer when destroying the FormValidation (using validator.destroy() method)
  6347. */
  6348. destroy: function(validator, $field, options) {
  6349. var ns = validator.getNamespace(),
  6350. timer = $field.data(ns + '.remote.timer');
  6351. if (timer) {
  6352. clearTimeout(timer);
  6353. $field.removeData(ns + '.remote.timer');
  6354. }
  6355. },
  6356. /**
  6357. * Request a remote server to check the input value
  6358. *
  6359. * @param {FormValidation.Base} validator Plugin instance
  6360. * @param {jQuery} $field Field element
  6361. * @param {Object} options Can consist of the following keys:
  6362. * - crossDomain {Boolean} [optional]
  6363. * - data {Object|Function} [optional]: By default, it will take the value
  6364. * {
  6365. * <fieldName>: <fieldValue>
  6366. * }
  6367. * - dataType {String} [optional]: The type of data which is returned by remote server.
  6368. * It can be json (default), text, script
  6369. * - delay {Number} [optional]
  6370. * - headers {String[]} [optional]: Additional headers
  6371. * - message {String} [optional]: The invalid message
  6372. * - name {String} [optional]: Override the field name for the request.
  6373. * - type {String} [optional] Can be GET or POST (default)
  6374. * - url {String|Function}
  6375. * - validKey {String} [optional]: The valid key. It's "valid" by default
  6376. * This is useful when connecting to external remote server or APIs provided by 3rd parties
  6377. * @returns {Deferred}
  6378. */
  6379. validate: function(validator, $field, options) {
  6380. var ns = validator.getNamespace(),
  6381. value = validator.getFieldValue($field, 'remote'),
  6382. dfd = new $.Deferred();
  6383. if (value === '') {
  6384. dfd.resolve($field, 'remote', { valid: true });
  6385. return dfd;
  6386. }
  6387. var name = $field.attr('data-' + ns + '-field'),
  6388. data = options.data || {},
  6389. url = options.url,
  6390. validKey = options.validKey || 'valid';
  6391. // Support dynamic data
  6392. if ('function' === typeof data) {
  6393. data = data.call(this, validator);
  6394. }
  6395. // Parse string data from HTML5 attribute
  6396. if ('string' === typeof data) {
  6397. data = JSON.parse(data);
  6398. }
  6399. // Support dynamic url
  6400. if ('function' === typeof url) {
  6401. url = url.call(this, validator);
  6402. }
  6403. data[options.name || name] = value;
  6404. var ajaxOptions = {
  6405. data: data,
  6406. dataType: options.dataType || 'json',
  6407. headers: options.headers || {},
  6408. type: options.type || 'GET',
  6409. url: url
  6410. };
  6411. if (options.crossDomain !== null) {
  6412. ajaxOptions.crossDomain = (options.crossDomain === true || options.crossDomain === 'true');
  6413. }
  6414. function runCallback() {
  6415. var xhr = $.ajax(ajaxOptions);
  6416. xhr
  6417. .success(function(response) {
  6418. response.valid = (response[validKey] === true || response[validKey] === 'true')
  6419. ? true
  6420. : (response[validKey] === false || response[validKey] === 'false' ? false : null);
  6421. dfd.resolve($field, 'remote', response);
  6422. })
  6423. .error(function(response) {
  6424. dfd.resolve($field, 'remote', {
  6425. valid: false
  6426. });
  6427. });
  6428. dfd.fail(function() {
  6429. xhr.abort();
  6430. });
  6431. return dfd;
  6432. }
  6433. if (options.delay) {
  6434. // Since the form might have multiple fields with the same name
  6435. // I have to attach the timer to the field element
  6436. if ($field.data(ns + '.remote.timer')) {
  6437. clearTimeout($field.data(ns + '.remote.timer'));
  6438. }
  6439. $field.data(ns + '.remote.timer', setTimeout(runCallback, options.delay));
  6440. return dfd;
  6441. } else {
  6442. return runCallback();
  6443. }
  6444. }
  6445. };
  6446. }(jQuery));
  6447. ;(function($) {
  6448. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6449. 'en_US': {
  6450. rtn: {
  6451. 'default': 'Please enter a valid RTN number'
  6452. }
  6453. }
  6454. });
  6455. FormValidation.Validator.rtn = {
  6456. /**
  6457. * Validate a RTN (Routing transit number)
  6458. * Examples:
  6459. * - Valid: 021200025, 789456124
  6460. *
  6461. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  6462. * @param {FormValidation.Base} validator The validator plugin instance
  6463. * @param {jQuery} $field Field element
  6464. * @param {Object} options Can consist of the following keys:
  6465. * - message: The invalid message
  6466. * @returns {Boolean}
  6467. */
  6468. validate: function(validator, $field, options) {
  6469. var value = validator.getFieldValue($field, 'rtn');
  6470. if (value === '') {
  6471. return true;
  6472. }
  6473. if (!/^\d{9}$/.test(value)) {
  6474. return false;
  6475. }
  6476. var sum = 0;
  6477. for (var i = 0; i < value.length; i += 3) {
  6478. sum += parseInt(value.charAt(i), 10) * 3
  6479. + parseInt(value.charAt(i + 1), 10) * 7
  6480. + parseInt(value.charAt(i + 2), 10);
  6481. }
  6482. return (sum !== 0 && sum % 10 === 0);
  6483. }
  6484. };
  6485. }(jQuery));
  6486. ;(function($) {
  6487. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6488. 'en_US': {
  6489. sedol: {
  6490. 'default': 'Please enter a valid SEDOL number'
  6491. }
  6492. }
  6493. });
  6494. FormValidation.Validator.sedol = {
  6495. /**
  6496. * Validate a SEDOL (Stock Exchange Daily Official List)
  6497. * Examples:
  6498. * - Valid: 0263494, B0WNLY7
  6499. *
  6500. * @see http://en.wikipedia.org/wiki/SEDOL
  6501. * @param {FormValidation.Base} validator The validator plugin instance
  6502. * @param {jQuery} $field Field element
  6503. * @param {Object} options Can consist of the following keys:
  6504. * - message: The invalid message
  6505. * @returns {Boolean}
  6506. */
  6507. validate: function(validator, $field, options) {
  6508. var value = validator.getFieldValue($field, 'sedol');
  6509. if (value === '') {
  6510. return true;
  6511. }
  6512. value = value.toUpperCase();
  6513. if (!/^[0-9A-Z]{7}$/.test(value)) {
  6514. return false;
  6515. }
  6516. var sum = 0,
  6517. weight = [1, 3, 1, 7, 3, 9, 1],
  6518. length = value.length;
  6519. for (var i = 0; i < length - 1; i++) {
  6520. sum += weight[i] * parseInt(value.charAt(i), 36);
  6521. }
  6522. sum = (10 - sum % 10) % 10;
  6523. return sum + '' === value.charAt(length - 1);
  6524. }
  6525. };
  6526. }(jQuery));
  6527. ;(function($) {
  6528. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6529. 'en_US': {
  6530. siren: {
  6531. 'default': 'Please enter a valid SIREN number'
  6532. }
  6533. }
  6534. });
  6535. FormValidation.Validator.siren = {
  6536. /**
  6537. * Check if a string is a siren number
  6538. *
  6539. * @param {FormValidation.Base} validator The validator plugin instance
  6540. * @param {jQuery} $field Field element
  6541. * @param {Object} options Consist of key:
  6542. * - message: The invalid message
  6543. * @returns {Boolean}
  6544. */
  6545. validate: function(validator, $field, options) {
  6546. var value = validator.getFieldValue($field, 'siren');
  6547. if (value === '') {
  6548. return true;
  6549. }
  6550. if (!/^\d{9}$/.test(value)) {
  6551. return false;
  6552. }
  6553. return FormValidation.Helper.luhn(value);
  6554. }
  6555. };
  6556. }(jQuery));
  6557. ;(function($) {
  6558. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6559. 'en_US': {
  6560. siret: {
  6561. 'default': 'Please enter a valid SIRET number'
  6562. }
  6563. }
  6564. });
  6565. FormValidation.Validator.siret = {
  6566. /**
  6567. * Check if a string is a siret number
  6568. *
  6569. * @param {FormValidation.Base} validator The validator plugin instance
  6570. * @param {jQuery} $field Field element
  6571. * @param {Object} options Consist of key:
  6572. * - message: The invalid message
  6573. * @returns {Boolean}
  6574. */
  6575. validate: function(validator, $field, options) {
  6576. var value = validator.getFieldValue($field, 'siret');
  6577. if (value === '') {
  6578. return true;
  6579. }
  6580. var sum = 0,
  6581. length = value.length,
  6582. tmp;
  6583. for (var i = 0; i < length; i++) {
  6584. tmp = parseInt(value.charAt(i), 10);
  6585. if ((i % 2) === 0) {
  6586. tmp = tmp * 2;
  6587. if (tmp > 9) {
  6588. tmp -= 9;
  6589. }
  6590. }
  6591. sum += tmp;
  6592. }
  6593. return (sum % 10 === 0);
  6594. }
  6595. };
  6596. }(jQuery));
  6597. ;(function($) {
  6598. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6599. 'en_US': {
  6600. step: {
  6601. 'default': 'Please enter a valid step of %s'
  6602. }
  6603. }
  6604. });
  6605. FormValidation.Validator.step = {
  6606. html5Attributes: {
  6607. message: 'message',
  6608. base: 'baseValue',
  6609. step: 'step'
  6610. },
  6611. /**
  6612. * Return true if the input value is valid step one
  6613. *
  6614. * @param {FormValidation.Base} validator The validator plugin instance
  6615. * @param {jQuery} $field Field element
  6616. * @param {Object} options Can consist of the following keys:
  6617. * - baseValue: The base value
  6618. * - step: The step
  6619. * - message: The invalid message
  6620. * @returns {Boolean|Object}
  6621. */
  6622. validate: function(validator, $field, options) {
  6623. var value = validator.getFieldValue($field, 'step');
  6624. if (value === '') {
  6625. return true;
  6626. }
  6627. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  6628. value = parseFloat(value);
  6629. if (!$.isNumeric(value)) {
  6630. return false;
  6631. }
  6632. var round = function(x, precision) {
  6633. var m = Math.pow(10, precision);
  6634. x = x * m;
  6635. var sign = (x > 0) | -(x < 0),
  6636. isHalf = (x % 1 === 0.5 * sign);
  6637. if (isHalf) {
  6638. return (Math.floor(x) + (sign > 0)) / m;
  6639. } else {
  6640. return Math.round(x) / m;
  6641. }
  6642. },
  6643. floatMod = function(x, y) {
  6644. if (y === 0.0) {
  6645. return 1.0;
  6646. }
  6647. var dotX = (x + '').split('.'),
  6648. dotY = (y + '').split('.'),
  6649. precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  6650. return round(x - y * Math.floor(x / y), precision);
  6651. };
  6652. var locale = validator.getLocale(),
  6653. mod = floatMod(value - options.baseValue, options.step);
  6654. return {
  6655. valid: mod === 0.0 || mod === options.step,
  6656. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].step['default'], [options.step])
  6657. };
  6658. }
  6659. };
  6660. }(jQuery));
  6661. ;(function($) {
  6662. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6663. 'en_US': {
  6664. stringCase: {
  6665. 'default': 'Please enter only lowercase characters',
  6666. upper: 'Please enter only uppercase characters'
  6667. }
  6668. }
  6669. });
  6670. FormValidation.Validator.stringCase = {
  6671. html5Attributes: {
  6672. message: 'message',
  6673. 'case': 'case'
  6674. },
  6675. /**
  6676. * Check if a string is a lower or upper case one
  6677. *
  6678. * @param {FormValidation.Base} validator The validator plugin instance
  6679. * @param {jQuery} $field Field element
  6680. * @param {Object} options Consist of key:
  6681. * - message: The invalid message
  6682. * - case: Can be 'lower' (default) or 'upper'
  6683. * @returns {Object}
  6684. */
  6685. validate: function(validator, $field, options) {
  6686. var value = validator.getFieldValue($field, 'stringCase');
  6687. if (value === '') {
  6688. return true;
  6689. }
  6690. var locale = validator.getLocale(),
  6691. stringCase = (options['case'] || 'lower').toLowerCase();
  6692. return {
  6693. valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
  6694. message: options.message || (('upper' === stringCase) ? FormValidation.I18n[locale].stringCase.upper : FormValidation.I18n[locale].stringCase['default'])
  6695. };
  6696. }
  6697. };
  6698. }(jQuery));
  6699. ;(function($) {
  6700. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6701. 'en_US': {
  6702. stringLength: {
  6703. 'default': 'Please enter a value with valid length',
  6704. less: 'Please enter less than %s characters',
  6705. more: 'Please enter more than %s characters',
  6706. between: 'Please enter value between %s and %s characters long'
  6707. }
  6708. }
  6709. });
  6710. FormValidation.Validator.stringLength = {
  6711. html5Attributes: {
  6712. message: 'message',
  6713. min: 'min',
  6714. max: 'max',
  6715. trim: 'trim',
  6716. utf8bytes: 'utf8Bytes'
  6717. },
  6718. enableByHtml5: function($field) {
  6719. var options = {},
  6720. maxLength = $field.attr('maxlength'),
  6721. minLength = $field.attr('minlength');
  6722. if (maxLength) {
  6723. options.max = parseInt(maxLength, 10);
  6724. }
  6725. if (minLength) {
  6726. options.min = parseInt(minLength, 10);
  6727. }
  6728. return $.isEmptyObject(options) ? false : options;
  6729. },
  6730. /**
  6731. * Check if the length of element value is less or more than given number
  6732. *
  6733. * @param {FormValidation.Base} validator The validator plugin instance
  6734. * @param {jQuery} $field Field element
  6735. * @param {Object} options Consists of following keys:
  6736. * - min
  6737. * - max
  6738. * At least one of two keys is required
  6739. * The min, max keys define the number which the field value compares to. min, max can be
  6740. * - A number
  6741. * - Name of field which its value defines the number
  6742. * - Name of callback function that returns the number
  6743. * - A callback function that returns the number
  6744. *
  6745. * - message: The invalid message
  6746. * - trim: Indicate the length will be calculated after trimming the value or not. It is false, by default
  6747. * - utf8bytes: Evaluate string length in UTF-8 bytes, default to false
  6748. * @returns {Object}
  6749. */
  6750. validate: function(validator, $field, options) {
  6751. var value = validator.getFieldValue($field, 'stringLength');
  6752. if (options.trim === true || options.trim === 'true') {
  6753. value = $.trim(value);
  6754. }
  6755. if (value === '') {
  6756. return true;
  6757. }
  6758. var locale = validator.getLocale(),
  6759. min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  6760. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  6761. // Credit to http://stackoverflow.com/a/23329386 (@lovasoa) for UTF-8 byte length code
  6762. utf8Length = function(str) {
  6763. var s = str.length;
  6764. for (var i = str.length - 1; i >= 0; i--) {
  6765. var code = str.charCodeAt(i);
  6766. if (code > 0x7f && code <= 0x7ff) {
  6767. s++;
  6768. } else if (code > 0x7ff && code <= 0xffff) {
  6769. s += 2;
  6770. }
  6771. if (code >= 0xDC00 && code <= 0xDFFF) {
  6772. i--;
  6773. }
  6774. }
  6775. return s;
  6776. },
  6777. length = options.utf8Bytes ? utf8Length(value) : value.length,
  6778. isValid = true,
  6779. message = options.message || FormValidation.I18n[locale].stringLength['default'];
  6780. if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
  6781. isValid = false;
  6782. }
  6783. switch (true) {
  6784. case (!!min && !!max):
  6785. message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
  6786. break;
  6787. case (!!min):
  6788. message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.more, parseInt(min, 10));
  6789. break;
  6790. case (!!max):
  6791. message = FormValidation.Helper.format(options.message || FormValidation.I18n[locale].stringLength.less, parseInt(max, 10));
  6792. break;
  6793. default:
  6794. break;
  6795. }
  6796. return {
  6797. valid: isValid,
  6798. message: message
  6799. };
  6800. }
  6801. };
  6802. }(jQuery));
  6803. ;(function($) {
  6804. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6805. 'en_US': {
  6806. uri: {
  6807. 'default': 'Please enter a valid URI'
  6808. }
  6809. }
  6810. });
  6811. FormValidation.Validator.uri = {
  6812. html5Attributes: {
  6813. message: 'message',
  6814. allowlocal: 'allowLocal',
  6815. allowemptyprotocol: 'allowEmptyProtocol',
  6816. protocol: 'protocol'
  6817. },
  6818. enableByHtml5: function($field) {
  6819. return ('url' === $field.attr('type'));
  6820. },
  6821. /**
  6822. * Return true if the input value is a valid URL
  6823. *
  6824. * @param {FormValidation.Base} validator The validator plugin instance
  6825. * @param {jQuery} $field Field element
  6826. * @param {Object} options
  6827. * - message: The error message
  6828. * - allowLocal: Allow the private and local network IP. Default to false
  6829. * - allowEmptyProtocol: Allow the URI without protocol. Default to false
  6830. * - protocol: The protocols, separated by a comma. Default to "http, https, ftp"
  6831. * @returns {Boolean}
  6832. */
  6833. validate: function(validator, $field, options) {
  6834. var value = validator.getFieldValue($field, 'uri');
  6835. if (value === '') {
  6836. return true;
  6837. }
  6838. // Credit to https://gist.github.com/dperini/729294
  6839. //
  6840. // Regular Expression for URL validation
  6841. //
  6842. // Author: Diego Perini
  6843. // Updated: 2010/12/05
  6844. //
  6845. // the regular expression composed & commented
  6846. // could be easily tweaked for RFC compliance,
  6847. // it was expressly modified to fit & satisfy
  6848. // these test for an URL shortener:
  6849. //
  6850. // http://mathiasbynens.be/demo/url-regex
  6851. //
  6852. // Notes on possible differences from a standard/generic validation:
  6853. //
  6854. // - utf-8 char class take in consideration the full Unicode range
  6855. // - TLDs are mandatory unless `allowLocal` is true
  6856. // - protocols have been restricted to ftp, http and https only as requested
  6857. //
  6858. // Changes:
  6859. //
  6860. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  6861. // first and last IP address of each class is considered invalid
  6862. // (since they are broadcast/network addresses)
  6863. //
  6864. // - Added exclusion of private, reserved and/or local networks ranges
  6865. // unless `allowLocal` is true
  6866. //
  6867. // - Added possibility of choosing a custom protocol
  6868. //
  6869. // - Add option to validate without protocol
  6870. //
  6871. var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
  6872. allowEmptyProtocol = options.allowEmptyProtocol === true || options.allowEmptyProtocol === 'true',
  6873. protocol = (options.protocol || 'http, https, ftp').split(',').join('|').replace(/\s/g, ''),
  6874. urlExp = new RegExp(
  6875. "^" +
  6876. // protocol identifier
  6877. "(?:(?:" + protocol + ")://)" +
  6878. // allow empty protocol
  6879. (allowEmptyProtocol ? '?' : '') +
  6880. // user:pass authentication
  6881. "(?:\\S+(?::\\S*)?@)?" +
  6882. "(?:" +
  6883. // IP address exclusion
  6884. // private & local networks
  6885. (allowLocal
  6886. ? ''
  6887. : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  6888. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  6889. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  6890. // IP address dotted notation octets
  6891. // excludes loopback network 0.0.0.0
  6892. // excludes reserved space >= 224.0.0.0
  6893. // excludes network & broadcast addresses
  6894. // (first & last IP address of each class)
  6895. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  6896. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  6897. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  6898. "|" +
  6899. // host name
  6900. "(?:(?:[a-z\\u00a1-\\uffff0-9]-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  6901. // domain name
  6902. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-?)*[a-z\\u00a1-\\uffff0-9])*" +
  6903. // TLD identifier
  6904. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  6905. // Allow intranet sites (no TLD) if `allowLocal` is true
  6906. (allowLocal ? '?' : '') +
  6907. ")" +
  6908. // port number
  6909. "(?::\\d{2,5})?" +
  6910. // resource path
  6911. "(?:/[^\\s]*)?" +
  6912. "$", "i"
  6913. );
  6914. return urlExp.test(value);
  6915. }
  6916. };
  6917. }(jQuery));
  6918. ;(function($) {
  6919. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6920. 'en_US': {
  6921. uuid: {
  6922. 'default': 'Please enter a valid UUID number',
  6923. version: 'Please enter a valid UUID version %s number'
  6924. }
  6925. }
  6926. });
  6927. FormValidation.Validator.uuid = {
  6928. html5Attributes: {
  6929. message: 'message',
  6930. version: 'version'
  6931. },
  6932. /**
  6933. * Return true if and only if the input value is a valid UUID string
  6934. *
  6935. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  6936. * @param {FormValidation.Base} validator The validator plugin instance
  6937. * @param {jQuery} $field Field element
  6938. * @param {Object} options Consist of key:
  6939. * - message: The invalid message
  6940. * - version: Can be 3, 4, 5, null
  6941. * @returns {Boolean|Object}
  6942. */
  6943. validate: function(validator, $field, options) {
  6944. var value = validator.getFieldValue($field, 'uuid');
  6945. if (value === '') {
  6946. return true;
  6947. }
  6948. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  6949. var locale = validator.getLocale(),
  6950. patterns = {
  6951. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  6952. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  6953. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  6954. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  6955. },
  6956. version = options.version ? (options.version + '') : 'all';
  6957. return {
  6958. valid: (null === patterns[version]) ? true : patterns[version].test(value),
  6959. message: options.version
  6960. ? FormValidation.Helper.format(options.message || FormValidation.I18n[locale].uuid.version, options.version)
  6961. : (options.message || FormValidation.I18n[locale].uuid['default'])
  6962. };
  6963. }
  6964. };
  6965. }(jQuery));
  6966. ;(function($) {
  6967. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  6968. 'en_US': {
  6969. vat: {
  6970. 'default': 'Please enter a valid VAT number',
  6971. country: 'Please enter a valid VAT number in %s',
  6972. countries: {
  6973. AT: 'Austria',
  6974. BE: 'Belgium',
  6975. BG: 'Bulgaria',
  6976. BR: 'Brazil',
  6977. CH: 'Switzerland',
  6978. CY: 'Cyprus',
  6979. CZ: 'Czech Republic',
  6980. DE: 'Germany',
  6981. DK: 'Denmark',
  6982. EE: 'Estonia',
  6983. ES: 'Spain',
  6984. FI: 'Finland',
  6985. FR: 'France',
  6986. GB: 'United Kingdom',
  6987. GR: 'Greek',
  6988. EL: 'Greek',
  6989. HU: 'Hungary',
  6990. HR: 'Croatia',
  6991. IE: 'Ireland',
  6992. IS: 'Iceland',
  6993. IT: 'Italy',
  6994. LT: 'Lithuania',
  6995. LU: 'Luxembourg',
  6996. LV: 'Latvia',
  6997. MT: 'Malta',
  6998. NL: 'Netherlands',
  6999. NO: 'Norway',
  7000. PL: 'Poland',
  7001. PT: 'Portugal',
  7002. RO: 'Romania',
  7003. RU: 'Russia',
  7004. RS: 'Serbia',
  7005. SE: 'Sweden',
  7006. SI: 'Slovenia',
  7007. SK: 'Slovakia',
  7008. VE: 'Venezuela',
  7009. ZA: 'South Africa'
  7010. }
  7011. }
  7012. }
  7013. });
  7014. FormValidation.Validator.vat = {
  7015. html5Attributes: {
  7016. message: 'message',
  7017. country: 'country'
  7018. },
  7019. // Supported country codes
  7020. COUNTRY_CODES: [
  7021. 'AT', 'BE', 'BG', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU',
  7022. 'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SE', 'SK', 'SI', 'VE',
  7023. 'ZA'
  7024. ],
  7025. /**
  7026. * Validate an European VAT number
  7027. *
  7028. * @param {FormValidation.Base} validator The validator plugin instance
  7029. * @param {jQuery} $field Field element
  7030. * @param {Object} options Consist of key:
  7031. * - message: The invalid message
  7032. * - country: The ISO 3166-1 country code. It can be
  7033. * - One of country code defined in COUNTRY_CODES
  7034. * - Name of field which its value defines the country code
  7035. * - Name of callback function that returns the country code
  7036. * - A callback function that returns the country code
  7037. * @returns {Boolean|Object}
  7038. */
  7039. validate: function(validator, $field, options) {
  7040. var value = validator.getFieldValue($field, 'vat');
  7041. if (value === '') {
  7042. return true;
  7043. }
  7044. var locale = validator.getLocale(),
  7045. country = options.country;
  7046. if (!country) {
  7047. country = value.substr(0, 2);
  7048. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  7049. // Determine the country code
  7050. country = validator.getDynamicOption($field, country);
  7051. }
  7052. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  7053. return true;
  7054. }
  7055. var method = ['_', country.toLowerCase()].join('');
  7056. return this[method](value)
  7057. ? true
  7058. : {
  7059. valid: false,
  7060. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].vat.country, FormValidation.I18n[locale].vat.countries[country.toUpperCase()])
  7061. };
  7062. },
  7063. // VAT validators
  7064. /**
  7065. * Validate Austrian VAT number
  7066. * Example:
  7067. * - Valid: ATU13585627
  7068. * - Invalid: ATU13585626
  7069. *
  7070. * @param {String} value VAT number
  7071. * @returns {Boolean}
  7072. */
  7073. _at: function(value) {
  7074. if (/^ATU[0-9]{8}$/.test(value)) {
  7075. value = value.substr(2);
  7076. }
  7077. if (!/^U[0-9]{8}$/.test(value)) {
  7078. return false;
  7079. }
  7080. value = value.substr(1);
  7081. var sum = 0,
  7082. weight = [1, 2, 1, 2, 1, 2, 1],
  7083. temp = 0;
  7084. for (var i = 0; i < 7; i++) {
  7085. temp = parseInt(value.charAt(i), 10) * weight[i];
  7086. if (temp > 9) {
  7087. temp = Math.floor(temp / 10) + temp % 10;
  7088. }
  7089. sum += temp;
  7090. }
  7091. sum = 10 - (sum + 4) % 10;
  7092. if (sum === 10) {
  7093. sum = 0;
  7094. }
  7095. return (sum + '' === value.substr(7, 1));
  7096. },
  7097. /**
  7098. * Validate Belgian VAT number
  7099. * Example:
  7100. * - Valid: BE0428759497
  7101. * - Invalid: BE431150351
  7102. *
  7103. * @param {String} value VAT number
  7104. * @returns {Boolean}
  7105. */
  7106. _be: function(value) {
  7107. if (/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  7108. value = value.substr(2);
  7109. }
  7110. if (!/^[0]{0,1}[0-9]{9}$/.test(value)) {
  7111. return false;
  7112. }
  7113. if (value.length === 9) {
  7114. value = '0' + value;
  7115. }
  7116. if (value.substr(1, 1) === '0') {
  7117. return false;
  7118. }
  7119. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  7120. return (sum % 97 === 0);
  7121. },
  7122. /**
  7123. * Validate Bulgarian VAT number
  7124. * Example:
  7125. * - Valid: BG175074752,
  7126. * BG7523169263, BG8032056031,
  7127. * BG7542011030,
  7128. * BG7111042925
  7129. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  7130. *
  7131. * @param {String} value VAT number
  7132. * @returns {Boolean}
  7133. */
  7134. _bg: function(value) {
  7135. if (/^BG[0-9]{9,10}$/.test(value)) {
  7136. value = value.substr(2);
  7137. }
  7138. if (!/^[0-9]{9,10}$/.test(value)) {
  7139. return false;
  7140. }
  7141. var sum = 0, i = 0;
  7142. // Legal entities
  7143. if (value.length === 9) {
  7144. for (i = 0; i < 8; i++) {
  7145. sum += parseInt(value.charAt(i), 10) * (i + 1);
  7146. }
  7147. sum = sum % 11;
  7148. if (sum === 10) {
  7149. sum = 0;
  7150. for (i = 0; i < 8; i++) {
  7151. sum += parseInt(value.charAt(i), 10) * (i + 3);
  7152. }
  7153. }
  7154. sum = sum % 10;
  7155. return (sum + '' === value.substr(8));
  7156. }
  7157. // Physical persons, foreigners and others
  7158. else if (value.length === 10) {
  7159. // Validate Bulgarian national identification numbers
  7160. var egn = function(value) {
  7161. // Check the birth date
  7162. var year = parseInt(value.substr(0, 2), 10) + 1900,
  7163. month = parseInt(value.substr(2, 2), 10),
  7164. day = parseInt(value.substr(4, 2), 10);
  7165. if (month > 40) {
  7166. year += 100;
  7167. month -= 40;
  7168. } else if (month > 20) {
  7169. year -= 100;
  7170. month -= 20;
  7171. }
  7172. if (!FormValidation.Helper.date(year, month, day)) {
  7173. return false;
  7174. }
  7175. var sum = 0,
  7176. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  7177. for (var i = 0; i < 9; i++) {
  7178. sum += parseInt(value.charAt(i), 10) * weight[i];
  7179. }
  7180. sum = (sum % 11) % 10;
  7181. return (sum + '' === value.substr(9, 1));
  7182. },
  7183. // Validate Bulgarian personal number of a foreigner
  7184. pnf = function(value) {
  7185. var sum = 0,
  7186. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  7187. for (var i = 0; i < 9; i++) {
  7188. sum += parseInt(value.charAt(i), 10) * weight[i];
  7189. }
  7190. sum = sum % 10;
  7191. return (sum + '' === value.substr(9, 1));
  7192. },
  7193. // Finally, consider it as a VAT number
  7194. vat = function(value) {
  7195. var sum = 0,
  7196. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  7197. for (var i = 0; i < 9; i++) {
  7198. sum += parseInt(value.charAt(i), 10) * weight[i];
  7199. }
  7200. sum = 11 - sum % 11;
  7201. if (sum === 10) {
  7202. return false;
  7203. }
  7204. if (sum === 11) {
  7205. sum = 0;
  7206. }
  7207. return (sum + '' === value.substr(9, 1));
  7208. };
  7209. return (egn(value) || pnf(value) || vat(value));
  7210. }
  7211. return false;
  7212. },
  7213. /**
  7214. * Validate Brazilian VAT number (CNPJ)
  7215. *
  7216. * @param {String} value VAT number
  7217. * @returns {Boolean}
  7218. */
  7219. _br: function(value) {
  7220. if (value === '') {
  7221. return true;
  7222. }
  7223. var cnpj = value.replace(/[^\d]+/g, '');
  7224. if (cnpj === '' || cnpj.length !== 14) {
  7225. return false;
  7226. }
  7227. // Remove invalids CNPJs
  7228. if (cnpj === '00000000000000' || cnpj === '11111111111111' || cnpj === '22222222222222' ||
  7229. cnpj === '33333333333333' || cnpj === '44444444444444' || cnpj === '55555555555555' ||
  7230. cnpj === '66666666666666' || cnpj === '77777777777777' || cnpj === '88888888888888' ||
  7231. cnpj === '99999999999999')
  7232. {
  7233. return false;
  7234. }
  7235. // Validate verification digits
  7236. var length = cnpj.length - 2,
  7237. numbers = cnpj.substring(0, length),
  7238. digits = cnpj.substring(length),
  7239. sum = 0,
  7240. pos = length - 7;
  7241. for (var i = length; i >= 1; i--) {
  7242. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  7243. if (pos < 2) {
  7244. pos = 9;
  7245. }
  7246. }
  7247. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  7248. if (result !== parseInt(digits.charAt(0), 10)) {
  7249. return false;
  7250. }
  7251. length = length + 1;
  7252. numbers = cnpj.substring(0, length);
  7253. sum = 0;
  7254. pos = length - 7;
  7255. for (i = length; i >= 1; i--) {
  7256. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  7257. if (pos < 2) {
  7258. pos = 9;
  7259. }
  7260. }
  7261. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  7262. return (result === parseInt(digits.charAt(1), 10));
  7263. },
  7264. /**
  7265. * Validate Swiss VAT number
  7266. *
  7267. * @param {String} value VAT number
  7268. * @returns {Boolean}
  7269. */
  7270. _ch: function(value) {
  7271. if (/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  7272. value = value.substr(2);
  7273. }
  7274. if (!/^E[0-9]{9}(MWST)?$/.test(value)) {
  7275. return false;
  7276. }
  7277. value = value.substr(1);
  7278. var sum = 0,
  7279. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  7280. for (var i = 0; i < 8; i++) {
  7281. sum += parseInt(value.charAt(i), 10) * weight[i];
  7282. }
  7283. sum = 11 - sum % 11;
  7284. if (sum === 10) {
  7285. return false;
  7286. }
  7287. if (sum === 11) {
  7288. sum = 0;
  7289. }
  7290. return (sum + '' === value.substr(8, 1));
  7291. },
  7292. /**
  7293. * Validate Cypriot VAT number
  7294. * Examples:
  7295. * - Valid: CY10259033P
  7296. * - Invalid: CY10259033Z
  7297. *
  7298. * @param {String} value VAT number
  7299. * @returns {Boolean}
  7300. */
  7301. _cy: function(value) {
  7302. if (/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  7303. value = value.substr(2);
  7304. }
  7305. if (!/^[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  7306. return false;
  7307. }
  7308. // Do not allow to start with "12"
  7309. if (value.substr(0, 2) === '12') {
  7310. return false;
  7311. }
  7312. // Extract the next digit and multiply by the counter.
  7313. var sum = 0,
  7314. translation = {
  7315. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  7316. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  7317. };
  7318. for (var i = 0; i < 8; i++) {
  7319. var temp = parseInt(value.charAt(i), 10);
  7320. if (i % 2 === 0) {
  7321. temp = translation[temp + ''];
  7322. }
  7323. sum += temp;
  7324. }
  7325. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  7326. return (sum + '' === value.substr(8, 1));
  7327. },
  7328. /**
  7329. * Validate Czech Republic VAT number
  7330. * Can be:
  7331. * i) Legal entities (8 digit numbers)
  7332. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  7333. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  7334. *
  7335. * Examples:
  7336. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  7337. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  7338. *
  7339. * @param {String} value VAT number
  7340. * @returns {Boolean}
  7341. */
  7342. _cz: function(value) {
  7343. if (/^CZ[0-9]{8,10}$/.test(value)) {
  7344. value = value.substr(2);
  7345. }
  7346. if (!/^[0-9]{8,10}$/.test(value)) {
  7347. return false;
  7348. }
  7349. var sum = 0,
  7350. i = 0;
  7351. if (value.length === 8) {
  7352. // Do not allow to start with '9'
  7353. if (value.charAt(0) + '' === '9') {
  7354. return false;
  7355. }
  7356. sum = 0;
  7357. for (i = 0; i < 7; i++) {
  7358. sum += parseInt(value.charAt(i), 10) * (8 - i);
  7359. }
  7360. sum = 11 - sum % 11;
  7361. if (sum === 10) {
  7362. sum = 0;
  7363. }
  7364. if (sum === 11) {
  7365. sum = 1;
  7366. }
  7367. return (sum + '' === value.substr(7, 1));
  7368. } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  7369. sum = 0;
  7370. // Skip the first (which is 6)
  7371. for (i = 0; i < 7; i++) {
  7372. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  7373. }
  7374. sum = 11 - sum % 11;
  7375. if (sum === 10) {
  7376. sum = 0;
  7377. }
  7378. if (sum === 11) {
  7379. sum = 1;
  7380. }
  7381. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  7382. return (sum + '' === value.substr(8, 1));
  7383. } else if (value.length === 9 || value.length === 10) {
  7384. // Validate Czech birth number (Rodné číslo), which is also national identifier
  7385. var year = 1900 + parseInt(value.substr(0, 2), 10),
  7386. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  7387. day = parseInt(value.substr(4, 2), 10);
  7388. if (value.length === 9) {
  7389. if (year >= 1980) {
  7390. year -= 100;
  7391. }
  7392. if (year > 1953) {
  7393. return false;
  7394. }
  7395. } else if (year < 1954) {
  7396. year += 100;
  7397. }
  7398. if (!FormValidation.Helper.date(year, month, day)) {
  7399. return false;
  7400. }
  7401. // Check that the birth date is not in the future
  7402. if (value.length === 10) {
  7403. var check = parseInt(value.substr(0, 9), 10) % 11;
  7404. if (year < 1985) {
  7405. check = check % 10;
  7406. }
  7407. return (check + '' === value.substr(9, 1));
  7408. }
  7409. return true;
  7410. }
  7411. return false;
  7412. },
  7413. /**
  7414. * Validate German VAT number
  7415. * Examples:
  7416. * - Valid: DE136695976
  7417. * - Invalid: DE136695978
  7418. *
  7419. * @param {String} value VAT number
  7420. * @returns {Boolean}
  7421. */
  7422. _de: function(value) {
  7423. if (/^DE[0-9]{9}$/.test(value)) {
  7424. value = value.substr(2);
  7425. }
  7426. if (!/^[0-9]{9}$/.test(value)) {
  7427. return false;
  7428. }
  7429. return FormValidation.Helper.mod11And10(value);
  7430. },
  7431. /**
  7432. * Validate Danish VAT number
  7433. * Example:
  7434. * - Valid: DK13585628
  7435. * - Invalid: DK13585627
  7436. *
  7437. * @param {String} value VAT number
  7438. * @returns {Boolean}
  7439. */
  7440. _dk: function(value) {
  7441. if (/^DK[0-9]{8}$/.test(value)) {
  7442. value = value.substr(2);
  7443. }
  7444. if (!/^[0-9]{8}$/.test(value)) {
  7445. return false;
  7446. }
  7447. var sum = 0,
  7448. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  7449. for (var i = 0; i < 8; i++) {
  7450. sum += parseInt(value.charAt(i), 10) * weight[i];
  7451. }
  7452. return (sum % 11 === 0);
  7453. },
  7454. /**
  7455. * Validate Estonian VAT number
  7456. * Examples:
  7457. * - Valid: EE100931558, EE100594102
  7458. * - Invalid: EE100594103
  7459. *
  7460. * @param {String} value VAT number
  7461. * @returns {Boolean}
  7462. */
  7463. _ee: function(value) {
  7464. if (/^EE[0-9]{9}$/.test(value)) {
  7465. value = value.substr(2);
  7466. }
  7467. if (!/^[0-9]{9}$/.test(value)) {
  7468. return false;
  7469. }
  7470. var sum = 0,
  7471. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  7472. for (var i = 0; i < 9; i++) {
  7473. sum += parseInt(value.charAt(i), 10) * weight[i];
  7474. }
  7475. return (sum % 10 === 0);
  7476. },
  7477. /**
  7478. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  7479. * Can be:
  7480. * i) DNI (Documento nacional de identidad), for Spaniards
  7481. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  7482. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  7483. *
  7484. * Examples:
  7485. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  7486. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  7487. *
  7488. * @param {String} value VAT number
  7489. * @returns {Boolean}
  7490. */
  7491. _es: function(value) {
  7492. if (/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  7493. value = value.substr(2);
  7494. }
  7495. if (!/^[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  7496. return false;
  7497. }
  7498. var dni = function(value) {
  7499. var check = parseInt(value.substr(0, 8), 10);
  7500. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  7501. return (check + '' === value.substr(8, 1));
  7502. },
  7503. nie = function(value) {
  7504. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  7505. check = parseInt(check, 10);
  7506. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  7507. return (check + '' === value.substr(8, 1));
  7508. },
  7509. cif = function(value) {
  7510. var first = value.charAt(0), check;
  7511. if ('KLM'.indexOf(first) !== -1) {
  7512. // K: Spanish younger than 14 year old
  7513. // L: Spanish living outside Spain without DNI
  7514. // M: Granted the tax to foreigners who have no NIE
  7515. check = parseInt(value.substr(1, 8), 10);
  7516. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  7517. return (check + '' === value.substr(8, 1));
  7518. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  7519. var sum = 0,
  7520. weight = [2, 1, 2, 1, 2, 1, 2],
  7521. temp = 0;
  7522. for (var i = 0; i < 7; i++) {
  7523. temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  7524. if (temp > 9) {
  7525. temp = Math.floor(temp / 10) + temp % 10;
  7526. }
  7527. sum += temp;
  7528. }
  7529. sum = 10 - sum % 10;
  7530. if (sum === 10) {
  7531. sum = 0;
  7532. }
  7533. return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  7534. }
  7535. return false;
  7536. };
  7537. var first = value.charAt(0);
  7538. if (/^[0-9]$/.test(first)) {
  7539. return dni(value);
  7540. } else if (/^[XYZ]$/.test(first)) {
  7541. return nie(value);
  7542. } else {
  7543. return cif(value);
  7544. }
  7545. },
  7546. /**
  7547. * Validate Finnish VAT number
  7548. * Examples:
  7549. * - Valid: FI20774740
  7550. * - Invalid: FI20774741
  7551. *
  7552. * @param {String} value VAT number
  7553. * @returns {Boolean}
  7554. */
  7555. _fi: function(value) {
  7556. if (/^FI[0-9]{8}$/.test(value)) {
  7557. value = value.substr(2);
  7558. }
  7559. if (!/^[0-9]{8}$/.test(value)) {
  7560. return false;
  7561. }
  7562. var sum = 0,
  7563. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  7564. for (var i = 0; i < 8; i++) {
  7565. sum += parseInt(value.charAt(i), 10) * weight[i];
  7566. }
  7567. return (sum % 11 === 0);
  7568. },
  7569. /**
  7570. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  7571. * It's constructed by a SIREN number, prefixed by two characters.
  7572. *
  7573. * Examples:
  7574. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  7575. * - Invalid: FR84323140391
  7576. *
  7577. * @param {String} value VAT number
  7578. * @returns {Boolean}
  7579. */
  7580. _fr: function(value) {
  7581. if (/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  7582. value = value.substr(2);
  7583. }
  7584. if (!/^[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  7585. return false;
  7586. }
  7587. if (!FormValidation.Helper.luhn(value.substr(2))) {
  7588. return false;
  7589. }
  7590. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  7591. // First two characters are digits
  7592. return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  7593. } else {
  7594. // The first characters cann't be O and I
  7595. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  7596. check;
  7597. // First one is digit
  7598. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  7599. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  7600. } else {
  7601. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  7602. }
  7603. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  7604. }
  7605. },
  7606. /**
  7607. * Validate United Kingdom VAT number
  7608. * Example:
  7609. * - Valid: GB980780684
  7610. * - Invalid: GB802311781
  7611. *
  7612. * @param {String} value VAT number
  7613. * @returns {Boolean}
  7614. */
  7615. _gb: function(value) {
  7616. if (/^GB[0-9]{9}$/.test(value) /* Standard */
  7617. || /^GB[0-9]{12}$/.test(value) /* Branches */
  7618. || /^GBGD[0-9]{3}$/.test(value) /* Government department */
  7619. || /^GBHA[0-9]{3}$/.test(value) /* Health authority */
  7620. || /^GB(GD|HA)8888[0-9]{5}$/.test(value))
  7621. {
  7622. value = value.substr(2);
  7623. }
  7624. if (!/^[0-9]{9}$/.test(value)
  7625. && !/^[0-9]{12}$/.test(value)
  7626. && !/^GD[0-9]{3}$/.test(value)
  7627. && !/^HA[0-9]{3}$/.test(value)
  7628. && !/^(GD|HA)8888[0-9]{5}$/.test(value))
  7629. {
  7630. return false;
  7631. }
  7632. var length = value.length;
  7633. if (length === 5) {
  7634. var firstTwo = value.substr(0, 2),
  7635. lastThree = parseInt(value.substr(2), 10);
  7636. return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  7637. } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  7638. if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  7639. || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  7640. {
  7641. return false;
  7642. }
  7643. return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  7644. } else if (length === 9 || length === 12) {
  7645. var sum = 0,
  7646. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  7647. for (var i = 0; i < 9; i++) {
  7648. sum += parseInt(value.charAt(i), 10) * weight[i];
  7649. }
  7650. sum = sum % 97;
  7651. if (parseInt(value.substr(0, 3), 10) >= 100) {
  7652. return (sum === 0 || sum === 42 || sum === 55);
  7653. } else {
  7654. return (sum === 0);
  7655. }
  7656. }
  7657. return true;
  7658. },
  7659. /**
  7660. * Validate Greek VAT number
  7661. * Examples:
  7662. * - Valid: GR023456780, EL094259216
  7663. * - Invalid: EL123456781
  7664. *
  7665. * @param {String} value VAT number
  7666. * @returns {Boolean}
  7667. */
  7668. _gr: function(value) {
  7669. if (/^(GR|EL)[0-9]{9}$/.test(value)) {
  7670. value = value.substr(2);
  7671. }
  7672. if (!/^[0-9]{9}$/.test(value)) {
  7673. return false;
  7674. }
  7675. if (value.length === 8) {
  7676. value = '0' + value;
  7677. }
  7678. var sum = 0,
  7679. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  7680. for (var i = 0; i < 8; i++) {
  7681. sum += parseInt(value.charAt(i), 10) * weight[i];
  7682. }
  7683. sum = (sum % 11) % 10;
  7684. return (sum + '' === value.substr(8, 1));
  7685. },
  7686. // EL is traditionally prefix of Greek VAT numbers
  7687. _el: function(value) {
  7688. return this._gr(value);
  7689. },
  7690. /**
  7691. * Validate Hungarian VAT number
  7692. * Examples:
  7693. * - Valid: HU12892312
  7694. * - Invalid: HU12892313
  7695. *
  7696. * @param {String} value VAT number
  7697. * @returns {Boolean}
  7698. */
  7699. _hu: function(value) {
  7700. if (/^HU[0-9]{8}$/.test(value)) {
  7701. value = value.substr(2);
  7702. }
  7703. if (!/^[0-9]{8}$/.test(value)) {
  7704. return false;
  7705. }
  7706. var sum = 0,
  7707. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  7708. for (var i = 0; i < 8; i++) {
  7709. sum += parseInt(value.charAt(i), 10) * weight[i];
  7710. }
  7711. return (sum % 10 === 0);
  7712. },
  7713. /**
  7714. * Validate Croatian VAT number
  7715. * Examples:
  7716. * - Valid: HR33392005961
  7717. * - Invalid: HR33392005962
  7718. *
  7719. * @param {String} value VAT number
  7720. * @returns {Boolean}
  7721. */
  7722. _hr: function(value) {
  7723. if (/^HR[0-9]{11}$/.test(value)) {
  7724. value = value.substr(2);
  7725. }
  7726. if (!/^[0-9]{11}$/.test(value)) {
  7727. return false;
  7728. }
  7729. return FormValidation.Helper.mod11And10(value);
  7730. },
  7731. /**
  7732. * Validate Irish VAT number
  7733. * Examples:
  7734. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  7735. * - Invalid: IE8D79738J
  7736. *
  7737. * @param {String} value VAT number
  7738. * @returns {Boolean}
  7739. */
  7740. _ie: function(value) {
  7741. if (/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  7742. value = value.substr(2);
  7743. }
  7744. if (!/^[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  7745. return false;
  7746. }
  7747. var getCheckDigit = function(value) {
  7748. while (value.length < 7) {
  7749. value = '0' + value;
  7750. }
  7751. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  7752. sum = 0;
  7753. for (var i = 0; i < 7; i++) {
  7754. sum += parseInt(value.charAt(i), 10) * (8 - i);
  7755. }
  7756. sum += 9 * alphabet.indexOf(value.substr(7));
  7757. return alphabet[sum % 23];
  7758. };
  7759. // The first 7 characters are digits
  7760. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  7761. // New system
  7762. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  7763. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  7764. // Old system
  7765. return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  7766. }
  7767. return true;
  7768. },
  7769. /**
  7770. * Validate Icelandic VAT (VSK) number
  7771. * Examples:
  7772. * - Valid: 12345, 123456
  7773. * - Invalid: 1234567
  7774. *
  7775. * @params {String} value VAT number
  7776. * @returns {Boolean}
  7777. */
  7778. _is: function(value) {
  7779. if (/^IS[0-9]{5,6}$/.test(value)) {
  7780. value = value.substr(2);
  7781. }
  7782. return /^[0-9]{5,6}$/.test(value);
  7783. },
  7784. /**
  7785. * Validate Italian VAT number, which consists of 11 digits.
  7786. * - First 7 digits are a company identifier
  7787. * - Next 3 are the province of residence
  7788. * - The last one is a check digit
  7789. *
  7790. * Examples:
  7791. * - Valid: IT00743110157
  7792. * - Invalid: IT00743110158
  7793. *
  7794. * @param {String} value VAT number
  7795. * @returns {Boolean}
  7796. */
  7797. _it: function(value) {
  7798. if (/^IT[0-9]{11}$/.test(value)) {
  7799. value = value.substr(2);
  7800. }
  7801. if (!/^[0-9]{11}$/.test(value)) {
  7802. return false;
  7803. }
  7804. if (parseInt(value.substr(0, 7), 10) === 0) {
  7805. return false;
  7806. }
  7807. var lastThree = parseInt(value.substr(7, 3), 10);
  7808. if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  7809. return false;
  7810. }
  7811. return FormValidation.Helper.luhn(value);
  7812. },
  7813. /**
  7814. * Validate Lithuanian VAT number
  7815. * It can be:
  7816. * - 9 digits, for legal entities
  7817. * - 12 digits, for temporarily registered taxpayers
  7818. *
  7819. * Examples:
  7820. * - Valid: LT119511515, LT100001919017, LT100004801610
  7821. * - Invalid: LT100001919018
  7822. *
  7823. * @param {String} value VAT number
  7824. * @returns {Boolean}
  7825. */
  7826. _lt: function(value) {
  7827. if (/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  7828. value = value.substr(2);
  7829. }
  7830. if (!/^([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  7831. return false;
  7832. }
  7833. var length = value.length,
  7834. sum = 0,
  7835. i;
  7836. for (i = 0; i < length - 1; i++) {
  7837. sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  7838. }
  7839. var check = sum % 11;
  7840. if (check === 10) {
  7841. sum = 0;
  7842. for (i = 0; i < length - 1; i++) {
  7843. sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  7844. }
  7845. }
  7846. check = check % 11 % 10;
  7847. return (check + '' === value.charAt(length - 1));
  7848. },
  7849. /**
  7850. * Validate Luxembourg VAT number
  7851. * Examples:
  7852. * - Valid: LU15027442
  7853. * - Invalid: LU15027443
  7854. *
  7855. * @param {String} value VAT number
  7856. * @returns {Boolean}
  7857. */
  7858. _lu: function(value) {
  7859. if (/^LU[0-9]{8}$/.test(value)) {
  7860. value = value.substr(2);
  7861. }
  7862. if (!/^[0-9]{8}$/.test(value)) {
  7863. return false;
  7864. }
  7865. return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  7866. },
  7867. /**
  7868. * Validate Latvian VAT number
  7869. * Examples:
  7870. * - Valid: LV40003521600, LV16117519997
  7871. * - Invalid: LV40003521601, LV16137519997
  7872. *
  7873. * @param {String} value VAT number
  7874. * @returns {Boolean}
  7875. */
  7876. _lv: function(value) {
  7877. if (/^LV[0-9]{11}$/.test(value)) {
  7878. value = value.substr(2);
  7879. }
  7880. if (!/^[0-9]{11}$/.test(value)) {
  7881. return false;
  7882. }
  7883. var first = parseInt(value.charAt(0), 10),
  7884. sum = 0,
  7885. weight = [],
  7886. i,
  7887. length = value.length;
  7888. if (first > 3) {
  7889. // Legal entity
  7890. sum = 0;
  7891. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  7892. for (i = 0; i < length; i++) {
  7893. sum += parseInt(value.charAt(i), 10) * weight[i];
  7894. }
  7895. sum = sum % 11;
  7896. return (sum === 3);
  7897. } else {
  7898. // Check birth date
  7899. var day = parseInt(value.substr(0, 2), 10),
  7900. month = parseInt(value.substr(2, 2), 10),
  7901. year = parseInt(value.substr(4, 2), 10);
  7902. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  7903. if (!FormValidation.Helper.date(year, month, day)) {
  7904. return false;
  7905. }
  7906. // Check personal code
  7907. sum = 0;
  7908. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  7909. for (i = 0; i < length - 1; i++) {
  7910. sum += parseInt(value.charAt(i), 10) * weight[i];
  7911. }
  7912. sum = (sum + 1) % 11 % 10;
  7913. return (sum + '' === value.charAt(length - 1));
  7914. }
  7915. },
  7916. /**
  7917. * Validate Maltese VAT number
  7918. * Examples:
  7919. * - Valid: MT11679112
  7920. * - Invalid: MT11679113
  7921. *
  7922. * @param {String} value VAT number
  7923. * @returns {Boolean}
  7924. */
  7925. _mt: function(value) {
  7926. if (/^MT[0-9]{8}$/.test(value)) {
  7927. value = value.substr(2);
  7928. }
  7929. if (!/^[0-9]{8}$/.test(value)) {
  7930. return false;
  7931. }
  7932. var sum = 0,
  7933. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  7934. for (var i = 0; i < 8; i++) {
  7935. sum += parseInt(value.charAt(i), 10) * weight[i];
  7936. }
  7937. return (sum % 37 === 0);
  7938. },
  7939. /**
  7940. * Validate Dutch VAT number
  7941. * Examples:
  7942. * - Valid: NL004495445B01
  7943. * - Invalid: NL123456789B90
  7944. *
  7945. * @param {String} value VAT number
  7946. * @returns {Boolean}
  7947. */
  7948. _nl: function(value) {
  7949. if (/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  7950. value = value.substr(2);
  7951. }
  7952. if (!/^[0-9]{9}B[0-9]{2}$/.test(value)) {
  7953. return false;
  7954. }
  7955. var sum = 0,
  7956. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  7957. for (var i = 0; i < 8; i++) {
  7958. sum += parseInt(value.charAt(i), 10) * weight[i];
  7959. }
  7960. sum = sum % 11;
  7961. if (sum > 9) {
  7962. sum = 0;
  7963. }
  7964. return (sum + '' === value.substr(8, 1));
  7965. },
  7966. /**
  7967. * Validate Norwegian VAT number
  7968. *
  7969. * @see http://www.brreg.no/english/coordination/number.html
  7970. * @param {String} value VAT number
  7971. * @returns {Boolean}
  7972. */
  7973. _no: function(value) {
  7974. if (/^NO[0-9]{9}$/.test(value)) {
  7975. value = value.substr(2);
  7976. }
  7977. if (!/^[0-9]{9}$/.test(value)) {
  7978. return false;
  7979. }
  7980. var sum = 0,
  7981. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  7982. for (var i = 0; i < 8; i++) {
  7983. sum += parseInt(value.charAt(i), 10) * weight[i];
  7984. }
  7985. sum = 11 - sum % 11;
  7986. if (sum === 11) {
  7987. sum = 0;
  7988. }
  7989. return (sum + '' === value.substr(8, 1));
  7990. },
  7991. /**
  7992. * Validate Polish VAT number
  7993. * Examples:
  7994. * - Valid: PL8567346215
  7995. * - Invalid: PL8567346216
  7996. *
  7997. * @param {String} value VAT number
  7998. * @returns {Boolean}
  7999. */
  8000. _pl: function(value) {
  8001. if (/^PL[0-9]{10}$/.test(value)) {
  8002. value = value.substr(2);
  8003. }
  8004. if (!/^[0-9]{10}$/.test(value)) {
  8005. return false;
  8006. }
  8007. var sum = 0,
  8008. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  8009. for (var i = 0; i < 10; i++) {
  8010. sum += parseInt(value.charAt(i), 10) * weight[i];
  8011. }
  8012. return (sum % 11 === 0);
  8013. },
  8014. /**
  8015. * Validate Portuguese VAT number
  8016. * Examples:
  8017. * - Valid: PT501964843
  8018. * - Invalid: PT501964842
  8019. *
  8020. * @param {String} value VAT number
  8021. * @returns {Boolean}
  8022. */
  8023. _pt: function(value) {
  8024. if (/^PT[0-9]{9}$/.test(value)) {
  8025. value = value.substr(2);
  8026. }
  8027. if (!/^[0-9]{9}$/.test(value)) {
  8028. return false;
  8029. }
  8030. var sum = 0,
  8031. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  8032. for (var i = 0; i < 8; i++) {
  8033. sum += parseInt(value.charAt(i), 10) * weight[i];
  8034. }
  8035. sum = 11 - sum % 11;
  8036. if (sum > 9) {
  8037. sum = 0;
  8038. }
  8039. return (sum + '' === value.substr(8, 1));
  8040. },
  8041. /**
  8042. * Validate Romanian VAT number
  8043. * Examples:
  8044. * - Valid: RO18547290
  8045. * - Invalid: RO18547291
  8046. *
  8047. * @param {String} value VAT number
  8048. * @returns {Boolean}
  8049. */
  8050. _ro: function(value) {
  8051. if (/^RO[1-9][0-9]{1,9}$/.test(value)) {
  8052. value = value.substr(2);
  8053. }
  8054. if (!/^[1-9][0-9]{1,9}$/.test(value)) {
  8055. return false;
  8056. }
  8057. var length = value.length,
  8058. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  8059. sum = 0;
  8060. for (var i = 0; i < length - 1; i++) {
  8061. sum += parseInt(value.charAt(i), 10) * weight[i];
  8062. }
  8063. sum = (10 * sum) % 11 % 10;
  8064. return (sum + '' === value.substr(length - 1, 1));
  8065. },
  8066. /**
  8067. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  8068. *
  8069. * @param {String} value VAT number
  8070. * @returns {Boolean}
  8071. */
  8072. _ru: function(value) {
  8073. if (/^RU([0-9]{10}|[0-9]{12})$/.test(value)) {
  8074. value = value.substr(2);
  8075. }
  8076. if (!/^([0-9]{10}|[0-9]{12})$/.test(value)) {
  8077. return false;
  8078. }
  8079. var i = 0;
  8080. if (value.length === 10) {
  8081. var sum = 0,
  8082. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  8083. for (i = 0; i < 10; i++) {
  8084. sum += parseInt(value.charAt(i), 10) * weight[i];
  8085. }
  8086. sum = sum % 11;
  8087. if (sum > 9) {
  8088. sum = sum % 10;
  8089. }
  8090. return (sum + '' === value.substr(9, 1));
  8091. } else if (value.length === 12) {
  8092. var sum1 = 0,
  8093. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  8094. sum2 = 0,
  8095. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  8096. for (i = 0; i < 11; i++) {
  8097. sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  8098. sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  8099. }
  8100. sum1 = sum1 % 11;
  8101. if (sum1 > 9) {
  8102. sum1 = sum1 % 10;
  8103. }
  8104. sum2 = sum2 % 11;
  8105. if (sum2 > 9) {
  8106. sum2 = sum2 % 10;
  8107. }
  8108. return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  8109. }
  8110. return false;
  8111. },
  8112. /**
  8113. * Validate Serbian VAT number
  8114. *
  8115. * @param {String} value VAT number
  8116. * @returns {Boolean}
  8117. */
  8118. _rs: function(value) {
  8119. if (/^RS[0-9]{9}$/.test(value)) {
  8120. value = value.substr(2);
  8121. }
  8122. if (!/^[0-9]{9}$/.test(value)) {
  8123. return false;
  8124. }
  8125. var sum = 10,
  8126. temp = 0;
  8127. for (var i = 0; i < 8; i++) {
  8128. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  8129. if (temp === 0) {
  8130. temp = 10;
  8131. }
  8132. sum = (2 * temp) % 11;
  8133. }
  8134. return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  8135. },
  8136. /**
  8137. * Validate Swedish VAT number
  8138. * Examples:
  8139. * - Valid: SE123456789701
  8140. * - Invalid: SE123456789101
  8141. *
  8142. * @param {String} value VAT number
  8143. * @returns {Boolean}
  8144. */
  8145. _se: function(value) {
  8146. if (/^SE[0-9]{10}01$/.test(value)) {
  8147. value = value.substr(2);
  8148. }
  8149. if (!/^[0-9]{10}01$/.test(value)) {
  8150. return false;
  8151. }
  8152. value = value.substr(0, 10);
  8153. return FormValidation.Helper.luhn(value);
  8154. },
  8155. /**
  8156. * Validate Slovenian VAT number
  8157. * Examples:
  8158. * - Valid: SI50223054
  8159. * - Invalid: SI50223055
  8160. * - Invalid: SI09999990
  8161. *
  8162. * @param {String} value VAT number
  8163. * @returns {Boolean}
  8164. */
  8165. _si: function(value) {
  8166. // The Slovenian VAT numbers don't start with zero
  8167. var res = value.match(/^(SI)?([1-9][0-9]{7})$/);
  8168. if (!res) {
  8169. return false;
  8170. }
  8171. if (res[1]) {
  8172. value = value.substr(2);
  8173. }
  8174. var sum = 0,
  8175. weight = [8, 7, 6, 5, 4, 3, 2];
  8176. for (var i = 0; i < 7; i++) {
  8177. sum += parseInt(value.charAt(i), 10) * weight[i];
  8178. }
  8179. sum = 11 - sum % 11;
  8180. if (sum === 10) {
  8181. sum = 0;
  8182. }
  8183. return (sum + '' === value.substr(7, 1));
  8184. },
  8185. /**
  8186. * Validate Slovak VAT number
  8187. * Examples:
  8188. * - Valid: SK2022749619
  8189. * - Invalid: SK2022749618
  8190. *
  8191. * @param {String} value VAT number
  8192. * @returns {Boolean}
  8193. */
  8194. _sk: function(value) {
  8195. if (/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  8196. value = value.substr(2);
  8197. }
  8198. if (!/^[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  8199. return false;
  8200. }
  8201. return (parseInt(value, 10) % 11 === 0);
  8202. },
  8203. /**
  8204. * Validate Venezuelan VAT number (RIF)
  8205. * Examples:
  8206. * - Valid: VEJ309272292, VEV242818101, VEJ000126518, VEJ000458324, J309272292, V242818101, J000126518, J000458324
  8207. * - Invalid: VEJ309272293, VEV242818100, J000126519, J000458323
  8208. *
  8209. * @param {String} value VAT number
  8210. * @returns {Boolean}
  8211. */
  8212. _ve: function(value) {
  8213. if (/^VE[VEJPG][0-9]{9}$/.test(value)) {
  8214. value = value.substr(2);
  8215. }
  8216. if (!/^[VEJPG][0-9]{9}$/.test(value)) {
  8217. return false;
  8218. }
  8219. var types = {
  8220. 'V': 4,
  8221. 'E': 8,
  8222. 'J': 12,
  8223. 'P': 16,
  8224. 'G': 20
  8225. },
  8226. sum = types[value.charAt(0)],
  8227. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  8228. for (var i = 0; i < 8; i++) {
  8229. sum += parseInt(value.charAt(i + 1), 10) * weight[i];
  8230. }
  8231. sum = 11 - sum % 11;
  8232. if (sum === 11 || sum === 10) {
  8233. sum = 0;
  8234. }
  8235. return (sum + '' === value.substr(9, 1));
  8236. },
  8237. /**
  8238. * Validate South African VAT number
  8239. * Examples:
  8240. * - Valid: 4012345678
  8241. * - Invalid: 40123456789, 3012345678
  8242. *
  8243. * @params {String} value VAT number
  8244. * @returns {Boolean}
  8245. */
  8246. _za: function(value) {
  8247. if (/^ZA4[0-9]{9}$/.test(value)) {
  8248. value = value.substr(2);
  8249. }
  8250. return /^4[0-9]{9}$/.test(value);
  8251. }
  8252. };
  8253. }(jQuery));
  8254. ;(function($) {
  8255. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  8256. 'en_US': {
  8257. vin: {
  8258. 'default': 'Please enter a valid VIN number'
  8259. }
  8260. }
  8261. });
  8262. FormValidation.Validator.vin = {
  8263. /**
  8264. * Validate an US VIN (Vehicle Identification Number)
  8265. *
  8266. * @param {FormValidation.Base} validator The validator plugin instance
  8267. * @param {jQuery} $field Field element
  8268. * @param {Object} options Consist of key:
  8269. * - message: The invalid message
  8270. * @returns {Boolean}
  8271. */
  8272. validate: function(validator, $field, options) {
  8273. var value = validator.getFieldValue($field, 'vin');
  8274. if (value === '') {
  8275. return true;
  8276. }
  8277. // Don't accept I, O, Q characters
  8278. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  8279. return false;
  8280. }
  8281. value = value.toUpperCase();
  8282. var chars = {
  8283. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  8284. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  8285. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  8286. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  8287. },
  8288. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  8289. sum = 0,
  8290. length = value.length;
  8291. for (var i = 0; i < length; i++) {
  8292. sum += chars[value.charAt(i) + ''] * weights[i];
  8293. }
  8294. var reminder = sum % 11;
  8295. if (reminder === 10) {
  8296. reminder = 'X';
  8297. }
  8298. return (reminder + '') === value.charAt(8);
  8299. }
  8300. };
  8301. }(jQuery));
  8302. ;(function($) {
  8303. FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
  8304. 'en_US': {
  8305. zipCode: {
  8306. 'default': 'Please enter a valid postal code',
  8307. country: 'Please enter a valid postal code in %s',
  8308. countries: {
  8309. AT: 'Austria',
  8310. BG: 'Bulgaria',
  8311. BR: 'Brazil',
  8312. CA: 'Canada',
  8313. CH: 'Switzerland',
  8314. CZ: 'Czech Republic',
  8315. DE: 'Germany',
  8316. DK: 'Denmark',
  8317. ES: 'Spain',
  8318. FR: 'France',
  8319. GB: 'United Kingdom',
  8320. IE: 'Ireland',
  8321. IN: 'India',
  8322. IT: 'Italy',
  8323. MA: 'Morocco',
  8324. NL: 'Netherlands',
  8325. PL: 'Poland',
  8326. PT: 'Portugal',
  8327. RO: 'Romania',
  8328. RU: 'Russia',
  8329. SE: 'Sweden',
  8330. SG: 'Singapore',
  8331. SK: 'Slovakia',
  8332. US: 'USA'
  8333. }
  8334. }
  8335. }
  8336. });
  8337. FormValidation.Validator.zipCode = {
  8338. html5Attributes: {
  8339. message: 'message',
  8340. country: 'country'
  8341. },
  8342. COUNTRY_CODES: ['AT', 'BG', 'BR', 'CA', 'CH', 'CZ', 'DE', 'DK', 'ES', 'FR', 'GB', 'IE', 'IN', 'IT', 'MA', 'NL', 'PL', 'PT', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
  8343. /**
  8344. * Return true if and only if the input value is a valid country zip code
  8345. *
  8346. * @param {FormValidation.Base} validator The validator plugin instance
  8347. * @param {jQuery} $field Field element
  8348. * @param {Object} options Consist of key:
  8349. * - message: The invalid message
  8350. * - country: The country
  8351. *
  8352. * The country can be defined by:
  8353. * - An ISO 3166 country code
  8354. * - Name of field which its value defines the country code
  8355. * - Name of callback function that returns the country code
  8356. * - A callback function that returns the country code
  8357. *
  8358. * callback: function(value, validator, $field) {
  8359. * // value is the value of field
  8360. * // validator is the BootstrapValidator instance
  8361. * // $field is jQuery element representing the field
  8362. * }
  8363. *
  8364. * @returns {Boolean|Object}
  8365. */
  8366. validate: function(validator, $field, options) {
  8367. var value = validator.getFieldValue($field, 'zipCode');
  8368. if (value === '' || !options.country) {
  8369. return true;
  8370. }
  8371. var locale = validator.getLocale(),
  8372. country = options.country;
  8373. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  8374. // Try to determine the country
  8375. country = validator.getDynamicOption($field, country);
  8376. }
  8377. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  8378. return true;
  8379. }
  8380. var isValid = false;
  8381. country = country.toUpperCase();
  8382. switch (country) {
  8383. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Austria
  8384. case 'AT':
  8385. isValid = /^([1-9]{1})(\d{3})$/.test(value);
  8386. break;
  8387. case 'BG':
  8388. isValid = /^([1-9]{1}[0-9]{3})$/.test($.trim(value));
  8389. break;
  8390. case 'BR':
  8391. isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
  8392. break;
  8393. case 'CA':
  8394. isValid = /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}[0-9]{1}$/i.test(value);
  8395. break;
  8396. case 'CH':
  8397. isValid = /^([1-9]{1})(\d{3})$/.test(value);
  8398. break;
  8399. case 'CZ':
  8400. // Test: http://regexr.com/39hhr
  8401. isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  8402. break;
  8403. // http://stackoverflow.com/questions/7926687/regular-expression-german-zip-codes
  8404. case 'DE':
  8405. isValid = /^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$/.test(value);
  8406. break;
  8407. case 'DK':
  8408. isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
  8409. break;
  8410. // Zip codes in Spain go from 01XXX to 52XXX.
  8411. // Test: http://refiddle.com/1ufo
  8412. case 'ES':
  8413. isValid = /^(?:0[1-9]|[1-4][0-9]|5[0-2])\d{3}$/.test(value);
  8414. break;
  8415. // http://en.wikipedia.org/wiki/Postal_codes_in_France
  8416. case 'FR':
  8417. isValid = /^[0-9]{5}$/i.test(value);
  8418. break;
  8419. case 'GB':
  8420. isValid = this._gb(value);
  8421. break;
  8422. // Indian PIN (Postal Index Number) validation
  8423. // http://en.wikipedia.org/wiki/Postal_Index_Number
  8424. // Test: http://regex101.com/r/kV0vH3/1
  8425. case 'IN':
  8426. isValid = /^\d{3}\s?\d{3}$/.test(value);
  8427. break;
  8428. // http://www.eircode.ie/docs/default-source/Common/prepare-your-business-for-eircode---published-v2.pdf?sfvrsn=2
  8429. // Test: http://refiddle.com/1kpl
  8430. case 'IE':
  8431. isValid = /^(D6W|[ACDEFHKNPRTVWXY]\d{2})\s[0-9ACDEFHKNPRTVWXY]{4}$/.test(value);
  8432. break;
  8433. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  8434. case 'IT':
  8435. isValid = /^(I-|IT-)?\d{5}$/i.test(value);
  8436. break;
  8437. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
  8438. case 'MA':
  8439. isValid = /^[1-9][0-9]{4}$/i.test(value);
  8440. break;
  8441. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  8442. case 'NL':
  8443. isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  8444. break;
  8445. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Poland
  8446. case 'PL':
  8447. isValid = /^[0-9]{2}\-[0-9]{3}$/.test(value);
  8448. break;
  8449. // Test: http://refiddle.com/1l2t
  8450. case 'PT':
  8451. isValid = /^[1-9]\d{3}-\d{3}$/.test(value);
  8452. break;
  8453. case 'RO':
  8454. isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
  8455. break;
  8456. case 'RU':
  8457. isValid = /^[0-9]{6}$/i.test(value);
  8458. break;
  8459. case 'SE':
  8460. isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  8461. break;
  8462. case 'SG':
  8463. isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  8464. break;
  8465. case 'SK':
  8466. // Test: http://regexr.com/39hhr
  8467. isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  8468. break;
  8469. case 'US':
  8470. /* falls through */
  8471. default:
  8472. isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
  8473. break;
  8474. }
  8475. return {
  8476. valid: isValid,
  8477. message: FormValidation.Helper.format(options.message || FormValidation.I18n[locale].zipCode.country, FormValidation.I18n[locale].zipCode.countries[country])
  8478. };
  8479. },
  8480. /**
  8481. * Validate United Kingdom postcode
  8482. * Examples:
  8483. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  8484. * - Special cases:
  8485. * AI-2640, ASCN 1ZZ, GIR 0AA
  8486. *
  8487. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  8488. * @param {String} value The postcode
  8489. * @returns {Boolean}
  8490. */
  8491. _gb: function(value) {
  8492. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  8493. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  8494. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  8495. fourthChar = '[ABEHMNPRVWXY]',
  8496. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  8497. regexps = [
  8498. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  8499. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  8500. // ANA NAA
  8501. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  8502. // AANA NAA
  8503. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  8504. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  8505. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  8506. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  8507. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  8508. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  8509. /^(AI-2640)$/i // Anguilla
  8510. ];
  8511. for (var i = 0; i < regexps.length; i++) {
  8512. if (regexps[i].test(value)) {
  8513. return true;
  8514. }
  8515. }
  8516. return false;
  8517. }
  8518. };
  8519. }(jQuery));