bootstrapValidator.js 313 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089
  1. /*!
  2. * BootstrapValidator (http://bootstrapvalidator.com)
  3. * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  4. *
  5. <<<<<<< HEAD
  6. <<<<<<< HEAD
  7. <<<<<<< HEAD
  8. <<<<<<< HEAD
  9. <<<<<<< HEAD
  10. <<<<<<< HEAD
  11. <<<<<<< HEAD
  12. * @version v0.5.3-dev, built on 2014-10-06 8:02:42 AM
  13. =======
  14. * @version v0.5.2-dev, built on 2014-09-18 9:55:01 PM
  15. >>>>>>> Add built files for the rgbColor and keywordColor commits
  16. =======
  17. * @version v0.5.2-dev, built on 2014-09-18 9:55:14 PM
  18. >>>>>>> Add validator and test suite for rgba() color validation
  19. =======
  20. * @version v0.5.2-dev, built on 2014-09-18 9:55:28 PM
  21. >>>>>>> Add validator and test suite for hsl() color validation
  22. =======
  23. * @version v0.5.2-dev, built on 2014-09-18 9:57:05 PM
  24. >>>>>>> Add built files for the rgbColor and keywordColor commits
  25. =======
  26. * @version v0.5.2-dev, built on 2014-09-18 9:57:12 PM
  27. >>>>>>> Add validator and test suite for rgba() color validation
  28. =======
  29. * @version v0.5.2-dev, built on 2014-09-18 9:57:19 PM
  30. >>>>>>> Add validator and test suite for hsl() color validation
  31. =======
  32. * @version v0.5.2-dev, built on 2014-09-18 9:57:27 PM
  33. >>>>>>> Fix bug in form names for test suites for rgb, rgba and hsl
  34. * @author https://twitter.com/nghuuphuoc
  35. * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
  36. * @license MIT
  37. */
  38. if (typeof jQuery === 'undefined') {
  39. throw new Error('BootstrapValidator\'s JavaScript requires jQuery');
  40. }
  41. (function($) {
  42. var BootstrapValidator = function(form, options) {
  43. this.$form = $(form);
  44. this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options);
  45. this.$invalidFields = $([]); // Array of invalid fields
  46. this.$submitButton = null; // The submit button which is clicked to submit form
  47. this.$hiddenButton = null;
  48. // Validating status
  49. this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
  50. this.STATUS_VALIDATING = 'VALIDATING';
  51. this.STATUS_INVALID = 'INVALID';
  52. this.STATUS_VALID = 'VALID';
  53. // Determine the event that is fired when user change the field value
  54. // Most modern browsers supports input event except IE 7, 8.
  55. // IE 9 supports input event but the event is still not fired if I press the backspace key.
  56. // Get IE version
  57. // https://gist.github.com/padolsey/527683/#comment-7595
  58. var ieVersion = (function() {
  59. var v = 3, div = document.createElement('div'), a = div.all || [];
  60. while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]) {}
  61. return v > 4 ? v : !v;
  62. }());
  63. var el = document.createElement('div');
  64. this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';
  65. // The flag to indicate that the form is ready to submit when a remote/callback validator returns
  66. this._submitIfValid = null;
  67. // Field elements
  68. this._cacheFields = {};
  69. this._init();
  70. };
  71. BootstrapValidator.prototype = {
  72. constructor: BootstrapValidator,
  73. /**
  74. * Init form
  75. */
  76. _init: function() {
  77. var that = this,
  78. options = {
  79. container: this.$form.attr('data-bv-container'),
  80. events: {
  81. formInit: this.$form.attr('data-bv-events-form-init'),
  82. formError: this.$form.attr('data-bv-events-form-error'),
  83. formSuccess: this.$form.attr('data-bv-events-form-success'),
  84. fieldAdded: this.$form.attr('data-bv-events-field-added'),
  85. fieldRemoved: this.$form.attr('data-bv-events-field-removed'),
  86. fieldInit: this.$form.attr('data-bv-events-field-init'),
  87. fieldError: this.$form.attr('data-bv-events-field-error'),
  88. fieldSuccess: this.$form.attr('data-bv-events-field-success'),
  89. fieldStatus: this.$form.attr('data-bv-events-field-status'),
  90. validatorError: this.$form.attr('data-bv-events-validator-error'),
  91. validatorSuccess: this.$form.attr('data-bv-events-validator-success')
  92. },
  93. excluded: this.$form.attr('data-bv-excluded'),
  94. feedbackIcons: {
  95. valid: this.$form.attr('data-bv-feedbackicons-valid'),
  96. invalid: this.$form.attr('data-bv-feedbackicons-invalid'),
  97. validating: this.$form.attr('data-bv-feedbackicons-validating')
  98. },
  99. group: this.$form.attr('data-bv-group'),
  100. live: this.$form.attr('data-bv-live'),
  101. message: this.$form.attr('data-bv-message'),
  102. onError: this.$form.attr('data-bv-onerror'),
  103. onSuccess: this.$form.attr('data-bv-onsuccess'),
  104. submitButtons: this.$form.attr('data-bv-submitbuttons'),
  105. threshold: this.$form.attr('data-bv-threshold'),
  106. trigger: this.$form.attr('data-bv-trigger'),
  107. verbose: this.$form.attr('data-bv-verbose'),
  108. fields: {}
  109. };
  110. this.$form
  111. // Disable client side validation in HTML 5
  112. .attr('novalidate', 'novalidate')
  113. .addClass(this.options.elementClass)
  114. // Disable the default submission first
  115. .on('submit.bv', function(e) {
  116. e.preventDefault();
  117. that.validate();
  118. })
  119. .on('click.bv', this.options.submitButtons, function() {
  120. that.$submitButton = $(this);
  121. // The user just click the submit button
  122. that._submitIfValid = true;
  123. })
  124. // Find all fields which have either "name" or "data-bv-field" attribute
  125. .find('[name], [data-bv-field]')
  126. .each(function() {
  127. var $field = $(this),
  128. field = $field.attr('name') || $field.attr('data-bv-field'),
  129. opts = that._parseOptions($field);
  130. if (opts) {
  131. $field.attr('data-bv-field', field);
  132. options.fields[field] = $.extend({}, opts, options.fields[field]);
  133. }
  134. });
  135. this.options = $.extend(true, this.options, options);
  136. // When pressing Enter on any field in the form, the first submit button will do its job.
  137. // The form then will be submitted.
  138. // I create a first hidden submit button
  139. this.$hiddenButton = $('<button/>')
  140. .attr('type', 'submit')
  141. .prependTo(this.$form)
  142. .addClass('bv-hidden-submit')
  143. .css({ display: 'none', width: 0, height: 0 });
  144. this.$form
  145. .on('click.bv', '[type="submit"]', function(e) {
  146. // #746: Check if the button click handler returns false
  147. if (!e.isDefaultPrevented()) {
  148. var $target = $(e.target),
  149. // The button might contain HTML tag
  150. $button = $target.is('[type="submit"]') ? $target.eq(0) : $target.parent('[type="submit"]').eq(0);
  151. // Don't perform validation when clicking on the submit button/input
  152. // which aren't defined by the 'submitButtons' option
  153. if (that.options.submitButtons && !$button.is(that.options.submitButtons) && !$button.is(that.$hiddenButton)) {
  154. that.$form.off('submit.bv').submit();
  155. }
  156. }
  157. });
  158. for (var field in this.options.fields) {
  159. this._initField(field);
  160. }
  161. this.$form.trigger($.Event(this.options.events.formInit), {
  162. bv: this,
  163. options: this.options
  164. });
  165. // Prepare the events
  166. if (this.options.onSuccess) {
  167. this.$form.on(this.options.events.formSuccess, function(e) {
  168. $.fn.bootstrapValidator.helpers.call(that.options.onSuccess, [e]);
  169. });
  170. }
  171. if (this.options.onError) {
  172. this.$form.on(this.options.events.formError, function(e) {
  173. $.fn.bootstrapValidator.helpers.call(that.options.onError, [e]);
  174. });
  175. }
  176. },
  177. /**
  178. * Parse the validator options from HTML attributes
  179. *
  180. * @param {jQuery} $field The field element
  181. * @returns {Object}
  182. */
  183. _parseOptions: function($field) {
  184. var field = $field.attr('name') || $field.attr('data-bv-field'),
  185. validators = {},
  186. validator,
  187. v, // Validator name
  188. enabled,
  189. optionName,
  190. optionValue,
  191. html5AttrName,
  192. html5AttrMap;
  193. for (v in $.fn.bootstrapValidator.validators) {
  194. validator = $.fn.bootstrapValidator.validators[v];
  195. enabled = $field.attr('data-bv-' + v.toLowerCase()) + '';
  196. html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
  197. if ((html5AttrMap && enabled !== 'false')
  198. || (html5AttrMap !== true && ('' === enabled || 'true' === enabled)))
  199. {
  200. // Try to parse the options via attributes
  201. validator.html5Attributes = $.extend({}, { message: 'message', onerror: 'onError', onsuccess: 'onSuccess' }, validator.html5Attributes);
  202. validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]);
  203. for (html5AttrName in validator.html5Attributes) {
  204. optionName = validator.html5Attributes[html5AttrName];
  205. optionValue = $field.attr('data-bv-' + v.toLowerCase() + '-' + html5AttrName);
  206. if (optionValue) {
  207. if ('true' === optionValue) {
  208. optionValue = true;
  209. } else if ('false' === optionValue) {
  210. optionValue = false;
  211. }
  212. validators[v][optionName] = optionValue;
  213. }
  214. }
  215. }
  216. }
  217. var opts = {
  218. container: $field.attr('data-bv-container'),
  219. excluded: $field.attr('data-bv-excluded'),
  220. feedbackIcons: $field.attr('data-bv-feedbackicons'),
  221. group: $field.attr('data-bv-group'),
  222. message: $field.attr('data-bv-message'),
  223. onError: $field.attr('data-bv-onerror'),
  224. onStatus: $field.attr('data-bv-onstatus'),
  225. onSuccess: $field.attr('data-bv-onsuccess'),
  226. selector: $field.attr('data-bv-selector'),
  227. threshold: $field.attr('data-bv-threshold'),
  228. trigger: $field.attr('data-bv-trigger'),
  229. verbose: $field.attr('data-bv-verbose'),
  230. validators: validators
  231. },
  232. emptyOptions = $.isEmptyObject(opts), // Check if the field options are set using HTML attributes
  233. emptyValidators = $.isEmptyObject(validators); // Check if the field validators are set using HTML attributes
  234. if (!emptyValidators || (!emptyOptions && this.options.fields && this.options.fields[field])) {
  235. opts.validators = validators;
  236. return opts;
  237. } else {
  238. return null;
  239. }
  240. },
  241. /**
  242. * Init field
  243. *
  244. * @param {String|jQuery} field The field name or field element
  245. */
  246. _initField: function(field) {
  247. var fields = $([]);
  248. switch (typeof field) {
  249. case 'object':
  250. fields = field;
  251. field = field.attr('data-bv-field');
  252. break;
  253. case 'string':
  254. fields = this.getFieldElements(field);
  255. fields.attr('data-bv-field', field);
  256. break;
  257. default:
  258. break;
  259. }
  260. // We don't need to validate non-existing fields
  261. if (fields.length === 0) {
  262. return;
  263. }
  264. if (this.options.fields[field] === null || this.options.fields[field].validators === null) {
  265. return;
  266. }
  267. var validatorName;
  268. for (validatorName in this.options.fields[field].validators) {
  269. if (!$.fn.bootstrapValidator.validators[validatorName]) {
  270. delete this.options.fields[field].validators[validatorName];
  271. }
  272. }
  273. if (this.options.fields[field].enabled === null) {
  274. this.options.fields[field].enabled = true;
  275. }
  276. var that = this,
  277. total = fields.length,
  278. type = fields.attr('type'),
  279. updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
  280. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent,
  281. trigger = (this.options.fields[field].trigger || this.options.trigger || event).split(' '),
  282. events = $.map(trigger, function(item) {
  283. return item + '.update.bv';
  284. }).join(' ');
  285. for (var i = 0; i < total; i++) {
  286. var $field = fields.eq(i),
  287. group = this.options.fields[field].group || this.options.group,
  288. $parent = $field.parents(group),
  289. // Allow user to indicate where the error messages are shown
  290. container = ('function' === typeof (this.options.fields[field].container || this.options.container)) ? (this.options.fields[field].container || this.options.container).call(this, $field, this) : (this.options.fields[field].container || this.options.container),
  291. $message = (container && container !== 'tooltip' && container !== 'popover') ? $(container) : this._getMessageContainer($field, group);
  292. if (container && container !== 'tooltip' && container !== 'popover') {
  293. $message.addClass('has-error');
  294. }
  295. // Remove all error messages and feedback icons
  296. $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove();
  297. $parent.find('i[data-bv-icon-for="' + field + '"]').remove();
  298. // Whenever the user change the field value, mark it as not validated yet
  299. $field.off(events).on(events, function() {
  300. that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
  301. });
  302. // Create help block elements for showing the error messages
  303. $field.data('bv.messages', $message);
  304. for (validatorName in this.options.fields[field].validators) {
  305. $field.data('bv.result.' + validatorName, this.STATUS_NOT_VALIDATED);
  306. if (!updateAll || i === total - 1) {
  307. $('<small/>')
  308. .css('display', 'none')
  309. .addClass('help-block')
  310. .attr('data-bv-validator', validatorName)
  311. .attr('data-bv-for', field)
  312. .attr('data-bv-result', this.STATUS_NOT_VALIDATED)
  313. .html(this._getMessage(field, validatorName))
  314. .appendTo($message);
  315. }
  316. // Init the validator
  317. if ('function' === typeof $.fn.bootstrapValidator.validators[validatorName].init) {
  318. $.fn.bootstrapValidator.validators[validatorName].init(this, $field, this.options.fields[field].validators[validatorName]);
  319. }
  320. }
  321. // Prepare the feedback icons
  322. // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
  323. if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
  324. && this.options.feedbackIcons
  325. && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
  326. && (!updateAll || i === total - 1))
  327. {
  328. // $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
  329. // Keep error messages which are populated from back-end
  330. $parent.addClass('has-feedback');
  331. var $icon = $('<i/>')
  332. .css('display', 'none')
  333. .addClass('form-control-feedback')
  334. .attr('data-bv-icon-for', field)
  335. .insertAfter($field);
  336. // Place it after the container of checkbox/radio
  337. // so when clicking the icon, it doesn't effect to the checkbox/radio element
  338. if ('checkbox' === type || 'radio' === type) {
  339. var $fieldParent = $field.parent();
  340. if ($fieldParent.hasClass(type)) {
  341. $icon.insertAfter($fieldParent);
  342. } else if ($fieldParent.parent().hasClass(type)) {
  343. $icon.insertAfter($fieldParent.parent());
  344. }
  345. }
  346. // The feedback icon does not render correctly if there is no label
  347. // https://github.com/twbs/bootstrap/issues/12873
  348. if ($parent.find('label').length === 0) {
  349. $icon.addClass('bv-no-label');
  350. }
  351. // Fix feedback icons in input-group
  352. if ($parent.find('.input-group').length !== 0) {
  353. $icon.addClass('bv-icon-input-group')
  354. .insertAfter($parent.find('.input-group').eq(0));
  355. }
  356. if (container) {
  357. $field
  358. // Show tooltip/popover message when field gets focus
  359. .off('focus.bv')
  360. .on('focus.bv', function() {
  361. switch (container) {
  362. case 'tooltip':
  363. $icon.tooltip('show');
  364. break;
  365. case 'popover':
  366. $icon.popover('show');
  367. break;
  368. default:
  369. break;
  370. }
  371. })
  372. // and hide them when losing focus
  373. .off('blur.bv')
  374. .on('blur.bv', function() {
  375. switch (container) {
  376. case 'tooltip':
  377. $icon.tooltip('hide');
  378. break;
  379. case 'popover':
  380. $icon.popover('hide');
  381. break;
  382. default:
  383. break;
  384. }
  385. });
  386. }
  387. }
  388. }
  389. // Prepare the events
  390. fields
  391. .on(this.options.events.fieldSuccess, function(e, data) {
  392. var onSuccess = that.getOptions(data.field, null, 'onSuccess');
  393. if (onSuccess) {
  394. $.fn.bootstrapValidator.helpers.call(onSuccess, [e, data]);
  395. }
  396. })
  397. .on(this.options.events.fieldError, function(e, data) {
  398. var onError = that.getOptions(data.field, null, 'onError');
  399. if (onError) {
  400. $.fn.bootstrapValidator.helpers.call(onError, [e, data]);
  401. }
  402. })
  403. .on(this.options.events.fieldStatus, function(e, data) {
  404. var onStatus = that.getOptions(data.field, null, 'onStatus');
  405. if (onStatus) {
  406. $.fn.bootstrapValidator.helpers.call(onStatus, [e, data]);
  407. }
  408. })
  409. .on(this.options.events.validatorError, function(e, data) {
  410. var onError = that.getOptions(data.field, data.validator, 'onError');
  411. if (onError) {
  412. $.fn.bootstrapValidator.helpers.call(onError, [e, data]);
  413. }
  414. })
  415. .on(this.options.events.validatorSuccess, function(e, data) {
  416. var onSuccess = that.getOptions(data.field, data.validator, 'onSuccess');
  417. if (onSuccess) {
  418. $.fn.bootstrapValidator.helpers.call(onSuccess, [e, data]);
  419. }
  420. });
  421. // Set live mode
  422. events = $.map(trigger, function(item) {
  423. return item + '.live.bv';
  424. }).join(' ');
  425. switch (this.options.live) {
  426. case 'submitted':
  427. break;
  428. case 'disabled':
  429. fields.off(events);
  430. break;
  431. case 'enabled':
  432. /* falls through */
  433. default:
  434. fields.off(events).on(events, function() {
  435. if (that._exceedThreshold($(this))) {
  436. that.validateField($(this));
  437. }
  438. });
  439. break;
  440. }
  441. fields.trigger($.Event(this.options.events.fieldInit), {
  442. bv: this,
  443. field: field,
  444. element: fields
  445. });
  446. },
  447. /**
  448. * Get the error message for given field and validator
  449. *
  450. * @param {String} field The field name
  451. * @param {String} validatorName The validator name
  452. * @returns {String}
  453. */
  454. _getMessage: function(field, validatorName) {
  455. if (!this.options.fields[field] || !$.fn.bootstrapValidator.validators[validatorName]
  456. || !this.options.fields[field].validators || !this.options.fields[field].validators[validatorName])
  457. {
  458. return '';
  459. }
  460. var options = this.options.fields[field].validators[validatorName];
  461. switch (true) {
  462. case (!!options.message):
  463. return options.message;
  464. case (!!this.options.fields[field].message):
  465. return this.options.fields[field].message;
  466. case (!!$.fn.bootstrapValidator.i18n[validatorName]):
  467. return $.fn.bootstrapValidator.i18n[validatorName]['default'];
  468. default:
  469. return this.options.message;
  470. }
  471. },
  472. /**
  473. * Get the element to place the error messages
  474. *
  475. * @param {jQuery} $field The field element
  476. * @param {String} group
  477. * @returns {jQuery}
  478. */
  479. _getMessageContainer: function($field, group) {
  480. var $parent = $field.parent();
  481. if ($parent.is(group)) {
  482. return $parent;
  483. }
  484. var cssClasses = $parent.attr('class');
  485. if (!cssClasses) {
  486. return this._getMessageContainer($parent, group);
  487. }
  488. cssClasses = cssClasses.split(' ');
  489. var n = cssClasses.length;
  490. for (var i = 0; i < n; i++) {
  491. if (/^col-(xs|sm|md|lg)-\d+$/.test(cssClasses[i]) || /^col-(xs|sm|md|lg)-offset-\d+$/.test(cssClasses[i])) {
  492. return $parent;
  493. }
  494. }
  495. return this._getMessageContainer($parent, group);
  496. },
  497. /**
  498. * Called when all validations are completed
  499. */
  500. _submit: function() {
  501. var isValid = this.isValid(),
  502. eventType = isValid ? this.options.events.formSuccess : this.options.events.formError,
  503. e = $.Event(eventType);
  504. this.$form.trigger(e);
  505. // Call default handler
  506. // Check if whether the submit button is clicked
  507. if (this.$submitButton) {
  508. isValid ? this._onSuccess(e) : this._onError(e);
  509. }
  510. },
  511. /**
  512. * Check if the field is excluded.
  513. * Returning true means that the field will not be validated
  514. *
  515. * @param {jQuery} $field The field element
  516. * @returns {Boolean}
  517. */
  518. _isExcluded: function($field) {
  519. var excludedAttr = $field.attr('data-bv-excluded'),
  520. // I still need to check the 'name' attribute while initializing the field
  521. field = $field.attr('data-bv-field') || $field.attr('name');
  522. switch (true) {
  523. case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'true' || this.options.fields[field].excluded === true)):
  524. case (excludedAttr === 'true'):
  525. case (excludedAttr === ''):
  526. return true;
  527. case (!!field && this.options.fields && this.options.fields[field] && (this.options.fields[field].excluded === 'false' || this.options.fields[field].excluded === false)):
  528. case (excludedAttr === 'false'):
  529. return false;
  530. default:
  531. if (this.options.excluded) {
  532. // Convert to array first
  533. if ('string' === typeof this.options.excluded) {
  534. this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
  535. // Trim the spaces
  536. return $.trim(item);
  537. });
  538. }
  539. var length = this.options.excluded.length;
  540. for (var i = 0; i < length; i++) {
  541. if (('string' === typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
  542. || ('function' === typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) === true))
  543. {
  544. return true;
  545. }
  546. }
  547. }
  548. return false;
  549. }
  550. },
  551. /**
  552. * Check if the number of characters of field value exceed the threshold or not
  553. *
  554. * @param {jQuery} $field The field element
  555. * @returns {Boolean}
  556. */
  557. _exceedThreshold: function($field) {
  558. var field = $field.attr('data-bv-field'),
  559. threshold = this.options.fields[field].threshold || this.options.threshold;
  560. if (!threshold) {
  561. return true;
  562. }
  563. var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
  564. return (cannotType || $field.val().length >= threshold);
  565. },
  566. // ---
  567. // Events
  568. // ---
  569. /**
  570. * The default handler of error.form.bv event.
  571. * It will be called when there is a invalid field
  572. *
  573. * @param {jQuery.Event} e The jQuery event object
  574. */
  575. _onError: function(e) {
  576. if (e.isDefaultPrevented()) {
  577. return;
  578. }
  579. if ('submitted' === this.options.live) {
  580. // Enable live mode
  581. this.options.live = 'enabled';
  582. var that = this;
  583. for (var field in this.options.fields) {
  584. (function(f) {
  585. var fields = that.getFieldElements(f);
  586. if (fields.length) {
  587. var type = $(fields[0]).attr('type'),
  588. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === $(fields[0]).get(0).tagName) ? 'change' : that._changeEvent,
  589. trigger = that.options.fields[field].trigger || that.options.trigger || event,
  590. events = $.map(trigger.split(' '), function(item) {
  591. return item + '.live.bv';
  592. }).join(' ');
  593. fields.off(events).on(events, function() {
  594. if (that._exceedThreshold($(this))) {
  595. that.validateField($(this));
  596. }
  597. });
  598. }
  599. })(field);
  600. }
  601. }
  602. var $invalidField = this.$invalidFields.eq(0);
  603. if ($invalidField) {
  604. // Activate the tab containing the invalid field if exists
  605. var $tabPane = $invalidField.parents('.tab-pane'), tabId;
  606. if ($tabPane && (tabId = $tabPane.attr('id'))) {
  607. $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
  608. }
  609. // Focus to the first invalid field
  610. $invalidField.focus();
  611. }
  612. },
  613. /**
  614. * The default handler of success.form.bv event.
  615. * It will be called when all the fields are valid
  616. *
  617. * @param {jQuery.Event} e The jQuery event object
  618. */
  619. _onSuccess: function(e) {
  620. if (e.isDefaultPrevented()) {
  621. return;
  622. }
  623. // Submit the form
  624. this.disableSubmitButtons(true).defaultSubmit();
  625. },
  626. /**
  627. * Called after validating a field element
  628. *
  629. * @param {jQuery} $field The field element
  630. * @param {String} [validatorName] The validator name
  631. */
  632. _onFieldValidated: function($field, validatorName) {
  633. var field = $field.attr('data-bv-field'),
  634. validators = this.options.fields[field].validators,
  635. counter = {},
  636. numValidators = 0,
  637. data = {
  638. bv: this,
  639. field: field,
  640. element: $field,
  641. validator: validatorName,
  642. result: $field.data('bv.response.' + validatorName)
  643. };
  644. // Trigger an event after given validator completes
  645. if (validatorName) {
  646. switch ($field.data('bv.result.' + validatorName)) {
  647. case this.STATUS_INVALID:
  648. $field.trigger($.Event(this.options.events.validatorError), data);
  649. break;
  650. case this.STATUS_VALID:
  651. $field.trigger($.Event(this.options.events.validatorSuccess), data);
  652. break;
  653. default:
  654. break;
  655. }
  656. }
  657. counter[this.STATUS_NOT_VALIDATED] = 0;
  658. counter[this.STATUS_VALIDATING] = 0;
  659. counter[this.STATUS_INVALID] = 0;
  660. counter[this.STATUS_VALID] = 0;
  661. for (var v in validators) {
  662. if (validators[v].enabled === false) {
  663. continue;
  664. }
  665. numValidators++;
  666. var result = $field.data('bv.result.' + v);
  667. if (result) {
  668. counter[result]++;
  669. }
  670. }
  671. if (counter[this.STATUS_VALID] === numValidators) {
  672. // Remove from the list of invalid fields
  673. this.$invalidFields = this.$invalidFields.not($field);
  674. $field.trigger($.Event(this.options.events.fieldSuccess), data);
  675. }
  676. // If all validators are completed and there is at least one validator which doesn't pass
  677. else if (counter[this.STATUS_NOT_VALIDATED] === 0 && counter[this.STATUS_VALIDATING] === 0 && counter[this.STATUS_INVALID] > 0) {
  678. // Add to the list of invalid fields
  679. this.$invalidFields = this.$invalidFields.add($field);
  680. $field.trigger($.Event(this.options.events.fieldError), data);
  681. }
  682. },
  683. // ---
  684. // Public methods
  685. // ---
  686. /**
  687. * Retrieve the field elements by given name
  688. *
  689. * @param {String} field The field name
  690. * @returns {null|jQuery[]}
  691. */
  692. getFieldElements: function(field) {
  693. if (!this._cacheFields[field]) {
  694. this._cacheFields[field] = (this.options.fields[field] && this.options.fields[field].selector)
  695. ? $(this.options.fields[field].selector)
  696. : this.$form.find('[name="' + field + '"]');
  697. }
  698. return this._cacheFields[field];
  699. },
  700. /**
  701. * Get the field options
  702. *
  703. * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
  704. * @param {String} [validator] The name of validator. It null, the method returns form options
  705. * @param {String} [option] The option name
  706. * @return {String|Object}
  707. */
  708. getOptions: function(field, validator, option) {
  709. if (!field) {
  710. return this.options;
  711. }
  712. if ('object' === typeof field) {
  713. field = field.attr('data-bv-field');
  714. }
  715. if (!this.options.fields[field]) {
  716. return null;
  717. }
  718. var options = this.options.fields[field];
  719. if (!validator) {
  720. return option ? options[option] : options;
  721. }
  722. if (!options.validators || !options.validators[validator]) {
  723. return null;
  724. }
  725. return option ? options.validators[validator][option] : options.validators[validator];
  726. },
  727. /**
  728. * Disable/enable submit buttons
  729. *
  730. * @param {Boolean} disabled Can be true or false
  731. * @returns {BootstrapValidator}
  732. */
  733. disableSubmitButtons: function(disabled) {
  734. if (!disabled) {
  735. this.$form.find(this.options.submitButtons).removeAttr('disabled');
  736. } else if (this.options.live !== 'disabled') {
  737. // Don't disable if the live validating mode is disabled
  738. this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
  739. }
  740. return this;
  741. },
  742. /**
  743. * Validate the form
  744. *
  745. * @returns {BootstrapValidator}
  746. */
  747. validate: function() {
  748. if (!this.options.fields) {
  749. return this;
  750. }
  751. this.disableSubmitButtons(true);
  752. for (var field in this.options.fields) {
  753. this.validateField(field);
  754. }
  755. this._submit();
  756. return this;
  757. },
  758. /**
  759. * Validate given field
  760. *
  761. * @param {String|jQuery} field The field name or field element
  762. * @returns {BootstrapValidator}
  763. */
  764. validateField: function(field) {
  765. var fields = $([]);
  766. switch (typeof field) {
  767. case 'object':
  768. fields = field;
  769. field = field.attr('data-bv-field');
  770. break;
  771. case 'string':
  772. fields = this.getFieldElements(field);
  773. break;
  774. default:
  775. break;
  776. }
  777. if (fields.length === 0 || (this.options.fields[field] && this.options.fields[field].enabled === false)) {
  778. return this;
  779. }
  780. var that = this,
  781. type = fields.attr('type'),
  782. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  783. updateAll = ('radio' === type || 'checkbox' === type),
  784. validators = this.options.fields[field].validators,
  785. verbose = this.options.fields[field].verbose === 'true' || this.options.fields[field].verbose === true || this.options.verbose === 'true' || this.options.verbose === true,
  786. validatorName,
  787. validateResult;
  788. for (var i = 0; i < total; i++) {
  789. var $field = fields.eq(i);
  790. if (this._isExcluded($field)) {
  791. continue;
  792. }
  793. var stop = false;
  794. for (validatorName in validators) {
  795. if ($field.data('bv.dfs.' + validatorName)) {
  796. $field.data('bv.dfs.' + validatorName).reject();
  797. }
  798. if (stop) {
  799. break;
  800. }
  801. // Don't validate field if it is already done
  802. var result = $field.data('bv.result.' + validatorName);
  803. if (result === this.STATUS_VALID || result === this.STATUS_INVALID) {
  804. this._onFieldValidated($field, validatorName);
  805. continue;
  806. } else if (validators[validatorName].enabled === false) {
  807. this.updateStatus(updateAll ? field : $field, this.STATUS_VALID, validatorName);
  808. continue;
  809. }
  810. $field.data('bv.result.' + validatorName, this.STATUS_VALIDATING);
  811. validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);
  812. // validateResult can be a $.Deferred object ...
  813. if ('object' === typeof validateResult && validateResult.resolve) {
  814. this.updateStatus(updateAll ? field : $field, this.STATUS_VALIDATING, validatorName);
  815. $field.data('bv.dfs.' + validatorName, validateResult);
  816. validateResult.done(function($f, v, response) {
  817. // v is validator name
  818. $f.removeData('bv.dfs.' + v).data('bv.response.' + v, response);
  819. if (response.message) {
  820. that.updateMessage($f, v, response.message);
  821. }
  822. that.updateStatus(updateAll ? $f.attr('data-bv-field') : $f, response.valid ? that.STATUS_VALID : that.STATUS_INVALID, v);
  823. if (response.valid && that._submitIfValid === true) {
  824. // If a remote validator returns true and the form is ready to submit, then do it
  825. that._submit();
  826. } else if (!response.valid && !verbose) {
  827. stop = true;
  828. }
  829. });
  830. }
  831. // ... or object { valid: true/false, message: 'dynamic message' }
  832. else if ('object' === typeof validateResult && validateResult.valid !== undefined && validateResult.message !== undefined) {
  833. $field.data('bv.response.' + validatorName, validateResult);
  834. this.updateMessage(updateAll ? field : $field, validatorName, validateResult.message);
  835. this.updateStatus(updateAll ? field : $field, validateResult.valid ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  836. if (!validateResult.valid && !verbose) {
  837. break;
  838. }
  839. }
  840. // ... or a boolean value
  841. else if ('boolean' === typeof validateResult) {
  842. $field.data('bv.response.' + validatorName, validateResult);
  843. this.updateStatus(updateAll ? field : $field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  844. if (!validateResult && !verbose) {
  845. break;
  846. }
  847. }
  848. }
  849. }
  850. return this;
  851. },
  852. /**
  853. * Update the error message
  854. *
  855. * @param {String|jQuery} field The field name or field element
  856. * @param {String} validator The validator name
  857. * @param {String} message The message
  858. * @returns {BootstrapValidator}
  859. */
  860. updateMessage: function(field, validator, message) {
  861. var $fields = $([]);
  862. switch (typeof field) {
  863. case 'object':
  864. $fields = field;
  865. field = field.attr('data-bv-field');
  866. break;
  867. case 'string':
  868. $fields = this.getFieldElements(field);
  869. break;
  870. default:
  871. break;
  872. }
  873. $fields.each(function() {
  874. $(this).data('bv.messages').find('.help-block[data-bv-validator="' + validator + '"][data-bv-for="' + field + '"]').html(message);
  875. });
  876. },
  877. /**
  878. * Update all validating results of field
  879. *
  880. * @param {String|jQuery} field The field name or field element
  881. * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  882. * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  883. * @returns {BootstrapValidator}
  884. */
  885. updateStatus: function(field, status, validatorName) {
  886. var fields = $([]);
  887. switch (typeof field) {
  888. case 'object':
  889. fields = field;
  890. field = field.attr('data-bv-field');
  891. break;
  892. case 'string':
  893. fields = this.getFieldElements(field);
  894. break;
  895. default:
  896. break;
  897. }
  898. if (status === this.STATUS_NOT_VALIDATED) {
  899. // Reset the flag
  900. this._submitIfValid = false;
  901. }
  902. var that = this,
  903. type = fields.attr('type'),
  904. group = this.options.fields[field].group || this.options.group,
  905. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  906. for (var i = 0; i < total; i++) {
  907. var $field = fields.eq(i);
  908. if (this._isExcluded($field)) {
  909. continue;
  910. }
  911. var $parent = $field.parents(group),
  912. $message = $field.data('bv.messages'),
  913. $allErrors = $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]'),
  914. $errors = validatorName ? $allErrors.filter('[data-bv-validator="' + validatorName + '"]') : $allErrors,
  915. $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + field + '"]'),
  916. container = ('function' === typeof (this.options.fields[field].container || this.options.container)) ? (this.options.fields[field].container || this.options.container).call(this, $field, this) : (this.options.fields[field].container || this.options.container),
  917. isValidField = null;
  918. // Update status
  919. if (validatorName) {
  920. $field.data('bv.result.' + validatorName, status);
  921. } else {
  922. for (var v in this.options.fields[field].validators) {
  923. $field.data('bv.result.' + v, status);
  924. }
  925. }
  926. // Show/hide error elements and feedback icons
  927. $errors.attr('data-bv-result', status);
  928. // Determine the tab containing the element
  929. var $tabPane = $field.parents('.tab-pane'),
  930. tabId, $tab;
  931. if ($tabPane && (tabId = $tabPane.attr('id'))) {
  932. $tab = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent();
  933. }
  934. switch (status) {
  935. case this.STATUS_VALIDATING:
  936. isValidField = null;
  937. this.disableSubmitButtons(true);
  938. $parent.removeClass('has-success').removeClass('has-error');
  939. if ($icon) {
  940. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();
  941. }
  942. if ($tab) {
  943. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
  944. }
  945. break;
  946. case this.STATUS_INVALID:
  947. isValidField = false;
  948. this.disableSubmitButtons(true);
  949. $parent.removeClass('has-success').addClass('has-error');
  950. if ($icon) {
  951. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
  952. }
  953. if ($tab) {
  954. $tab.removeClass('bv-tab-success').addClass('bv-tab-error');
  955. }
  956. break;
  957. case this.STATUS_VALID:
  958. // If the field is valid (passes all validators)
  959. isValidField = ($allErrors.filter('[data-bv-result="' + this.STATUS_NOT_VALIDATED +'"]').length === 0)
  960. ? ($allErrors.filter('[data-bv-result="' + this.STATUS_VALID +'"]').length === $allErrors.length) // All validators are completed
  961. : null; // There are some validators that have not done
  962. if (isValidField !== null) {
  963. this.disableSubmitButtons(this.$submitButton ? !this.isValid() : !isValidField);
  964. if ($icon) {
  965. $icon
  966. .removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).removeClass(this.options.feedbackIcons.valid)
  967. .addClass(isValidField ? this.options.feedbackIcons.valid : this.options.feedbackIcons.invalid)
  968. .show();
  969. }
  970. }
  971. $parent.removeClass('has-error has-success').addClass(this.isValidContainer($parent) ? 'has-success' : 'has-error');
  972. if ($tab) {
  973. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error').addClass(this.isValidContainer($tabPane) ? 'bv-tab-success' : 'bv-tab-error');
  974. }
  975. break;
  976. case this.STATUS_NOT_VALIDATED:
  977. /* falls through */
  978. default:
  979. isValidField = null;
  980. this.disableSubmitButtons(false);
  981. $parent.removeClass('has-success').removeClass('has-error');
  982. if ($icon) {
  983. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide();
  984. }
  985. if ($tab) {
  986. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
  987. }
  988. break;
  989. }
  990. switch (true) {
  991. // Only show the first error message if it is placed inside a tooltip ...
  992. case ($icon && 'tooltip' === container):
  993. (isValidField === false)
  994. ? $icon.css('cursor', 'pointer').tooltip('destroy').tooltip({
  995. container: 'body',
  996. html: true,
  997. placement: 'top',
  998. title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
  999. })
  1000. : $icon.tooltip('hide');
  1001. break;
  1002. // ... or popover
  1003. case ($icon && 'popover' === container):
  1004. (isValidField === false)
  1005. ? $icon.css('cursor', 'pointer').popover('destroy').popover({
  1006. container: 'body',
  1007. content: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html(),
  1008. html: true,
  1009. placement: 'top',
  1010. trigger: 'hover click'
  1011. })
  1012. : $icon.popover('hide');
  1013. break;
  1014. default:
  1015. (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
  1016. break;
  1017. }
  1018. // Trigger an event
  1019. $field.trigger($.Event(this.options.events.fieldStatus), {
  1020. bv: this,
  1021. field: field,
  1022. element: $field,
  1023. status: status
  1024. });
  1025. this._onFieldValidated($field, validatorName);
  1026. }
  1027. return this;
  1028. },
  1029. /**
  1030. * Check the form validity
  1031. *
  1032. * @returns {Boolean}
  1033. */
  1034. isValid: function() {
  1035. for (var field in this.options.fields) {
  1036. if (!this.isValidField(field)) {
  1037. return false;
  1038. }
  1039. }
  1040. return true;
  1041. },
  1042. /**
  1043. * Check if the field is valid or not
  1044. *
  1045. * @param {String|jQuery} field The field name or field element
  1046. * @returns {Boolean}
  1047. */
  1048. isValidField: function(field) {
  1049. var fields = $([]);
  1050. switch (typeof field) {
  1051. case 'object':
  1052. fields = field;
  1053. field = field.attr('data-bv-field');
  1054. break;
  1055. case 'string':
  1056. fields = this.getFieldElements(field);
  1057. break;
  1058. default:
  1059. break;
  1060. }
  1061. if (fields.length === 0 || this.options.fields[field] === null || this.options.fields[field].enabled === false) {
  1062. return true;
  1063. }
  1064. var type = fields.attr('type'),
  1065. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  1066. $field, validatorName, status;
  1067. for (var i = 0; i < total; i++) {
  1068. $field = fields.eq(i);
  1069. if (this._isExcluded($field)) {
  1070. continue;
  1071. }
  1072. for (validatorName in this.options.fields[field].validators) {
  1073. if (this.options.fields[field].validators[validatorName].enabled === false) {
  1074. continue;
  1075. }
  1076. status = $field.data('bv.result.' + validatorName);
  1077. if (status !== this.STATUS_VALID) {
  1078. return false;
  1079. }
  1080. }
  1081. }
  1082. return true;
  1083. },
  1084. /**
  1085. * Check if all fields inside a given container are valid.
  1086. * It's useful when working with a wizard-like such as tab, collapse
  1087. *
  1088. * @param {String|jQuery} container The container selector or element
  1089. * @returns {Boolean}
  1090. */
  1091. isValidContainer: function(container) {
  1092. var that = this,
  1093. map = {},
  1094. $container = ('string' === typeof container) ? $(container) : container;
  1095. if ($container.length === 0) {
  1096. return true;
  1097. }
  1098. $container.find('[data-bv-field]').each(function() {
  1099. var $field = $(this),
  1100. field = $field.attr('data-bv-field');
  1101. if (!that._isExcluded($field) && !map[field]) {
  1102. map[field] = $field;
  1103. }
  1104. });
  1105. for (var field in map) {
  1106. var $f = map[field];
  1107. if ($f.data('bv.messages')
  1108. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
  1109. .filter('[data-bv-result="' + this.STATUS_INVALID +'"]')
  1110. .length > 0)
  1111. {
  1112. return false;
  1113. }
  1114. }
  1115. return true;
  1116. },
  1117. /**
  1118. * Submit the form using default submission.
  1119. * It also does not perform any validations when submitting the form
  1120. */
  1121. defaultSubmit: function() {
  1122. if (this.$submitButton) {
  1123. // Create hidden input to send the submit buttons
  1124. $('<input/>')
  1125. .attr('type', 'hidden')
  1126. .attr('data-bv-submit-hidden', '')
  1127. .attr('name', this.$submitButton.attr('name'))
  1128. .val(this.$submitButton.val())
  1129. .appendTo(this.$form);
  1130. }
  1131. // Submit form
  1132. this.$form.off('submit.bv').submit();
  1133. },
  1134. // ---
  1135. // Useful APIs which aren't used internally
  1136. // ---
  1137. /**
  1138. * Get the list of invalid fields
  1139. *
  1140. * @returns {jQuery[]}
  1141. */
  1142. getInvalidFields: function() {
  1143. return this.$invalidFields;
  1144. },
  1145. /**
  1146. * Returns the clicked submit button
  1147. *
  1148. * @returns {jQuery}
  1149. */
  1150. getSubmitButton: function() {
  1151. return this.$submitButton;
  1152. },
  1153. /**
  1154. * Get the error messages
  1155. *
  1156. * @param {String|jQuery} [field] The field name or field element
  1157. * If the field is not defined, the method returns all error messages of all fields
  1158. * @param {String} [validator] The name of validator
  1159. * If the validator is not defined, the method returns error messages of all validators
  1160. * @returns {String[]}
  1161. */
  1162. getMessages: function(field, validator) {
  1163. var that = this,
  1164. messages = [],
  1165. $fields = $([]);
  1166. switch (true) {
  1167. case (field && 'object' === typeof field):
  1168. $fields = field;
  1169. break;
  1170. case (field && 'string' === typeof field):
  1171. var f = this.getFieldElements(field);
  1172. if (f.length > 0) {
  1173. var type = f.attr('type');
  1174. $fields = ('radio' === type || 'checkbox' === type) ? f.eq(0) : f;
  1175. }
  1176. break;
  1177. default:
  1178. $fields = this.$invalidFields;
  1179. break;
  1180. }
  1181. var filter = validator ? '[data-bv-validator="' + validator + '"]' : '';
  1182. $fields.each(function() {
  1183. messages = messages.concat(
  1184. $(this)
  1185. .data('bv.messages')
  1186. .find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]' + filter)
  1187. .map(function() {
  1188. var v = $(this).attr('data-bv-validator'),
  1189. f = $(this).attr('data-bv-for');
  1190. return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html();
  1191. })
  1192. .get()
  1193. );
  1194. });
  1195. return messages;
  1196. },
  1197. /**
  1198. * Update the option of a specific validator
  1199. *
  1200. * @param {String|jQuery} field The field name or field element
  1201. * @param {String} validator The validator name
  1202. * @param {String} option The option name
  1203. * @param {String} value The value to set
  1204. * @returns {BootstrapValidator}
  1205. */
  1206. updateOption: function(field, validator, option, value) {
  1207. if ('object' === typeof field) {
  1208. field = field.attr('data-bv-field');
  1209. }
  1210. if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
  1211. this.options.fields[field].validators[validator][option] = value;
  1212. this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
  1213. }
  1214. return this;
  1215. },
  1216. /**
  1217. * Add a new field
  1218. *
  1219. * @param {String|jQuery} field The field name or field element
  1220. * @param {Object} [options] The validator rules
  1221. * @returns {BootstrapValidator}
  1222. */
  1223. addField: function(field, options) {
  1224. var fields = $([]);
  1225. switch (typeof field) {
  1226. case 'object':
  1227. fields = field;
  1228. field = field.attr('data-bv-field') || field.attr('name');
  1229. break;
  1230. case 'string':
  1231. delete this._cacheFields[field];
  1232. fields = this.getFieldElements(field);
  1233. break;
  1234. default:
  1235. break;
  1236. }
  1237. fields.attr('data-bv-field', field);
  1238. var type = fields.attr('type'),
  1239. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1240. for (var i = 0; i < total; i++) {
  1241. var $field = fields.eq(i);
  1242. // Try to parse the options from HTML attributes
  1243. var opts = this._parseOptions($field);
  1244. opts = (opts === null) ? options : $.extend(true, options, opts);
  1245. this.options.fields[field] = $.extend(true, this.options.fields[field], opts);
  1246. // Update the cache
  1247. this._cacheFields[field] = this._cacheFields[field] ? this._cacheFields[field].add($field) : $field;
  1248. // Init the element
  1249. this._initField(('checkbox' === type || 'radio' === type) ? field : $field);
  1250. }
  1251. this.disableSubmitButtons(false);
  1252. // Trigger an event
  1253. this.$form.trigger($.Event(this.options.events.fieldAdded), {
  1254. field: field,
  1255. element: fields,
  1256. options: this.options.fields[field]
  1257. });
  1258. return this;
  1259. },
  1260. /**
  1261. * Remove a given field
  1262. *
  1263. * @param {String|jQuery} field The field name or field element
  1264. * @returns {BootstrapValidator}
  1265. */
  1266. removeField: function(field) {
  1267. var fields = $([]);
  1268. switch (typeof field) {
  1269. case 'object':
  1270. fields = field;
  1271. field = field.attr('data-bv-field') || field.attr('name');
  1272. fields.attr('data-bv-field', field);
  1273. break;
  1274. case 'string':
  1275. fields = this.getFieldElements(field);
  1276. break;
  1277. default:
  1278. break;
  1279. }
  1280. if (fields.length === 0) {
  1281. return this;
  1282. }
  1283. var type = fields.attr('type'),
  1284. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1285. for (var i = 0; i < total; i++) {
  1286. var $field = fields.eq(i);
  1287. // Remove from the list of invalid fields
  1288. this.$invalidFields = this.$invalidFields.not($field);
  1289. // Update the cache
  1290. this._cacheFields[field] = this._cacheFields[field].not($field);
  1291. }
  1292. if (!this._cacheFields[field] || this._cacheFields[field].length === 0) {
  1293. delete this.options.fields[field];
  1294. }
  1295. if ('checkbox' === type || 'radio' === type) {
  1296. this._initField(field);
  1297. }
  1298. this.disableSubmitButtons(false);
  1299. // Trigger an event
  1300. this.$form.trigger($.Event(this.options.events.fieldRemoved), {
  1301. field: field,
  1302. element: fields
  1303. });
  1304. return this;
  1305. },
  1306. /**
  1307. * Reset given field
  1308. *
  1309. * @param {String|jQuery} field The field name or field element
  1310. * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  1311. * @returns {BootstrapValidator}
  1312. */
  1313. resetField: function(field, resetValue) {
  1314. var $fields = $([]);
  1315. switch (typeof field) {
  1316. case 'object':
  1317. $fields = field;
  1318. field = field.attr('data-bv-field');
  1319. break;
  1320. case 'string':
  1321. $fields = this.getFieldElements(field);
  1322. break;
  1323. default:
  1324. break;
  1325. }
  1326. var total = $fields.length;
  1327. if (this.options.fields[field]) {
  1328. for (var i = 0; i < total; i++) {
  1329. for (var validator in this.options.fields[field].validators) {
  1330. $fields.eq(i).removeData('bv.dfs.' + validator);
  1331. }
  1332. }
  1333. }
  1334. // Mark field as not validated yet
  1335. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1336. if (resetValue) {
  1337. var type = $fields.attr('type');
  1338. ('radio' === type || 'checkbox' === type) ? $fields.removeAttr('checked').removeAttr('selected') : $fields.val('');
  1339. }
  1340. return this;
  1341. },
  1342. /**
  1343. * Reset the form
  1344. *
  1345. * @param {Boolean} [resetValue] If true, the method resets field value to empty or remove checked/selected attribute (for radio/checkbox)
  1346. * @returns {BootstrapValidator}
  1347. */
  1348. resetForm: function(resetValue) {
  1349. for (var field in this.options.fields) {
  1350. this.resetField(field, resetValue);
  1351. }
  1352. this.$invalidFields = $([]);
  1353. this.$submitButton = null;
  1354. // Enable submit buttons
  1355. this.disableSubmitButtons(false);
  1356. return this;
  1357. },
  1358. /**
  1359. * Revalidate given field
  1360. * It's used when you need to revalidate the field which its value is updated by other plugin
  1361. *
  1362. * @param {String|jQuery} field The field name of field element
  1363. * @returns {BootstrapValidator}
  1364. */
  1365. revalidateField: function(field) {
  1366. this.updateStatus(field, this.STATUS_NOT_VALIDATED)
  1367. .validateField(field);
  1368. return this;
  1369. },
  1370. /**
  1371. * Enable/Disable all validators to given field
  1372. *
  1373. * @param {String} field The field name
  1374. * @param {Boolean} enabled Enable/Disable field validators
  1375. * @param {String} [validatorName] The validator name. If null, all validators will be enabled/disabled
  1376. * @returns {BootstrapValidator}
  1377. */
  1378. enableFieldValidators: function(field, enabled, validatorName) {
  1379. var validators = this.options.fields[field].validators;
  1380. // Enable/disable particular validator
  1381. if (validatorName
  1382. && validators
  1383. && validators[validatorName] && validators[validatorName].enabled !== enabled)
  1384. {
  1385. this.options.fields[field].validators[validatorName].enabled = enabled;
  1386. this.updateStatus(field, this.STATUS_NOT_VALIDATED, validatorName);
  1387. }
  1388. // Enable/disable all validators
  1389. else if (!validatorName && this.options.fields[field].enabled !== enabled) {
  1390. this.options.fields[field].enabled = enabled;
  1391. for (var v in validators) {
  1392. this.enableFieldValidators(field, enabled, v);
  1393. }
  1394. }
  1395. return this;
  1396. },
  1397. /**
  1398. * Some validators have option which its value is dynamic.
  1399. * For example, the zipCode validator has the country option which might be changed dynamically by a select element.
  1400. *
  1401. * @param {jQuery|String} field The field name or element
  1402. * @param {String|Function} option The option which can be determined by:
  1403. * - a string
  1404. * - name of field which defines the value
  1405. * - name of function which returns the value
  1406. * - a function returns the value
  1407. *
  1408. * The callback function has the format of
  1409. * callback: function(value, validator, $field) {
  1410. * // value is the value of field
  1411. * // validator is the BootstrapValidator instance
  1412. * // $field is the field element
  1413. * }
  1414. *
  1415. * @returns {String}
  1416. */
  1417. getDynamicOption: function(field, option) {
  1418. var $field = ('string' === typeof field) ? this.getFieldElements(field) : field,
  1419. value = $field.val();
  1420. // Option can be determined by
  1421. // ... a function
  1422. if ('function' === typeof option) {
  1423. return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]);
  1424. }
  1425. // ... value of other field
  1426. else if ('string' === typeof option) {
  1427. var $f = this.getFieldElements(option);
  1428. if ($f.length) {
  1429. return $f.val();
  1430. }
  1431. // ... return value of callback
  1432. else {
  1433. return $.fn.bootstrapValidator.helpers.call(option, [value, this, $field]) || option;
  1434. }
  1435. }
  1436. return null;
  1437. },
  1438. /**
  1439. * Destroy the plugin
  1440. * It will remove all error messages, feedback icons and turn off the events
  1441. */
  1442. destroy: function() {
  1443. var field, fields, $field, validator, $icon, group;
  1444. for (field in this.options.fields) {
  1445. fields = this.getFieldElements(field);
  1446. group = this.options.fields[field].group || this.options.group;
  1447. for (var i = 0; i < fields.length; i++) {
  1448. $field = fields.eq(i);
  1449. $field
  1450. // Remove all error messages
  1451. .data('bv.messages')
  1452. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove().end()
  1453. .end()
  1454. .removeData('bv.messages')
  1455. // Remove feedback classes
  1456. .parents(group)
  1457. .removeClass('has-feedback has-error has-success')
  1458. .end()
  1459. // Turn off events
  1460. .off('.bv')
  1461. .removeAttr('data-bv-field');
  1462. // Remove feedback icons, tooltip/popover container
  1463. $icon = $field.parents(group).find('i[data-bv-icon-for="' + field + '"]');
  1464. if ($icon) {
  1465. var container = ('function' === typeof (this.options.fields[field].container || this.options.container)) ? (this.options.fields[field].container || this.options.container).call(this, $field, this) : (this.options.fields[field].container || this.options.container);
  1466. switch (container) {
  1467. case 'tooltip':
  1468. $icon.tooltip('destroy').remove();
  1469. break;
  1470. case 'popover':
  1471. $icon.popover('destroy').remove();
  1472. break;
  1473. default:
  1474. $icon.remove();
  1475. break;
  1476. }
  1477. }
  1478. for (validator in this.options.fields[field].validators) {
  1479. if ($field.data('bv.dfs.' + validator)) {
  1480. $field.data('bv.dfs.' + validator).reject();
  1481. }
  1482. $field.removeData('bv.result.' + validator)
  1483. .removeData('bv.response.' + validator)
  1484. .removeData('bv.dfs.' + validator);
  1485. // Destroy the validator
  1486. if ('function' === typeof $.fn.bootstrapValidator.validators[validator].destroy) {
  1487. $.fn.bootstrapValidator.validators[validator].destroy(this, $field, this.options.fields[field].validators[validator]);
  1488. }
  1489. }
  1490. }
  1491. }
  1492. this.disableSubmitButtons(false); // Enable submit buttons
  1493. this.$hiddenButton.remove(); // Remove the hidden button
  1494. this.$form
  1495. .removeClass(this.options.elementClass)
  1496. .off('.bv')
  1497. .removeData('bootstrapValidator')
  1498. // Remove generated hidden elements
  1499. .find('[data-bv-submit-hidden]').remove().end()
  1500. .find('[type="submit"]').off('click.bv');
  1501. }
  1502. };
  1503. // Plugin definition
  1504. $.fn.bootstrapValidator = function(option) {
  1505. var params = arguments;
  1506. return this.each(function() {
  1507. var $this = $(this),
  1508. data = $this.data('bootstrapValidator'),
  1509. options = 'object' === typeof option && option;
  1510. if (!data) {
  1511. data = new BootstrapValidator(this, options);
  1512. $this.data('bootstrapValidator', data);
  1513. }
  1514. // Allow to call plugin method
  1515. if ('string' === typeof option) {
  1516. data[option].apply(data, Array.prototype.slice.call(params, 1));
  1517. }
  1518. });
  1519. };
  1520. // The default options
  1521. $.fn.bootstrapValidator.DEFAULT_OPTIONS = {
  1522. // The form CSS class
  1523. elementClass: 'bv-form',
  1524. // Default invalid message
  1525. message: 'This value is not valid',
  1526. // The CSS selector for indicating the element consists the field
  1527. // By default, each field is placed inside the <div class="form-group"></div>
  1528. // You should adjust this option if your form group consists of many fields which not all of them need to be validated
  1529. group: '.form-group',
  1530. //The error messages container. It can be:
  1531. // - 'tooltip' if you want to use Bootstrap tooltip to show error messages
  1532. // - 'popover' if you want to use Bootstrap popover to show error messages
  1533. // - a CSS selector indicating the container
  1534. // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
  1535. // You also can define the message container for particular field
  1536. container: null,
  1537. // The field will not be live validated if its length is less than this number of characters
  1538. threshold: null,
  1539. // Indicate fields which won't be validated
  1540. // By default, the plugin will not validate the following kind of fields:
  1541. // - disabled
  1542. // - hidden
  1543. // - invisible
  1544. //
  1545. // The setting consists of jQuery filters. Accept 3 formats:
  1546. // - A string. Use a comma to separate filter
  1547. // - An array. Each element is a filter
  1548. // - An array. Each element can be a callback function
  1549. // function($field, validator) {
  1550. // $field is jQuery object representing the field element
  1551. // validator is the BootstrapValidator instance
  1552. // return true or false;
  1553. // }
  1554. //
  1555. // The 3 following settings are equivalent:
  1556. //
  1557. // 1) ':disabled, :hidden, :not(:visible)'
  1558. // 2) [':disabled', ':hidden', ':not(:visible)']
  1559. // 3) [':disabled', ':hidden', function($field) {
  1560. // return !$field.is(':visible');
  1561. // }]
  1562. excluded: [':disabled', ':hidden', ':not(:visible)'],
  1563. // Shows ok/error/loading icons based on the field validity.
  1564. // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
  1565. // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
  1566. // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
  1567. //
  1568. // Examples:
  1569. // - Use Glyphicons icons:
  1570. // feedbackIcons: {
  1571. // valid: 'glyphicon glyphicon-ok',
  1572. // invalid: 'glyphicon glyphicon-remove',
  1573. // validating: 'glyphicon glyphicon-refresh'
  1574. // }
  1575. // - Use FontAwesome icons:
  1576. // feedbackIcons: {
  1577. // valid: 'fa fa-check',
  1578. // invalid: 'fa fa-times',
  1579. // validating: 'fa fa-refresh'
  1580. // }
  1581. feedbackIcons: {
  1582. valid: null,
  1583. invalid: null,
  1584. validating: null
  1585. },
  1586. // The submit buttons selector
  1587. // These buttons will be disabled to prevent the valid form from multiple submissions
  1588. submitButtons: '[type="submit"]',
  1589. // Live validating option
  1590. // Can be one of 3 values:
  1591. // - enabled: The plugin validates fields as soon as they are changed
  1592. // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
  1593. // - submitted: The live validating is enabled after the form is submitted
  1594. live: 'enabled',
  1595. // Map the field name with validator rules
  1596. fields: null,
  1597. // Use custom event name to avoid window.onerror being invoked by jQuery
  1598. // See https://github.com/nghuuphuoc/bootstrapvalidator/issues/630
  1599. events: {
  1600. formInit: 'init.form.bv',
  1601. formError: 'error.form.bv',
  1602. formSuccess: 'success.form.bv',
  1603. fieldAdded: 'added.field.bv',
  1604. fieldRemoved: 'removed.field.bv',
  1605. fieldInit: 'init.field.bv',
  1606. fieldError: 'error.field.bv',
  1607. fieldSuccess: 'success.field.bv',
  1608. fieldStatus: 'status.field.bv',
  1609. validatorError: 'error.validator.bv',
  1610. validatorSuccess: 'success.validator.bv'
  1611. },
  1612. // Whether to be verbose when validating a field or not.
  1613. // Possible values:
  1614. // - true: when a field has multiple validators, all of them will be checked, and respectively - if errors occur in
  1615. // multiple validators, all of them will be displayed to the user
  1616. // - false: when a field has multiple validators, validation for this field will be terminated upon the first encountered error.
  1617. // Thus, only the very first error message related to this field will be displayed to the user
  1618. verbose: true
  1619. };
  1620. // Available validators
  1621. $.fn.bootstrapValidator.validators = {};
  1622. // i18n
  1623. $.fn.bootstrapValidator.i18n = {};
  1624. $.fn.bootstrapValidator.Constructor = BootstrapValidator;
  1625. // Helper methods, which can be used in validator class
  1626. $.fn.bootstrapValidator.helpers = {
  1627. /**
  1628. * Execute a callback function
  1629. *
  1630. * @param {String|Function} functionName Can be
  1631. * - name of global function
  1632. * - name of namespace function (such as A.B.C)
  1633. * - a function
  1634. * @param {Array} args The callback arguments
  1635. */
  1636. call: function(functionName, args) {
  1637. if ('function' === typeof functionName) {
  1638. return functionName.apply(this, args);
  1639. } else if ('string' === typeof functionName) {
  1640. if ('()' === functionName.substring(functionName.length - 2)) {
  1641. functionName = functionName.substring(0, functionName.length - 2);
  1642. }
  1643. var ns = functionName.split('.'),
  1644. func = ns.pop(),
  1645. context = window;
  1646. for (var i = 0; i < ns.length; i++) {
  1647. context = context[ns[i]];
  1648. }
  1649. return (typeof context[func] === 'undefined') ? null : context[func].apply(this, args);
  1650. }
  1651. },
  1652. /**
  1653. * Format a string
  1654. * It's used to format the error message
  1655. * format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
  1656. *
  1657. * @param {String} message
  1658. * @param {Array} parameters
  1659. * @returns {String}
  1660. */
  1661. format: function(message, parameters) {
  1662. if (!$.isArray(parameters)) {
  1663. parameters = [parameters];
  1664. }
  1665. for (var i in parameters) {
  1666. message = message.replace('%s', parameters[i]);
  1667. }
  1668. return message;
  1669. },
  1670. /**
  1671. * Validate a date
  1672. *
  1673. * @param {Number} year The full year in 4 digits
  1674. * @param {Number} month The month number
  1675. * @param {Number} day The day number
  1676. * @param {Boolean} [notInFuture] If true, the date must not be in the future
  1677. * @returns {Boolean}
  1678. */
  1679. date: function(year, month, day, notInFuture) {
  1680. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  1681. return false;
  1682. }
  1683. if (day.length > 2 || month.length > 2 || year.length > 4) {
  1684. return false;
  1685. }
  1686. day = parseInt(day, 10);
  1687. month = parseInt(month, 10);
  1688. year = parseInt(year, 10);
  1689. if (year < 1000 || year > 9999 || month <= 0 || month > 12) {
  1690. return false;
  1691. }
  1692. var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1693. // Update the number of days in Feb of leap year
  1694. if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
  1695. numDays[1] = 29;
  1696. }
  1697. // Check the day
  1698. if (day <= 0 || day > numDays[month - 1]) {
  1699. return false;
  1700. }
  1701. if (notInFuture === true) {
  1702. var currentDate = new Date(),
  1703. currentYear = currentDate.getFullYear(),
  1704. currentMonth = currentDate.getMonth(),
  1705. currentDay = currentDate.getDate();
  1706. return (year < currentYear
  1707. || (year === currentYear && month - 1 < currentMonth)
  1708. || (year === currentYear && month - 1 === currentMonth && day < currentDay));
  1709. }
  1710. return true;
  1711. },
  1712. /**
  1713. * Implement Luhn validation algorithm
  1714. * Credit to https://gist.github.com/ShirtlessKirk/2134376
  1715. *
  1716. * @see http://en.wikipedia.org/wiki/Luhn
  1717. * @param {String} value
  1718. * @returns {Boolean}
  1719. */
  1720. luhn: function(value) {
  1721. var length = value.length,
  1722. mul = 0,
  1723. prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
  1724. sum = 0;
  1725. while (length--) {
  1726. sum += prodArr[mul][parseInt(value.charAt(length), 10)];
  1727. mul ^= 1;
  1728. }
  1729. return (sum % 10 === 0 && sum > 0);
  1730. },
  1731. /**
  1732. * Implement modulus 11, 10 (ISO 7064) algorithm
  1733. *
  1734. * @param {String} value
  1735. * @returns {Boolean}
  1736. */
  1737. mod11And10: function(value) {
  1738. var check = 5,
  1739. length = value.length;
  1740. for (var i = 0; i < length; i++) {
  1741. check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
  1742. }
  1743. return (check === 1);
  1744. },
  1745. /**
  1746. * Implements Mod 37, 36 (ISO 7064) algorithm
  1747. * Usages:
  1748. * mod37And36('A12425GABC1234002M')
  1749. * mod37And36('002006673085', '0123456789')
  1750. *
  1751. * @param {String} value
  1752. * @param {String} [alphabet]
  1753. * @returns {Boolean}
  1754. */
  1755. mod37And36: function(value, alphabet) {
  1756. alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1757. var modulus = alphabet.length,
  1758. length = value.length,
  1759. check = Math.floor(modulus / 2);
  1760. for (var i = 0; i < length; i++) {
  1761. check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
  1762. }
  1763. return (check === 1);
  1764. }
  1765. };
  1766. }(window.jQuery));
  1767. ;(function($) {
  1768. $.fn.bootstrapValidator.i18n.base64 = $.extend($.fn.bootstrapValidator.i18n.base64 || {}, {
  1769. 'default': 'Please enter a valid base 64 encoded'
  1770. });
  1771. $.fn.bootstrapValidator.validators.base64 = {
  1772. /**
  1773. * Return true if the input value is a base 64 encoded string.
  1774. *
  1775. * @param {BootstrapValidator} validator The validator plugin instance
  1776. * @param {jQuery} $field Field element
  1777. * @param {Object} options Can consist of the following keys:
  1778. * - message: The invalid message
  1779. * @returns {Boolean}
  1780. */
  1781. validate: function(validator, $field, options) {
  1782. var value = $field.val();
  1783. if (value === '') {
  1784. return true;
  1785. }
  1786. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  1787. }
  1788. };
  1789. }(window.jQuery));
  1790. ;(function($) {
  1791. $.fn.bootstrapValidator.i18n.between = $.extend($.fn.bootstrapValidator.i18n.between || {}, {
  1792. 'default': 'Please enter a value between %s and %s',
  1793. notInclusive: 'Please enter a value between %s and %s strictly'
  1794. });
  1795. $.fn.bootstrapValidator.validators.between = {
  1796. html5Attributes: {
  1797. message: 'message',
  1798. min: 'min',
  1799. max: 'max',
  1800. inclusive: 'inclusive'
  1801. },
  1802. enableByHtml5: function($field) {
  1803. if ('range' === $field.attr('type')) {
  1804. return {
  1805. min: $field.attr('min'),
  1806. max: $field.attr('max')
  1807. };
  1808. }
  1809. return false;
  1810. },
  1811. /**
  1812. * Return true if the input value is between (strictly or not) two given numbers
  1813. *
  1814. * @param {BootstrapValidator} validator The validator plugin instance
  1815. * @param {jQuery} $field Field element
  1816. * @param {Object} options Can consist of the following keys:
  1817. * - min
  1818. * - max
  1819. *
  1820. * The min, max keys define the number which the field value compares to. min, max can be
  1821. * - A number
  1822. * - Name of field which its value defines the number
  1823. * - Name of callback function that returns the number
  1824. * - A callback function that returns the number
  1825. *
  1826. * - inclusive [optional]: Can be true or false. Default is true
  1827. * - message: The invalid message
  1828. * @returns {Boolean|Object}
  1829. */
  1830. validate: function(validator, $field, options) {
  1831. var value = $field.val();
  1832. if (value === '') {
  1833. return true;
  1834. }
  1835. if (!$.isNumeric(value)) {
  1836. return false;
  1837. }
  1838. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  1839. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max);
  1840. value = parseFloat(value);
  1841. return (options.inclusive === true || options.inclusive === undefined)
  1842. ? {
  1843. valid: value >= min && value <= max,
  1844. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between['default'], [min, max])
  1845. }
  1846. : {
  1847. valid: value > min && value < max,
  1848. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between.notInclusive, [min, max])
  1849. };
  1850. }
  1851. };
  1852. }(window.jQuery));
  1853. ;(function($) {
  1854. $.fn.bootstrapValidator.validators.blank = {
  1855. /**
  1856. * Placeholder validator that can be used to display a custom validation message
  1857. * returned from the server
  1858. * Example:
  1859. *
  1860. * (1) a "blank" validator is applied to an input field.
  1861. * (2) data is entered via the UI that is unable to be validated client-side.
  1862. * (3) server returns a 400 with JSON data that contains the field that failed
  1863. * validation and an associated message.
  1864. * (4) ajax 400 call handler does the following:
  1865. *
  1866. * bv.updateMessage(field, 'blank', errorMessage);
  1867. * bv.updateStatus(field, 'INVALID');
  1868. *
  1869. * @see https://github.com/nghuuphuoc/bootstrapvalidator/issues/542
  1870. * @see https://github.com/nghuuphuoc/bootstrapvalidator/pull/666
  1871. * @param {BootstrapValidator} validator The validator plugin instance
  1872. * @param {jQuery} $field Field element
  1873. * @param {Object} options Can consist of the following keys:
  1874. * - message: The invalid message
  1875. * @returns {Boolean}
  1876. */
  1877. validate: function(validator, $field, options) {
  1878. return true;
  1879. }
  1880. };
  1881. }(window.jQuery));
  1882. ;(function($) {
  1883. $.fn.bootstrapValidator.i18n.callback = $.extend($.fn.bootstrapValidator.i18n.callback || {}, {
  1884. 'default': 'Please enter a valid value'
  1885. });
  1886. $.fn.bootstrapValidator.validators.callback = {
  1887. html5Attributes: {
  1888. message: 'message',
  1889. callback: 'callback'
  1890. },
  1891. /**
  1892. * Return result from the callback method
  1893. *
  1894. * @param {BootstrapValidator} validator The validator plugin instance
  1895. * @param {jQuery} $field Field element
  1896. * @param {Object} options Can consist of the following keys:
  1897. * - callback: The callback method that passes 2 parameters:
  1898. * callback: function(fieldValue, validator, $field) {
  1899. * // fieldValue is the value of field
  1900. * // validator is instance of BootstrapValidator
  1901. * // $field is the field element
  1902. * }
  1903. * - message: The invalid message
  1904. * @returns {Deferred}
  1905. */
  1906. validate: function(validator, $field, options) {
  1907. var value = $field.val(),
  1908. dfd = new $.Deferred(),
  1909. result = { valid: true };
  1910. if (options.callback) {
  1911. var response = $.fn.bootstrapValidator.helpers.call(options.callback, [value, validator, $field]);
  1912. result = ('boolean' === typeof response) ? { valid: response } : response;
  1913. }
  1914. dfd.resolve($field, 'callback', result);
  1915. return dfd;
  1916. }
  1917. };
  1918. }(window.jQuery));
  1919. ;(function($) {
  1920. $.fn.bootstrapValidator.i18n.choice = $.extend($.fn.bootstrapValidator.i18n.choice || {}, {
  1921. 'default': 'Please enter a valid value',
  1922. less: 'Please choose %s options at minimum',
  1923. more: 'Please choose %s options at maximum',
  1924. between: 'Please choose %s - %s options'
  1925. });
  1926. $.fn.bootstrapValidator.validators.choice = {
  1927. html5Attributes: {
  1928. message: 'message',
  1929. min: 'min',
  1930. max: 'max'
  1931. },
  1932. /**
  1933. * Check if the number of checked boxes are less or more than a given number
  1934. *
  1935. * @param {BootstrapValidator} validator The validator plugin instance
  1936. * @param {jQuery} $field Field element
  1937. * @param {Object} options Consists of following keys:
  1938. * - min
  1939. * - max
  1940. *
  1941. * At least one of two keys is required
  1942. * The min, max keys define the number which the field value compares to. min, max can be
  1943. * - A number
  1944. * - Name of field which its value defines the number
  1945. * - Name of callback function that returns the number
  1946. * - A callback function that returns the number
  1947. *
  1948. * - message: The invalid message
  1949. * @returns {Object}
  1950. */
  1951. validate: function(validator, $field, options) {
  1952. var numChoices = $field.is('select')
  1953. ? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
  1954. : validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length,
  1955. min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
  1956. max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
  1957. isValid = true,
  1958. message = options.message || $.fn.bootstrapValidator.i18n.choice['default'];
  1959. if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
  1960. isValid = false;
  1961. }
  1962. switch (true) {
  1963. case (!!min && !!max):
  1964. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.between, [parseInt(min, 10), parseInt(max, 10)]);
  1965. break;
  1966. case (!!min):
  1967. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.less, parseInt(min, 10));
  1968. break;
  1969. case (!!max):
  1970. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.more, parseInt(max, 10));
  1971. break;
  1972. default:
  1973. break;
  1974. }
  1975. return { valid: isValid, message: message };
  1976. }
  1977. };
  1978. }(window.jQuery));
  1979. ;(function($) {
  1980. $.fn.bootstrapValidator.i18n.creditCard = $.extend($.fn.bootstrapValidator.i18n.creditCard || {}, {
  1981. 'default': 'Please enter a valid credit card number'
  1982. });
  1983. $.fn.bootstrapValidator.validators.creditCard = {
  1984. /**
  1985. * Return true if the input value is valid credit card number
  1986. * Based on https://gist.github.com/DiegoSalazar/4075533
  1987. *
  1988. * @param {BootstrapValidator} validator The validator plugin instance
  1989. * @param {jQuery} $field Field element
  1990. * @param {Object} [options] Can consist of the following key:
  1991. * - message: The invalid message
  1992. * @returns {Boolean}
  1993. */
  1994. validate: function(validator, $field, options) {
  1995. var value = $field.val();
  1996. if (value === '') {
  1997. return true;
  1998. }
  1999. // Accept only digits, dashes or spaces
  2000. if (/[^0-9-\s]+/.test(value)) {
  2001. return false;
  2002. }
  2003. value = value.replace(/\D/g, '');
  2004. if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
  2005. return false;
  2006. }
  2007. // Validate the card number based on prefix (IIN ranges) and length
  2008. var cards = {
  2009. AMERICAN_EXPRESS: {
  2010. length: [15],
  2011. prefix: ['34', '37']
  2012. },
  2013. DINERS_CLUB: {
  2014. length: [14],
  2015. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2016. },
  2017. DINERS_CLUB_US: {
  2018. length: [16],
  2019. prefix: ['54', '55']
  2020. },
  2021. DISCOVER: {
  2022. length: [16],
  2023. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2024. '62214', '62215', '62216', '62217', '62218', '62219',
  2025. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2026. '62290', '62291', '622920', '622921', '622922', '622923',
  2027. '622924', '622925', '644', '645', '646', '647', '648',
  2028. '649', '65']
  2029. },
  2030. JCB: {
  2031. length: [16],
  2032. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2033. },
  2034. LASER: {
  2035. length: [16, 17, 18, 19],
  2036. prefix: ['6304', '6706', '6771', '6709']
  2037. },
  2038. MAESTRO: {
  2039. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2040. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2041. },
  2042. MASTERCARD: {
  2043. length: [16],
  2044. prefix: ['51', '52', '53', '54', '55']
  2045. },
  2046. SOLO: {
  2047. length: [16, 18, 19],
  2048. prefix: ['6334', '6767']
  2049. },
  2050. UNIONPAY: {
  2051. length: [16, 17, 18, 19],
  2052. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2053. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2054. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2055. '622920', '622921', '622922', '622923', '622924', '622925']
  2056. },
  2057. VISA: {
  2058. length: [16],
  2059. prefix: ['4']
  2060. }
  2061. };
  2062. var type, i;
  2063. for (type in cards) {
  2064. for (i in cards[type].prefix) {
  2065. if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2066. && $.inArray(value.length, cards[type].length) !== -1) // and length
  2067. {
  2068. return true;
  2069. }
  2070. }
  2071. }
  2072. return false;
  2073. }
  2074. };
  2075. }(window.jQuery));
  2076. ;(function($) {
  2077. $.fn.bootstrapValidator.i18n.cusip = $.extend($.fn.bootstrapValidator.i18n.cusip || {}, {
  2078. 'default': 'Please enter a valid CUSIP number'
  2079. });
  2080. $.fn.bootstrapValidator.validators.cusip = {
  2081. /**
  2082. * Validate a CUSIP
  2083. * Examples:
  2084. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  2085. * - Invalid: 31430F200, 022615AC2
  2086. *
  2087. * @see http://en.wikipedia.org/wiki/CUSIP
  2088. * @param {BootstrapValidator} validator The validator plugin instance
  2089. * @param {jQuery} $field Field element
  2090. * @param {Object} [options] Can consist of the following keys:
  2091. * - message: The invalid message
  2092. * @returns {Boolean}
  2093. */
  2094. validate: function(validator, $field, options) {
  2095. var value = $field.val();
  2096. if (value === '') {
  2097. return true;
  2098. }
  2099. value = value.toUpperCase();
  2100. if (!/^[0-9A-Z]{9}$/.test(value)) {
  2101. return false;
  2102. }
  2103. var converted = $.map(value.split(''), function(item) {
  2104. var code = item.charCodeAt(0);
  2105. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2106. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2107. ? (code - 'A'.charCodeAt(0) + 10)
  2108. : item;
  2109. }),
  2110. length = converted.length,
  2111. sum = 0;
  2112. for (var i = 0; i < length - 1; i++) {
  2113. var num = parseInt(converted[i], 10);
  2114. if (i % 2 !== 0) {
  2115. num *= 2;
  2116. }
  2117. if (num > 9) {
  2118. num -= 9;
  2119. }
  2120. sum += num;
  2121. }
  2122. sum = (10 - (sum % 10)) % 10;
  2123. return sum === converted[length - 1];
  2124. }
  2125. };
  2126. }(window.jQuery));
  2127. ;(function($) {
  2128. $.fn.bootstrapValidator.i18n.cvv = $.extend($.fn.bootstrapValidator.i18n.cvv || {}, {
  2129. 'default': 'Please enter a valid CVV number'
  2130. });
  2131. $.fn.bootstrapValidator.validators.cvv = {
  2132. html5Attributes: {
  2133. message: 'message',
  2134. ccfield: 'creditCardField'
  2135. },
  2136. /**
  2137. * Return true if the input value is a valid CVV number.
  2138. *
  2139. * @param {BootstrapValidator} validator The validator plugin instance
  2140. * @param {jQuery} $field Field element
  2141. * @param {Object} options Can consist of the following keys:
  2142. * - creditCardField: The credit card number field. It can be null
  2143. * - message: The invalid message
  2144. * @returns {Boolean}
  2145. */
  2146. validate: function(validator, $field, options) {
  2147. var value = $field.val();
  2148. if (value === '') {
  2149. return true;
  2150. }
  2151. if (!/^[0-9]{3,4}$/.test(value)) {
  2152. return false;
  2153. }
  2154. if (!options.creditCardField) {
  2155. return true;
  2156. }
  2157. // Get the credit card number
  2158. var creditCard = validator.getFieldElements(options.creditCardField).val();
  2159. if (creditCard === '') {
  2160. return true;
  2161. }
  2162. creditCard = creditCard.replace(/\D/g, '');
  2163. // Supported credit card types
  2164. var cards = {
  2165. AMERICAN_EXPRESS: {
  2166. length: [15],
  2167. prefix: ['34', '37']
  2168. },
  2169. DINERS_CLUB: {
  2170. length: [14],
  2171. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2172. },
  2173. DINERS_CLUB_US: {
  2174. length: [16],
  2175. prefix: ['54', '55']
  2176. },
  2177. DISCOVER: {
  2178. length: [16],
  2179. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2180. '62214', '62215', '62216', '62217', '62218', '62219',
  2181. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2182. '62290', '62291', '622920', '622921', '622922', '622923',
  2183. '622924', '622925', '644', '645', '646', '647', '648',
  2184. '649', '65']
  2185. },
  2186. JCB: {
  2187. length: [16],
  2188. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2189. },
  2190. LASER: {
  2191. length: [16, 17, 18, 19],
  2192. prefix: ['6304', '6706', '6771', '6709']
  2193. },
  2194. MAESTRO: {
  2195. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2196. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2197. },
  2198. MASTERCARD: {
  2199. length: [16],
  2200. prefix: ['51', '52', '53', '54', '55']
  2201. },
  2202. SOLO: {
  2203. length: [16, 18, 19],
  2204. prefix: ['6334', '6767']
  2205. },
  2206. UNIONPAY: {
  2207. length: [16, 17, 18, 19],
  2208. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2209. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2210. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2211. '622920', '622921', '622922', '622923', '622924', '622925']
  2212. },
  2213. VISA: {
  2214. length: [16],
  2215. prefix: ['4']
  2216. }
  2217. };
  2218. var type, i, creditCardType = null;
  2219. for (type in cards) {
  2220. for (i in cards[type].prefix) {
  2221. if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2222. && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
  2223. {
  2224. creditCardType = type;
  2225. break;
  2226. }
  2227. }
  2228. }
  2229. return (creditCardType === null)
  2230. ? false
  2231. : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  2232. }
  2233. };
  2234. }(window.jQuery));
  2235. ;(function($) {
  2236. $.fn.bootstrapValidator.i18n.date = $.extend($.fn.bootstrapValidator.i18n.date || {}, {
  2237. 'default': 'Please enter a valid date',
  2238. min: 'Please enter a date after %s',
  2239. max: 'Please enter a date before %s',
  2240. range: 'Please enter a date in the range %s - %s'
  2241. });
  2242. $.fn.bootstrapValidator.validators.date = {
  2243. html5Attributes: {
  2244. message: 'message',
  2245. format: 'format',
  2246. min: 'min',
  2247. max: 'max',
  2248. separator: 'separator'
  2249. },
  2250. /**
  2251. * Return true if the input value is valid date
  2252. *
  2253. * @param {BootstrapValidator} validator The validator plugin instance
  2254. * @param {jQuery} $field Field element
  2255. * @param {Object} options Can consist of the following keys:
  2256. * - message: The invalid message
  2257. * - min: the minimum date
  2258. * - max: the maximum date
  2259. * - separator: Use to separate the date, month, and year.
  2260. * By default, it is /
  2261. * - format: The date format. Default is MM/DD/YYYY
  2262. * The format can be:
  2263. *
  2264. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2265. * ii) date and time:
  2266. * The time can consist of h, m, s parts which are separated by :
  2267. * ii) date, time and A (indicating AM or PM)
  2268. * @returns {Boolean|Object}
  2269. */
  2270. validate: function(validator, $field, options) {
  2271. var value = $field.val();
  2272. if (value === '') {
  2273. return true;
  2274. }
  2275. options.format = options.format || 'MM/DD/YYYY';
  2276. // #683: Force the format to YYYY-MM-DD as the default browser behaviour when using type="date" attribute
  2277. if ($field.attr('type') === 'date') {
  2278. options.format = 'YYYY-MM-DD';
  2279. }
  2280. var formats = options.format.split(' '),
  2281. dateFormat = formats[0],
  2282. timeFormat = (formats.length > 1) ? formats[1] : null,
  2283. amOrPm = (formats.length > 2) ? formats[2] : null,
  2284. sections = value.split(' '),
  2285. date = sections[0],
  2286. time = (sections.length > 1) ? sections[1] : null;
  2287. if (formats.length !== sections.length) {
  2288. return {
  2289. valid: false,
  2290. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2291. };
  2292. }
  2293. // Determine the separator
  2294. var separator = options.separator;
  2295. if (!separator) {
  2296. separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
  2297. }
  2298. if (separator === null || date.indexOf(separator) === -1) {
  2299. return {
  2300. valid: false,
  2301. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2302. };
  2303. }
  2304. // Determine the date
  2305. date = date.split(separator);
  2306. dateFormat = dateFormat.split(separator);
  2307. if (date.length !== dateFormat.length) {
  2308. return {
  2309. valid: false,
  2310. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2311. };
  2312. }
  2313. var year = date[$.inArray('YYYY', dateFormat)],
  2314. month = date[$.inArray('MM', dateFormat)],
  2315. day = date[$.inArray('DD', dateFormat)];
  2316. if (!year || !month || !day || year.length !== 4) {
  2317. return {
  2318. valid: false,
  2319. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2320. };
  2321. }
  2322. // Determine the time
  2323. var minutes = null, hours = null, seconds = null;
  2324. if (timeFormat) {
  2325. timeFormat = timeFormat.split(':');
  2326. time = time.split(':');
  2327. if (timeFormat.length !== time.length) {
  2328. return {
  2329. valid: false,
  2330. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2331. };
  2332. }
  2333. hours = time.length > 0 ? time[0] : null;
  2334. minutes = time.length > 1 ? time[1] : null;
  2335. seconds = time.length > 2 ? time[2] : null;
  2336. // Validate seconds
  2337. if (seconds) {
  2338. if (isNaN(seconds) || seconds.length > 2) {
  2339. return {
  2340. valid: false,
  2341. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2342. };
  2343. }
  2344. seconds = parseInt(seconds, 10);
  2345. if (seconds < 0 || seconds > 60) {
  2346. return {
  2347. valid: false,
  2348. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2349. };
  2350. }
  2351. }
  2352. // Validate hours
  2353. if (hours) {
  2354. if (isNaN(hours) || hours.length > 2) {
  2355. return {
  2356. valid: false,
  2357. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2358. };
  2359. }
  2360. hours = parseInt(hours, 10);
  2361. if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  2362. return {
  2363. valid: false,
  2364. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2365. };
  2366. }
  2367. }
  2368. // Validate minutes
  2369. if (minutes) {
  2370. if (isNaN(minutes) || minutes.length > 2) {
  2371. return {
  2372. valid: false,
  2373. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2374. };
  2375. }
  2376. minutes = parseInt(minutes, 10);
  2377. if (minutes < 0 || minutes > 59) {
  2378. return {
  2379. valid: false,
  2380. message: options.message || $.fn.bootstrapValidator.i18n.date['default']
  2381. };
  2382. }
  2383. }
  2384. }
  2385. // Validate day, month, and year
  2386. var valid = $.fn.bootstrapValidator.helpers.date(year, month, day),
  2387. message = options.message || $.fn.bootstrapValidator.i18n.date['default'];
  2388. // declare the date, min and max objects
  2389. var min = null,
  2390. max = null,
  2391. minOption = options.min,
  2392. maxOption = options.max;
  2393. if (minOption) {
  2394. if (isNaN(Date.parse(minOption))) {
  2395. minOption = validator.getDynamicOption($field, minOption);
  2396. }
  2397. min = this._parseDate(minOption, dateFormat, separator);
  2398. }
  2399. if (maxOption) {
  2400. if (isNaN(Date.parse(maxOption))) {
  2401. maxOption = validator.getDynamicOption($field, maxOption);
  2402. }
  2403. max = this._parseDate(maxOption, dateFormat, separator);
  2404. }
  2405. date = new Date(year, month, day, hours, minutes, seconds);
  2406. switch (true) {
  2407. case (minOption && !maxOption && valid):
  2408. valid = date.getTime() >= min.getTime();
  2409. message = options.message || $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.date.min, minOption);
  2410. break;
  2411. case (maxOption && !minOption && valid):
  2412. valid = date.getTime() <= max.getTime();
  2413. message = options.message || $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.date.max, maxOption);
  2414. break;
  2415. case (maxOption && minOption && valid):
  2416. valid = date.getTime() <= max.getTime() && date.getTime() >= min.getTime();
  2417. message = options.message || $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.date.range, [minOption, maxOption]);
  2418. break;
  2419. default:
  2420. break;
  2421. }
  2422. return {
  2423. valid: valid,
  2424. message: message
  2425. };
  2426. },
  2427. /**
  2428. * Return a date object after parsing the date string
  2429. *
  2430. * @param {String} date The date string to parse
  2431. * @param {String} format The date format
  2432. * The format can be:
  2433. * - date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2434. * - date and time:
  2435. * The time can consist of h, m, s parts which are separated by :
  2436. * @param {String} separator The separator used to separate the date, month, and year
  2437. * @returns {Date}
  2438. */
  2439. _parseDate: function(date, format, separator) {
  2440. var minutes = 0, hours = 0, seconds = 0,
  2441. sections = date.split(' '),
  2442. dateSection = sections[0],
  2443. timeSection = (sections.length > 1) ? sections[1] : null;
  2444. dateSection = dateSection.split(separator);
  2445. var year = dateSection[$.inArray('YYYY', format)],
  2446. month = dateSection[$.inArray('MM', format)],
  2447. day = dateSection[$.inArray('DD', format)];
  2448. if (timeSection) {
  2449. timeSection = timeSection.split(':');
  2450. hours = timeSection.length > 0 ? timeSection[0] : null;
  2451. minutes = timeSection.length > 1 ? timeSection[1] : null;
  2452. seconds = timeSection.length > 2 ? timeSection[2] : null;
  2453. }
  2454. return new Date(year, month, day, hours, minutes, seconds);
  2455. }
  2456. };
  2457. }(window.jQuery));
  2458. ;(function($) {
  2459. $.fn.bootstrapValidator.i18n.different = $.extend($.fn.bootstrapValidator.i18n.different || {}, {
  2460. 'default': 'Please enter a different value'
  2461. });
  2462. $.fn.bootstrapValidator.validators.different = {
  2463. html5Attributes: {
  2464. message: 'message',
  2465. field: 'field'
  2466. },
  2467. /**
  2468. * Return true if the input value is different with given field's value
  2469. *
  2470. * @param {BootstrapValidator} validator The validator plugin instance
  2471. * @param {jQuery} $field Field element
  2472. * @param {Object} options Consists of the following key:
  2473. * - field: The name of field that will be used to compare with current one
  2474. * - message: The invalid message
  2475. * @returns {Boolean}
  2476. */
  2477. validate: function(validator, $field, options) {
  2478. var value = $field.val();
  2479. if (value === '') {
  2480. return true;
  2481. }
  2482. var fields = options.field.split(','),
  2483. isValid = true;
  2484. for (var i = 0; i < fields.length; i++) {
  2485. var compareWith = validator.getFieldElements(fields[i]);
  2486. if (compareWith == null || compareWith.length === 0) {
  2487. continue;
  2488. }
  2489. var compareValue = compareWith.val();
  2490. if (value === compareValue) {
  2491. isValid = false;
  2492. } else if (compareValue !== '') {
  2493. validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
  2494. }
  2495. }
  2496. return isValid;
  2497. }
  2498. };
  2499. }(window.jQuery));
  2500. ;(function($) {
  2501. $.fn.bootstrapValidator.i18n.digits = $.extend($.fn.bootstrapValidator.i18n.digits || {}, {
  2502. 'default': 'Please enter only digits'
  2503. });
  2504. $.fn.bootstrapValidator.validators.digits = {
  2505. /**
  2506. * Return true if the input value contains digits only
  2507. *
  2508. * @param {BootstrapValidator} validator Validate plugin instance
  2509. * @param {jQuery} $field Field element
  2510. * @param {Object} [options]
  2511. * @returns {Boolean}
  2512. */
  2513. validate: function(validator, $field, options) {
  2514. var value = $field.val();
  2515. if (value === '') {
  2516. return true;
  2517. }
  2518. return /^\d+$/.test(value);
  2519. }
  2520. };
  2521. }(window.jQuery));
  2522. ;(function($) {
  2523. $.fn.bootstrapValidator.i18n.ean = $.extend($.fn.bootstrapValidator.i18n.ean || {}, {
  2524. 'default': 'Please enter a valid EAN number'
  2525. });
  2526. $.fn.bootstrapValidator.validators.ean = {
  2527. /**
  2528. * Validate EAN (International Article Number)
  2529. * Examples:
  2530. * - Valid: 73513537, 9780471117094, 4006381333931
  2531. * - Invalid: 73513536
  2532. *
  2533. * @see http://en.wikipedia.org/wiki/European_Article_Number
  2534. * @param {BootstrapValidator} 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. * @returns {Boolean}
  2539. */
  2540. validate: function(validator, $field, options) {
  2541. var value = $field.val();
  2542. if (value === '') {
  2543. return true;
  2544. }
  2545. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  2546. return false;
  2547. }
  2548. var length = value.length,
  2549. sum = 0,
  2550. weight = (length === 8) ? [3, 1] : [1, 3];
  2551. for (var i = 0; i < length - 1; i++) {
  2552. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  2553. }
  2554. sum = (10 - sum % 10) % 10;
  2555. return (sum + '' === value.charAt(length - 1));
  2556. }
  2557. };
  2558. }(window.jQuery));
  2559. ;(function($) {
  2560. $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
  2561. 'default': 'Please enter a valid email address'
  2562. });
  2563. $.fn.bootstrapValidator.validators.emailAddress = {
  2564. html5Attributes: {
  2565. message: 'message',
  2566. multiple: 'multiple',
  2567. separator: 'separator'
  2568. },
  2569. enableByHtml5: function($field) {
  2570. return ('email' === $field.attr('type'));
  2571. },
  2572. /**
  2573. * Return true if and only if the input value is a valid email address
  2574. *
  2575. * @param {BootstrapValidator} validator Validate plugin instance
  2576. * @param {jQuery} $field Field element
  2577. * @param {Object} [options]
  2578. * - multiple: Allow multiple email addresses, separated by a comma or semicolon; default is false.
  2579. * - separator: Regex for character or characters expected as separator between addresses; default is comma /[,;]/, i.e. comma or semicolon.
  2580. * @returns {Boolean}
  2581. */
  2582. validate: function(validator, $field, options) {
  2583. var value = $field.val();
  2584. if (value === '') {
  2585. return true;
  2586. }
  2587. // Email address regular expression
  2588. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  2589. 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])?)*$/,
  2590. allowMultiple = options.multiple === true || options.multiple === 'true';
  2591. if (allowMultiple) {
  2592. var separator = options.separator || /[,;]/,
  2593. addresses = this._splitEmailAddresses(value, separator);
  2594. for (var i = 0; i < addresses.length; i++) {
  2595. if (!emailRegExp.test(addresses[i])) {
  2596. return false;
  2597. }
  2598. }
  2599. return true;
  2600. } else {
  2601. return emailRegExp.test(value);
  2602. }
  2603. },
  2604. _splitEmailAddresses: function(emailAddresses, separator) {
  2605. var quotedFragments = emailAddresses.split(/"/),
  2606. quotedFragmentCount = quotedFragments.length,
  2607. emailAddressArray = [],
  2608. nextEmailAddress = '';
  2609. for (var i = 0; i < quotedFragmentCount; i++) {
  2610. if (i % 2 === 0) {
  2611. var splitEmailAddressFragments = quotedFragments[i].split(separator),
  2612. splitEmailAddressFragmentCount = splitEmailAddressFragments.length;
  2613. if (splitEmailAddressFragmentCount === 1) {
  2614. nextEmailAddress += splitEmailAddressFragments[0];
  2615. } else {
  2616. emailAddressArray.push(nextEmailAddress + splitEmailAddressFragments[0]);
  2617. for (var j = 1; j < splitEmailAddressFragmentCount - 1; j++) {
  2618. emailAddressArray.push(splitEmailAddressFragments[j]);
  2619. }
  2620. nextEmailAddress = splitEmailAddressFragments[splitEmailAddressFragmentCount - 1];
  2621. }
  2622. } else {
  2623. nextEmailAddress += '"' + quotedFragments[i];
  2624. if (i < quotedFragmentCount - 1) {
  2625. nextEmailAddress += '"';
  2626. }
  2627. }
  2628. }
  2629. emailAddressArray.push(nextEmailAddress);
  2630. return emailAddressArray;
  2631. }
  2632. };
  2633. }(window.jQuery));
  2634. ;(function($) {
  2635. $.fn.bootstrapValidator.i18n.file = $.extend($.fn.bootstrapValidator.i18n.file || {}, {
  2636. 'default': 'Please choose a valid file'
  2637. });
  2638. $.fn.bootstrapValidator.validators.file = {
  2639. html5Attributes: {
  2640. extension: 'extension',
  2641. maxsize: 'maxSize',
  2642. minsize: 'minSize',
  2643. message: 'message',
  2644. type: 'type'
  2645. },
  2646. /**
  2647. * Validate upload file. Use HTML 5 API if the browser supports
  2648. *
  2649. * @param {BootstrapValidator} validator The validator plugin instance
  2650. * @param {jQuery} $field Field element
  2651. * @param {Object} options Can consist of the following keys:
  2652. * - extension: The allowed extensions, separated by a comma
  2653. * - maxSize: The maximum size in bytes
  2654. * - minSize: the minimum size in bytes
  2655. * - message: The invalid message
  2656. * - type: The allowed MIME type, separated by a comma
  2657. * @returns {Boolean}
  2658. */
  2659. validate: function(validator, $field, options) {
  2660. var value = $field.val();
  2661. if (value === '') {
  2662. return true;
  2663. }
  2664. var ext,
  2665. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  2666. types = options.type ? options.type.toLowerCase().split(',') : null,
  2667. html5 = (window.File && window.FileList && window.FileReader);
  2668. if (html5) {
  2669. // Get FileList instance
  2670. var files = $field.get(0).files,
  2671. total = files.length;
  2672. for (var i = 0; i < total; i++) {
  2673. // Check the minSize
  2674. if (options.minSize && files[i].size < parseInt(options.minSize, 10)) {
  2675. return false;
  2676. }
  2677. // Check the maxSize
  2678. if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
  2679. return false;
  2680. }
  2681. // Check file extension
  2682. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  2683. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2684. return false;
  2685. }
  2686. // Check file type
  2687. if (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
  2688. return false;
  2689. }
  2690. }
  2691. } else {
  2692. // Check file extension
  2693. ext = value.substr(value.lastIndexOf('.') + 1);
  2694. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2695. return false;
  2696. }
  2697. }
  2698. return true;
  2699. }
  2700. };
  2701. }(window.jQuery));
  2702. ;(function($) {
  2703. $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
  2704. 'default': 'Please enter a value greater than or equal to %s',
  2705. notInclusive: 'Please enter a value greater than %s'
  2706. });
  2707. $.fn.bootstrapValidator.validators.greaterThan = {
  2708. html5Attributes: {
  2709. message: 'message',
  2710. value: 'value',
  2711. inclusive: 'inclusive'
  2712. },
  2713. enableByHtml5: function($field) {
  2714. var type = $field.attr('type'),
  2715. min = $field.attr('min');
  2716. if (min && type !== 'date') {
  2717. return {
  2718. value: min
  2719. };
  2720. }
  2721. return false;
  2722. },
  2723. /**
  2724. * Return true if the input value is greater than or equals to given number
  2725. *
  2726. * @param {BootstrapValidator} validator Validate plugin instance
  2727. * @param {jQuery} $field Field element
  2728. * @param {Object} options Can consist of the following keys:
  2729. * - value: Define the number to compare with. It can be
  2730. * - A number
  2731. * - Name of field which its value defines the number
  2732. * - Name of callback function that returns the number
  2733. * - A callback function that returns the number
  2734. *
  2735. * - inclusive [optional]: Can be true or false. Default is true
  2736. * - message: The invalid message
  2737. * @returns {Boolean|Object}
  2738. */
  2739. validate: function(validator, $field, options) {
  2740. var value = $field.val();
  2741. if (value === '') {
  2742. return true;
  2743. }
  2744. if (!$.isNumeric(value)) {
  2745. return false;
  2746. }
  2747. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
  2748. value = parseFloat(value);
  2749. return (options.inclusive === true || options.inclusive === undefined)
  2750. ? {
  2751. valid: value >= compareTo,
  2752. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan['default'], compareTo)
  2753. }
  2754. : {
  2755. valid: value > compareTo,
  2756. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
  2757. };
  2758. }
  2759. };
  2760. }(window.jQuery));
  2761. ;(function($) {
  2762. $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
  2763. 'default': 'Please enter a valid GRId number'
  2764. });
  2765. $.fn.bootstrapValidator.validators.grid = {
  2766. /**
  2767. * Validate GRId (Global Release Identifier)
  2768. * Examples:
  2769. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  2770. * - Invalid: A1-2425G-ABC1234002-Q
  2771. *
  2772. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  2773. * @param {BootstrapValidator} validator The validator plugin instance
  2774. * @param {jQuery} $field Field element
  2775. * @param {Object} options Can consist of the following keys:
  2776. * - message: The invalid message
  2777. * @returns {Boolean}
  2778. */
  2779. validate: function(validator, $field, options) {
  2780. var value = $field.val();
  2781. if (value === '') {
  2782. return true;
  2783. }
  2784. value = value.toUpperCase();
  2785. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  2786. return false;
  2787. }
  2788. value = value.replace(/\s/g, '').replace(/-/g, '');
  2789. if ('GRID:' === value.substr(0, 5)) {
  2790. value = value.substr(5);
  2791. }
  2792. return $.fn.bootstrapValidator.helpers.mod37And36(value);
  2793. }
  2794. };
  2795. }(window.jQuery));
  2796. ;(function($) {
  2797. $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
  2798. 'default': 'Please enter a valid hexadecimal number'
  2799. });
  2800. $.fn.bootstrapValidator.validators.hex = {
  2801. /**
  2802. * Return true if and only if the input value is a valid hexadecimal number
  2803. *
  2804. * @param {BootstrapValidator} validator The validator plugin instance
  2805. * @param {jQuery} $field Field element
  2806. * @param {Object} options Consist of key:
  2807. * - message: The invalid message
  2808. * @returns {Boolean}
  2809. */
  2810. validate: function(validator, $field, options) {
  2811. var value = $field.val();
  2812. if (value === '') {
  2813. return true;
  2814. }
  2815. return /^[0-9a-fA-F]+$/.test(value);
  2816. }
  2817. };
  2818. }(window.jQuery));
  2819. ;(function($) {
  2820. $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
  2821. 'default': 'Please enter a valid hex color'
  2822. });
  2823. $.fn.bootstrapValidator.validators.hexColor = {
  2824. enableByHtml5: function($field) {
  2825. return ('color' === $field.attr('type'));
  2826. },
  2827. /**
  2828. * Return true if the input value is a valid hex color
  2829. *
  2830. * @param {BootstrapValidator} validator The validator plugin instance
  2831. * @param {jQuery} $field Field element
  2832. * @param {Object} options Can consist of the following keys:
  2833. * - message: The invalid message
  2834. * @returns {Boolean}
  2835. */
  2836. validate: function(validator, $field, options) {
  2837. var value = $field.val();
  2838. if (value === '') {
  2839. return true;
  2840. }
  2841. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2842. }
  2843. };
  2844. }(window.jQuery));
  2845. ;(function($) {
  2846. $.fn.bootstrapValidator.i18n.hslColor = $.extend($.fn.bootstrapValidator.i18n.hslColor || {}, {
  2847. 'default': 'Please enter a valid hsl color'
  2848. });
  2849. $.fn.bootstrapValidator.validators.hslColor = {
  2850. /**
  2851. * Return true if the input value is a valid hsl() color
  2852. *
  2853. * @param {BootstrapValidator} validator The validator plugin instance
  2854. * @param {jQuery} $field Field element
  2855. * @param {Object} options Can consist of the following keys:
  2856. * - message: The invalid message
  2857. * @returns {Boolean}
  2858. */
  2859. validate: function(validator, $field, options) {
  2860. var value = $field.val();
  2861. if (value === '') {
  2862. return true;
  2863. }
  2864. 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);
  2865. }
  2866. };
  2867. }(window.jQuery));
  2868. ;(function($) {
  2869. $.fn.bootstrapValidator.i18n.iban = $.extend($.fn.bootstrapValidator.i18n.iban || {}, {
  2870. 'default': 'Please enter a valid IBAN number',
  2871. countryNotSupported: 'The country code %s is not supported',
  2872. country: 'Please enter a valid IBAN number in %s',
  2873. countries: {
  2874. AD: 'Andorra',
  2875. AE: 'United Arab Emirates',
  2876. AL: 'Albania',
  2877. AO: 'Angola',
  2878. AT: 'Austria',
  2879. AZ: 'Azerbaijan',
  2880. BA: 'Bosnia and Herzegovina',
  2881. BE: 'Belgium',
  2882. BF: 'Burkina Faso',
  2883. BG: 'Bulgaria',
  2884. BH: 'Bahrain',
  2885. BI: 'Burundi',
  2886. BJ: 'Benin',
  2887. BR: 'Brazil',
  2888. CH: 'Switzerland',
  2889. CI: 'Ivory Coast',
  2890. CM: 'Cameroon',
  2891. CR: 'Costa Rica',
  2892. CV: 'Cape Verde',
  2893. CY: 'Cyprus',
  2894. CZ: 'Czech Republic',
  2895. DE: 'Germany',
  2896. DK: 'Denmark',
  2897. DO: 'Dominica',
  2898. DZ: 'Algeria',
  2899. EE: 'Estonia',
  2900. ES: 'Spain',
  2901. FI: 'Finland',
  2902. FO: 'Faroe Islands',
  2903. FR: 'France',
  2904. GB: 'United Kingdom',
  2905. GE: 'Georgia',
  2906. GI: 'Gibraltar',
  2907. GL: 'Greenland',
  2908. GR: 'Greece',
  2909. GT: 'Guatemala',
  2910. HR: 'Croatia',
  2911. HU: 'Hungary',
  2912. IE: 'Ireland',
  2913. IL: 'Israel',
  2914. IR: 'Iran',
  2915. IS: 'Iceland',
  2916. IT: 'Italy',
  2917. JO: 'Jordan',
  2918. KW: 'Kuwait',
  2919. KZ: 'Kazakhstan',
  2920. LB: 'Lebanon',
  2921. LI: 'Liechtenstein',
  2922. LT: 'Lithuania',
  2923. LU: 'Luxembourg',
  2924. LV: 'Latvia',
  2925. MC: 'Monaco',
  2926. MD: 'Moldova',
  2927. ME: 'Montenegro',
  2928. MG: 'Madagascar',
  2929. MK: 'Macedonia',
  2930. ML: 'Mali',
  2931. MR: 'Mauritania',
  2932. MT: 'Malta',
  2933. MU: 'Mauritius',
  2934. MZ: 'Mozambique',
  2935. NL: 'Netherlands',
  2936. NO: 'Norway',
  2937. PK: 'Pakistan',
  2938. PL: 'Poland',
  2939. PS: 'Palestine',
  2940. PT: 'Portugal',
  2941. QA: 'Qatar',
  2942. RO: 'Romania',
  2943. RS: 'Serbia',
  2944. SA: 'Saudi Arabia',
  2945. SE: 'Sweden',
  2946. SI: 'Slovenia',
  2947. SK: 'Slovakia',
  2948. SM: 'San Marino',
  2949. SN: 'Senegal',
  2950. TN: 'Tunisia',
  2951. TR: 'Turkey',
  2952. VG: 'Virgin Islands, British'
  2953. }
  2954. });
  2955. $.fn.bootstrapValidator.validators.iban = {
  2956. html5Attributes: {
  2957. message: 'message',
  2958. country: 'country'
  2959. },
  2960. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  2961. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  2962. REGEX: {
  2963. AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  2964. AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  2965. AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  2966. AO: 'AO[0-9]{2}[0-9]{21}', // Angola
  2967. AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  2968. AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  2969. BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  2970. BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  2971. BF: 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  2972. BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  2973. BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  2974. BI: 'BI[0-9]{2}[0-9]{12}', // Burundi
  2975. BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  2976. BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  2977. CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  2978. CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  2979. CM: 'CM[0-9]{2}[0-9]{23}', // Cameroon
  2980. CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  2981. CV: 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  2982. CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  2983. CZ: 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  2984. DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  2985. DK: 'DK[0-9]{2}[0-9]{14}', // Denmark
  2986. DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  2987. DZ: 'DZ[0-9]{2}[0-9]{20}', // Algeria
  2988. EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  2989. ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  2990. FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  2991. FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  2992. FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  2993. GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  2994. GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  2995. GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  2996. GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland
  2997. GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  2998. GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  2999. HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  3000. HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  3001. IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  3002. IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  3003. IR: 'IR[0-9]{2}[0-9]{22}', // Iran
  3004. IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  3005. IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  3006. JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  3007. KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  3008. KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  3009. LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  3010. LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  3011. LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  3012. LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  3013. LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  3014. MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  3015. MD: 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  3016. ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  3017. MG: 'MG[0-9]{2}[0-9]{23}', // Madagascar
  3018. MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  3019. ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  3020. MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  3021. MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  3022. MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}', // Mauritius
  3023. MZ: 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  3024. NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  3025. NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  3026. PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  3027. PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  3028. PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  3029. PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  3030. QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  3031. RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  3032. RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  3033. SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  3034. SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  3035. SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  3036. SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  3037. SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  3038. SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  3039. TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  3040. TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  3041. VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  3042. },
  3043. /**
  3044. * Validate an International Bank Account Number (IBAN)
  3045. * To test it, take the sample IBAN from
  3046. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  3047. *
  3048. * @param {BootstrapValidator} validator The validator plugin instance
  3049. * @param {jQuery} $field Field element
  3050. * @param {Object} options Can consist of the following keys:
  3051. * - message: The invalid message
  3052. * - country: The ISO 3166-1 country code. It can be
  3053. * - A country code
  3054. * - Name of field which its value defines the country code
  3055. * - Name of callback function that returns the country code
  3056. * - A callback function that returns the country code
  3057. * @returns {Boolean|Object}
  3058. */
  3059. validate: function(validator, $field, options) {
  3060. var value = $field.val();
  3061. if (value === '') {
  3062. return true;
  3063. }
  3064. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  3065. var country = options.country;
  3066. if (!country) {
  3067. country = value.substr(0, 2);
  3068. } else if (typeof country !== 'string' || !this.REGEX[country]) {
  3069. // Determine the country code
  3070. country = validator.getDynamicOption($field, country);
  3071. }
  3072. if (!this.REGEX[country]) {
  3073. return {
  3074. valid: false,
  3075. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.iban.countryNotSupported, country)
  3076. };
  3077. }
  3078. if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  3079. return {
  3080. valid: false,
  3081. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  3082. };
  3083. }
  3084. value = value.substr(4) + value.substr(0, 4);
  3085. value = $.map(value.split(''), function(n) {
  3086. var code = n.charCodeAt(0);
  3087. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  3088. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  3089. ? (code - 'A'.charCodeAt(0) + 10)
  3090. : n;
  3091. });
  3092. value = value.join('');
  3093. var temp = parseInt(value.substr(0, 1), 10),
  3094. length = value.length;
  3095. for (var i = 1; i < length; ++i) {
  3096. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  3097. }
  3098. return {
  3099. valid: (temp === 1),
  3100. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  3101. };
  3102. }
  3103. };
  3104. }(window.jQuery));
  3105. ;(function($) {
  3106. $.fn.bootstrapValidator.i18n.id = $.extend($.fn.bootstrapValidator.i18n.id || {}, {
  3107. 'default': 'Please enter a valid identification number',
  3108. countryNotSupported: 'The country code %s is not supported',
  3109. country: 'Please enter a valid identification number in %s',
  3110. countries: {
  3111. BA: 'Bosnia and Herzegovina',
  3112. BG: 'Bulgaria',
  3113. BR: 'Brazil',
  3114. CH: 'Switzerland',
  3115. CL: 'Chile',
  3116. CN: 'China',
  3117. CZ: 'Czech Republic',
  3118. DK: 'Denmark',
  3119. EE: 'Estonia',
  3120. ES: 'Spain',
  3121. FI: 'Finland',
  3122. HR: 'Croatia',
  3123. IE: 'Ireland',
  3124. IS: 'Iceland',
  3125. LT: 'Lithuania',
  3126. LV: 'Latvia',
  3127. ME: 'Montenegro',
  3128. MK: 'Macedonia',
  3129. NL: 'Netherlands',
  3130. RO: 'Romania',
  3131. RS: 'Serbia',
  3132. SE: 'Sweden',
  3133. SI: 'Slovenia',
  3134. SK: 'Slovakia',
  3135. SM: 'San Marino',
  3136. TH: 'Thailand',
  3137. ZA: 'South Africa'
  3138. }
  3139. });
  3140. $.fn.bootstrapValidator.validators.id = {
  3141. html5Attributes: {
  3142. message: 'message',
  3143. country: 'country'
  3144. },
  3145. // Supported country codes
  3146. COUNTRY_CODES: [
  3147. 'BA', 'BG', 'BR', 'CH', 'CL', 'CN', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
  3148. 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TH', 'ZA'
  3149. ],
  3150. /**
  3151. * Validate identification number in different countries
  3152. *
  3153. * @see http://en.wikipedia.org/wiki/National_identification_number
  3154. * @param {BootstrapValidator} validator The validator plugin instance
  3155. * @param {jQuery} $field Field element
  3156. * @param {Object} options Consist of key:
  3157. * - message: The invalid message
  3158. * - country: The ISO 3166-1 country code. It can be
  3159. * - One of country code defined in COUNTRY_CODES
  3160. * - Name of field which its value defines the country code
  3161. * - Name of callback function that returns the country code
  3162. * - A callback function that returns the country code
  3163. * @returns {Boolean|Object}
  3164. */
  3165. validate: function(validator, $field, options) {
  3166. var value = $field.val();
  3167. if (value === '') {
  3168. return true;
  3169. }
  3170. var country = options.country;
  3171. if (!country) {
  3172. country = value.substr(0, 2);
  3173. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  3174. // Determine the country code
  3175. country = validator.getDynamicOption($field, country);
  3176. }
  3177. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  3178. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.id.countryNotSupported, country) };
  3179. }
  3180. var method = ['_', country.toLowerCase()].join('');
  3181. return this[method](value)
  3182. ? true
  3183. : {
  3184. valid: false,
  3185. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.id.country, $.fn.bootstrapValidator.i18n.id.countries[country.toUpperCase()])
  3186. };
  3187. },
  3188. /**
  3189. * Validate Unique Master Citizen Number which uses in
  3190. * - Bosnia and Herzegovina (country code: BA)
  3191. * - Macedonia (MK)
  3192. * - Montenegro (ME)
  3193. * - Serbia (RS)
  3194. * - Slovenia (SI)
  3195. *
  3196. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  3197. * @param {String} value The ID
  3198. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  3199. * @returns {Boolean}
  3200. */
  3201. _validateJMBG: function(value, countryCode) {
  3202. if (!/^\d{13}$/.test(value)) {
  3203. return false;
  3204. }
  3205. var day = parseInt(value.substr(0, 2), 10),
  3206. month = parseInt(value.substr(2, 2), 10),
  3207. year = parseInt(value.substr(4, 3), 10),
  3208. rr = parseInt(value.substr(7, 2), 10),
  3209. k = parseInt(value.substr(12, 1), 10);
  3210. // Validate date of birth
  3211. // FIXME: Validate the year of birth
  3212. if (day > 31 || month > 12) {
  3213. return false;
  3214. }
  3215. // Validate checksum
  3216. var sum = 0;
  3217. for (var i = 0; i < 6; i++) {
  3218. sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  3219. }
  3220. sum = 11 - sum % 11;
  3221. if (sum === 10 || sum === 11) {
  3222. sum = 0;
  3223. }
  3224. if (sum !== k) {
  3225. return false;
  3226. }
  3227. // Validate political region
  3228. // rr is the political region of birth, which can be in ranges:
  3229. // 10-19: Bosnia and Herzegovina
  3230. // 20-29: Montenegro
  3231. // 30-39: Croatia (not used anymore)
  3232. // 41-49: Macedonia
  3233. // 50-59: Slovenia (only 50 is used)
  3234. // 70-79: Central Serbia
  3235. // 80-89: Serbian province of Vojvodina
  3236. // 90-99: Kosovo
  3237. switch (countryCode.toUpperCase()) {
  3238. case 'BA':
  3239. return (10 <= rr && rr <= 19);
  3240. case 'MK':
  3241. return (41 <= rr && rr <= 49);
  3242. case 'ME':
  3243. return (20 <= rr && rr <= 29);
  3244. case 'RS':
  3245. return (70 <= rr && rr <= 99);
  3246. case 'SI':
  3247. return (50 <= rr && rr <= 59);
  3248. default:
  3249. return true;
  3250. }
  3251. },
  3252. _ba: function(value) {
  3253. return this._validateJMBG(value, 'BA');
  3254. },
  3255. _mk: function(value) {
  3256. return this._validateJMBG(value, 'MK');
  3257. },
  3258. _me: function(value) {
  3259. return this._validateJMBG(value, 'ME');
  3260. },
  3261. _rs: function(value) {
  3262. return this._validateJMBG(value, 'RS');
  3263. },
  3264. /**
  3265. * Examples: 0101006500006
  3266. */
  3267. _si: function(value) {
  3268. return this._validateJMBG(value, 'SI');
  3269. },
  3270. /**
  3271. * Validate Bulgarian national identification number (EGN)
  3272. * Examples:
  3273. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  3274. * - Invalid: 8019010008
  3275. *
  3276. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  3277. * @param {String} value The ID
  3278. * @returns {Boolean}
  3279. */
  3280. _bg: function(value) {
  3281. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  3282. return false;
  3283. }
  3284. value = value.replace(/\s/g, '');
  3285. // Check the birth date
  3286. var year = parseInt(value.substr(0, 2), 10) + 1900,
  3287. month = parseInt(value.substr(2, 2), 10),
  3288. day = parseInt(value.substr(4, 2), 10);
  3289. if (month > 40) {
  3290. year += 100;
  3291. month -= 40;
  3292. } else if (month > 20) {
  3293. year -= 100;
  3294. month -= 20;
  3295. }
  3296. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3297. return false;
  3298. }
  3299. var sum = 0,
  3300. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  3301. for (var i = 0; i < 9; i++) {
  3302. sum += parseInt(value.charAt(i), 10) * weight[i];
  3303. }
  3304. sum = (sum % 11) % 10;
  3305. return (sum + '' === value.substr(9, 1));
  3306. },
  3307. /**
  3308. * Validate Brazilian national identification number (CPF)
  3309. * Examples:
  3310. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  3311. * - Invalid: 231.002.999-00
  3312. *
  3313. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  3314. * @param {String} value The ID
  3315. * @returns {Boolean}
  3316. */
  3317. _br: function(value) {
  3318. if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  3319. return false;
  3320. }
  3321. if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
  3322. return false;
  3323. }
  3324. value = value.replace(/\./g, '').replace(/-/g, '');
  3325. var d1 = 0;
  3326. for (var i = 0; i < 9; i++) {
  3327. d1 += (10 - i) * parseInt(value.charAt(i), 10);
  3328. }
  3329. d1 = 11 - d1 % 11;
  3330. if (d1 === 10 || d1 === 11) {
  3331. d1 = 0;
  3332. }
  3333. if (d1 + '' !== value.charAt(9)) {
  3334. return false;
  3335. }
  3336. var d2 = 0;
  3337. for (i = 0; i < 10; i++) {
  3338. d2 += (11 - i) * parseInt(value.charAt(i), 10);
  3339. }
  3340. d2 = 11 - d2 % 11;
  3341. if (d2 === 10 || d2 === 11) {
  3342. d2 = 0;
  3343. }
  3344. return (d2 + '' === value.charAt(10));
  3345. },
  3346. /**
  3347. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  3348. * Examples:
  3349. * - Valid: 756.1234.5678.95, 7561234567895
  3350. *
  3351. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  3352. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  3353. * @param {String} value The ID
  3354. * @returns {Boolean}
  3355. */
  3356. _ch: function(value) {
  3357. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  3358. return false;
  3359. }
  3360. value = value.replace(/\D/g, '').substr(3);
  3361. var length = value.length,
  3362. sum = 0,
  3363. weight = (length === 8) ? [3, 1] : [1, 3];
  3364. for (var i = 0; i < length - 1; i++) {
  3365. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3366. }
  3367. sum = 10 - sum % 10;
  3368. return (sum + '' === value.charAt(length - 1));
  3369. },
  3370. /**
  3371. * Validate Chilean national identification number (RUN/RUT)
  3372. * Examples:
  3373. * - Valid: 76086428-5, 22060449-7, 12531909-2
  3374. *
  3375. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  3376. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  3377. * @param {String} value The ID
  3378. * @returns {Boolean}
  3379. */
  3380. _cl: function(value) {
  3381. if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
  3382. return false;
  3383. }
  3384. value = value.replace(/\-/g, '');
  3385. while (value.length < 9) {
  3386. value = '0' + value;
  3387. }
  3388. var sum = 0,
  3389. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  3390. for (var i = 0; i < 8; i++) {
  3391. sum += parseInt(value.charAt(i), 10) * weight[i];
  3392. }
  3393. sum = 11 - sum % 11;
  3394. if (sum === 11) {
  3395. sum = 0;
  3396. } else if (sum === 10) {
  3397. sum = 'K';
  3398. }
  3399. return sum + '' === value.charAt(8).toUpperCase();
  3400. },
  3401. /**
  3402. * Validate Chinese citizen identification number
  3403. *
  3404. * Rules:
  3405. * - For current 18-digit system (since 1st Oct 1999, defined by GB11643—1999 national standard):
  3406. * - Digit 0-5: Must be a valid administrative division code of China PR.
  3407. * - Digit 6-13: Must be a valid YYYYMMDD date of birth. A future date is tolerated.
  3408. * - Digit 14-16: Order code, any integer.
  3409. * - Digit 17: An ISO 7064:1983, MOD 11-2 checksum.
  3410. * Both upper/lower case of X are tolerated.
  3411. * - For deprecated 15-digit system:
  3412. * - Digit 0-5: Must be a valid administrative division code of China PR.
  3413. * - Digit 6-11: Must be a valid YYMMDD date of birth, indicating the year of 19XX.
  3414. * - Digit 12-14: Order code, any integer.
  3415. * Lists of valid administrative division codes of China PR can be seen here:
  3416. * <http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/>
  3417. * Published and maintained by National Bureau of Statistics of China PR.
  3418. * NOTE: Current and deprecated codes MUST BOTH be considered valid.
  3419. * Many Chinese citizens born in once existed administrative divisions!
  3420. *
  3421. * @see http://en.wikipedia.org/wiki/Resident_Identity_Card#Identity_card_number
  3422. * @param {String} value The ID
  3423. * @returns {Boolean}
  3424. */
  3425. _cn: function(value) {
  3426. // Basic format check (18 or 15 digits, considering X in checksum)
  3427. value = value.trim();
  3428. if (!/^\d{15}$/.test(value) && !/^\d{17}[\dXx]{1}$/.test(value)) {
  3429. return false;
  3430. }
  3431. // Check China PR Administrative division code
  3432. var adminDivisionCodes = {
  3433. 11: {
  3434. 0: [0],
  3435. 1: [[0, 9], [11, 17]],
  3436. 2: [0, 28, 29]
  3437. },
  3438. 12: {
  3439. 0: [0],
  3440. 1: [[0, 16]],
  3441. 2: [0, 21, 23, 25]
  3442. },
  3443. 13: {
  3444. 0: [0],
  3445. 1: [[0, 5], 7, 8, 21, [23, 33], [81, 85]],
  3446. 2: [[0, 5], [7, 9], [23, 25], 27, 29, 30, 81, 83],
  3447. 3: [[0, 4], [21, 24]],
  3448. 4: [[0, 4], 6, 21, [23, 35], 81],
  3449. 5: [[0, 3], [21, 35], 81, 82],
  3450. 6: [[0, 4], [21, 38], [81, 84]],
  3451. 7: [[0, 3], 5, 6, [21, 33]],
  3452. 8: [[0, 4], [21, 28]],
  3453. 9: [[0, 3], [21, 30], [81, 84]],
  3454. 10: [[0, 3], [22, 26], 28, 81, 82],
  3455. 11: [[0, 2], [21, 28], 81, 82]
  3456. },
  3457. 14: {
  3458. 0: [0],
  3459. 1: [0, 1, [5, 10], [21, 23], 81],
  3460. 2: [[0, 3], 11, 12, [21, 27]],
  3461. 3: [[0, 3], 11, 21, 22],
  3462. 4: [[0, 2], 11, 21, [23, 31], 81],
  3463. 5: [[0, 2], 21, 22, 24, 25, 81],
  3464. 6: [[0, 3], [21, 24]],
  3465. 7: [[0, 2], [21, 29], 81],
  3466. 8: [[0, 2], [21, 30], 81, 82],
  3467. 9: [[0, 2], [21, 32], 81],
  3468. 10: [[0, 2], [21, 34], 81, 82],
  3469. 11: [[0, 2], [21, 30], 81, 82],
  3470. 23: [[0, 3], 22, 23, [25, 30], 32, 33]
  3471. },
  3472. 15: {
  3473. 0: [0],
  3474. 1: [[0, 5], [21, 25]],
  3475. 2: [[0, 7], [21, 23]],
  3476. 3: [[0, 4]],
  3477. 4: [[0, 4], [21, 26], [28, 30]],
  3478. 5: [[0, 2], [21, 26], 81],
  3479. 6: [[0, 2], [21, 27]],
  3480. 7: [[0, 3], [21, 27], [81, 85]],
  3481. 8: [[0, 2], [21, 26]],
  3482. 9: [[0, 2], [21, 29], 81],
  3483. 22: [[0, 2], [21, 24]],
  3484. 25: [[0, 2], [22, 31]],
  3485. 26: [[0, 2], [24, 27], [29, 32], 34],
  3486. 28: [0, 1, [22, 27]],
  3487. 29: [0, [21, 23]]
  3488. },
  3489. 21: {
  3490. 0: [0],
  3491. 1: [[0, 6], [11, 14], [22, 24], 81],
  3492. 2: [[0, 4], [11, 13], 24, [81, 83]],
  3493. 3: [[0, 4], 11, 21, 23, 81],
  3494. 4: [[0, 4], 11, [21, 23]],
  3495. 5: [[0, 5], 21, 22],
  3496. 6: [[0, 4], 24, 81, 82],
  3497. 7: [[0, 3], 11, 26, 27, 81, 82],
  3498. 8: [[0, 4], 11, 81, 82],
  3499. 9: [[0, 5], 11, 21, 22],
  3500. 10: [[0, 5], 11, 21, 81],
  3501. 11: [[0, 3], 21, 22],
  3502. 12: [[0, 2], 4, 21, 23, 24, 81, 82],
  3503. 13: [[0, 3], 21, 22, 24, 81, 82],
  3504. 14: [[0, 4], 21, 22, 81]
  3505. },
  3506. 22: {
  3507. 0: [0],
  3508. 1: [[0, 6], 12, 22, [81, 83]],
  3509. 2: [[0, 4], 11, 21, [81, 84]],
  3510. 3: [[0, 3], 22, 23, 81, 82],
  3511. 4: [[0, 3], 21, 22],
  3512. 5: [[0, 3], 21, 23, 24, 81, 82],
  3513. 6: [[0, 2], 4, 5, [21, 23], 25, 81],
  3514. 7: [[0, 2], [21, 24], 81],
  3515. 8: [[0, 2], 21, 22, 81, 82],
  3516. 24: [[0, 6], 24, 26]
  3517. },
  3518. 23: {
  3519. 0: [0],
  3520. 1: [[0, 12], 21, [23, 29], [81, 84]],
  3521. 2: [[0, 8], 21, [23, 25], 27, [29, 31], 81],
  3522. 3: [[0, 7], 21, 81, 82],
  3523. 4: [[0, 7], 21, 22],
  3524. 5: [[0, 3], 5, 6, [21, 24]],
  3525. 6: [[0, 6], [21, 24]],
  3526. 7: [[0, 16], 22, 81],
  3527. 8: [[0, 5], 11, 22, 26, 28, 33, 81, 82],
  3528. 9: [[0, 4], 21],
  3529. 10: [[0, 5], 24, 25, 81, [83, 85]],
  3530. 11: [[0, 2], 21, 23, 24, 81, 82],
  3531. 12: [[0, 2], [21, 26], [81, 83]],
  3532. 27: [[0, 4], [21, 23]]
  3533. },
  3534. 31: {
  3535. 0: [0],
  3536. 1: [0, 1, [3, 10], [12, 20]],
  3537. 2: [0, 30]
  3538. },
  3539. 32: {
  3540. 0: [0],
  3541. 1: [[0, 7], 11, [13, 18], 24, 25],
  3542. 2: [[0, 6], 11, 81, 82],
  3543. 3: [[0, 5], 11, 12, [21, 24], 81, 82],
  3544. 4: [[0, 2], 4, 5, 11, 12, 81, 82],
  3545. 5: [[0, 9], [81, 85]],
  3546. 6: [[0, 2], 11, 12, 21, 23, [81, 84]],
  3547. 7: [0, 1, 3, 5, 6, [21, 24]],
  3548. 8: [[0, 4], 11, 26, [29, 31]],
  3549. 9: [[0, 3], [21, 25], 28, 81, 82],
  3550. 10: [[0, 3], 11, 12, 23, 81, 84, 88],
  3551. 11: [[0, 2], 11, 12, [81, 83]],
  3552. 12: [[0, 4], [81, 84]],
  3553. 13: [[0, 2], 11, [21, 24]]
  3554. },
  3555. 33: {
  3556. 0: [0],
  3557. 1: [[0, 6], [8, 10], 22, 27, 82, 83, 85],
  3558. 2: [0, 1, [3, 6], 11, 12, 25, 26, [81, 83]],
  3559. 3: [[0, 4], 22, 24, [26, 29], 81, 82],
  3560. 4: [[0, 2], 11, 21, 24, [81, 83]],
  3561. 5: [[0, 3], [21, 23]],
  3562. 6: [[0, 2], 21, 24, [81, 83]],
  3563. 7: [[0, 3], 23, 26, 27, [81, 84]],
  3564. 8: [[0, 3], 22, 24, 25, 81],
  3565. 9: [[0, 3], 21, 22],
  3566. 10: [[0, 4], [21, 24], 81, 82],
  3567. 11: [[0, 2], [21, 27], 81]
  3568. },
  3569. 34: {
  3570. 0: [0],
  3571. 1: [[0, 4], 11, [21, 24], 81],
  3572. 2: [[0, 4], 7, 8, [21, 23], 25],
  3573. 3: [[0, 4], 11, [21, 23]],
  3574. 4: [[0, 6], 21],
  3575. 5: [[0, 4], 6, [21, 23]],
  3576. 6: [[0, 4], 21],
  3577. 7: [[0, 3], 11, 21],
  3578. 8: [[0, 3], 11, [22, 28], 81],
  3579. 10: [[0, 4], [21, 24]],
  3580. 11: [[0, 3], 22, [24, 26], 81, 82],
  3581. 12: [[0, 4], 21, 22, 25, 26, 82],
  3582. 13: [[0, 2], [21, 24]],
  3583. 14: [[0, 2], [21, 24]],
  3584. 15: [[0, 3], [21, 25]],
  3585. 16: [[0, 2], [21, 23]],
  3586. 17: [[0, 2], [21, 23]],
  3587. 18: [[0, 2], [21, 25], 81]
  3588. },
  3589. 35: {
  3590. 0: [0],
  3591. 1: [[0, 5], 11, [21, 25], 28, 81, 82],
  3592. 2: [[0, 6], [11, 13]],
  3593. 3: [[0, 5], 22],
  3594. 4: [[0, 3], 21, [23, 30], 81],
  3595. 5: [[0, 5], 21, [24, 27], [81, 83]],
  3596. 6: [[0, 3], [22, 29], 81],
  3597. 7: [[0, 2], [21, 25], [81, 84]],
  3598. 8: [[0, 2], [21, 25], 81],
  3599. 9: [[0, 2], [21, 26], 81, 82]
  3600. },
  3601. 36: {
  3602. 0: [0],
  3603. 1: [[0, 5], 11, [21, 24]],
  3604. 2: [[0, 3], 22, 81],
  3605. 3: [[0, 2], 13, [21, 23]],
  3606. 4: [[0, 3], 21, [23, 30], 81, 82],
  3607. 5: [[0, 2], 21],
  3608. 6: [[0, 2], 22, 81],
  3609. 7: [[0, 2], [21, 35], 81, 82],
  3610. 8: [[0, 3], [21, 30], 81],
  3611. 9: [[0, 2], [21, 26], [81, 83]],
  3612. 10: [[0, 2], [21, 30]],
  3613. 11: [[0, 2], [21, 30], 81]
  3614. },
  3615. 37: {
  3616. 0: [0],
  3617. 1: [[0, 5], 12, 13, [24, 26], 81],
  3618. 2: [[0, 3], 5, [11, 14], [81, 85]],
  3619. 3: [[0, 6], [21, 23]],
  3620. 4: [[0, 6], 81],
  3621. 5: [[0, 3], [21, 23]],
  3622. 6: [[0, 2], [11, 13], 34, [81, 87]],
  3623. 7: [[0, 5], 24, 25, [81, 86]],
  3624. 8: [[0, 2], 11, [26, 32], [81, 83]],
  3625. 9: [[0, 3], 11, 21, 23, 82, 83],
  3626. 10: [[0, 2], [81, 83]],
  3627. 11: [[0, 3], 21, 22],
  3628. 12: [[0, 3]],
  3629. 13: [[0, 2], 11, 12, [21, 29]],
  3630. 14: [[0, 2], [21, 28], 81, 82],
  3631. 15: [[0, 2], [21, 26], 81],
  3632. 16: [[0, 2], [21, 26]],
  3633. 17: [[0, 2], [21, 28]]
  3634. },
  3635. 41: {
  3636. 0: [0],
  3637. 1: [[0, 6], 8, 22, [81, 85]],
  3638. 2: [[0, 5], 11, [21, 25]],
  3639. 3: [[0, 7], 11, [22, 29], 81],
  3640. 4: [[0, 4], 11, [21, 23], 25, 81, 82],
  3641. 5: [[0, 3], 5, 6, 22, 23, 26, 27, 81],
  3642. 6: [[0, 3], 11, 21, 22],
  3643. 7: [[0, 4], 11, 21, [24, 28], 81, 82],
  3644. 8: [[0, 4], 11, [21, 23], 25, [81, 83]],
  3645. 9: [[0, 2], 22, 23, [26, 28]],
  3646. 10: [[0, 2], [23, 25], 81, 82],
  3647. 11: [[0, 4], [21, 23]],
  3648. 12: [[0, 2], 21, 22, 24, 81, 82],
  3649. 13: [[0, 3], [21, 30], 81],
  3650. 14: [[0, 3], [21, 26], 81],
  3651. 15: [[0, 3], [21, 28]],
  3652. 16: [[0, 2], [21, 28], 81],
  3653. 17: [[0, 2], [21, 29]],
  3654. 90: [0, 1]
  3655. },
  3656. 42: {
  3657. 0: [0],
  3658. 1: [[0, 7], [11, 17]],
  3659. 2: [[0, 5], 22, 81],
  3660. 3: [[0, 3], [21, 25], 81],
  3661. 5: [[0, 6], [25, 29], [81, 83]],
  3662. 6: [[0, 2], 6, 7, [24, 26], [82, 84]],
  3663. 7: [[0, 4]],
  3664. 8: [[0, 2], 4, 21, 22, 81],
  3665. 9: [[0, 2], [21, 23], 81, 82, 84],
  3666. 10: [[0, 3], [22, 24], 81, 83, 87],
  3667. 11: [[0, 2], [21, 27], 81, 82],
  3668. 12: [[0, 2], [21, 24], 81],
  3669. 13: [[0, 3], 21, 81],
  3670. 28: [[0, 2], 22, 23, [25, 28]],
  3671. 90: [0, [4, 6], 21]
  3672. },
  3673. 43: {
  3674. 0: [0],
  3675. 1: [[0, 5], 11, 12, 21, 22, 24, 81],
  3676. 2: [[0, 4], 11, 21, [23, 25], 81],
  3677. 3: [[0, 2], 4, 21, 81, 82],
  3678. 4: [0, 1, [5, 8], 12, [21, 24], 26, 81, 82],
  3679. 5: [[0, 3], 11, [21, 25], [27, 29], 81],
  3680. 6: [[0, 3], 11, 21, 23, 24, 26, 81, 82],
  3681. 7: [[0, 3], [21, 26], 81],
  3682. 8: [[0, 2], 11, 21, 22],
  3683. 9: [[0, 3], [21, 23], 81],
  3684. 10: [[0, 3], [21, 28], 81],
  3685. 11: [[0, 3], [21, 29]],
  3686. 12: [[0, 2], [21, 30], 81],
  3687. 13: [[0, 2], 21, 22, 81, 82],
  3688. 31: [0, 1, [22, 27], 30]
  3689. },
  3690. 44: {
  3691. 0: [0],
  3692. 1: [[0, 7], [11, 16], 83, 84],
  3693. 2: [[0, 5], 21, 22, 24, 29, 32, 33, 81, 82],
  3694. 3: [0, 1, [3, 8]],
  3695. 4: [[0, 4]],
  3696. 5: [0, 1, [6, 15], 23, 82, 83],
  3697. 6: [0, 1, [4, 8]],
  3698. 7: [0, 1, [3, 5], 81, [83, 85]],
  3699. 8: [[0, 4], 11, 23, 25, [81, 83]],
  3700. 9: [[0, 3], 23, [81, 83]],
  3701. 12: [[0, 3], [23, 26], 83, 84],
  3702. 13: [[0, 3], [22, 24], 81],
  3703. 14: [[0, 2], [21, 24], 26, 27, 81],
  3704. 15: [[0, 2], 21, 23, 81],
  3705. 16: [[0, 2], [21, 25]],
  3706. 17: [[0, 2], 21, 23, 81],
  3707. 18: [[0, 3], 21, 23, [25, 27], 81, 82],
  3708. 19: [0],
  3709. 20: [0],
  3710. 51: [[0, 3], 21, 22],
  3711. 52: [[0, 3], 21, 22, 24, 81],
  3712. 53: [[0, 2], [21, 23], 81]
  3713. },
  3714. 45: {
  3715. 0: [0],
  3716. 1: [[0, 9], [21, 27]],
  3717. 2: [[0, 5], [21, 26]],
  3718. 3: [[0, 5], 11, 12, [21, 32]],
  3719. 4: [0, 1, [3, 6], 11, [21, 23], 81],
  3720. 5: [[0, 3], 12, 21],
  3721. 6: [[0, 3], 21, 81],
  3722. 7: [[0, 3], 21, 22],
  3723. 8: [[0, 4], 21, 81],
  3724. 9: [[0, 3], [21, 24], 81],
  3725. 10: [[0, 2], [21, 31]],
  3726. 11: [[0, 2], [21, 23]],
  3727. 12: [[0, 2], [21, 29], 81],
  3728. 13: [[0, 2], [21, 24], 81],
  3729. 14: [[0, 2], [21, 25], 81]
  3730. },
  3731. 46: {
  3732. 0: [0],
  3733. 1: [0, 1, [5, 8]],
  3734. 2: [0, 1],
  3735. 3: [0, [21, 23]],
  3736. 90: [[0, 3], [5, 7], [21, 39]]
  3737. },
  3738. 50: {
  3739. 0: [0],
  3740. 1: [[0, 19]],
  3741. 2: [0, [22, 38], [40, 43]],
  3742. 3: [0, [81, 84]]
  3743. },
  3744. 51: {
  3745. 0: [0],
  3746. 1: [0, 1, [4, 8], [12, 15], [21, 24], 29, 31, 32, [81, 84]],
  3747. 3: [[0, 4], 11, 21, 22],
  3748. 4: [[0, 3], 11, 21, 22],
  3749. 5: [[0, 4], 21, 22, 24, 25],
  3750. 6: [0, 1, 3, 23, 26, [81, 83]],
  3751. 7: [0, 1, 3, 4, [22, 27], 81],
  3752. 8: [[0, 2], 11, 12, [21, 24]],
  3753. 9: [[0, 4], [21, 23]],
  3754. 10: [[0, 2], 11, 24, 25, 28],
  3755. 11: [[0, 2], [11, 13], 23, 24, 26, 29, 32, 33, 81],
  3756. 13: [[0, 4], [21, 25], 81],
  3757. 14: [[0, 2], [21, 25]],
  3758. 15: [[0, 3], [21, 29]],
  3759. 16: [[0, 3], [21, 23], 81],
  3760. 17: [[0, 3], [21, 25], 81],
  3761. 18: [[0, 3], [21, 27]],
  3762. 19: [[0, 3], [21, 23]],
  3763. 20: [[0, 2], 21, 22, 81],
  3764. 32: [0, [21, 33]],
  3765. 33: [0, [21, 38]],
  3766. 34: [0, 1, [22, 37]]
  3767. },
  3768. 52: {
  3769. 0: [0],
  3770. 1: [[0, 3], [11, 15], [21, 23], 81],
  3771. 2: [0, 1, 3, 21, 22],
  3772. 3: [[0, 3], [21, 30], 81, 82],
  3773. 4: [[0, 2], [21, 25]],
  3774. 5: [[0, 2], [21, 27]],
  3775. 6: [[0, 3], [21, 28]],
  3776. 22: [0, 1, [22, 30]],
  3777. 23: [0, 1, [22, 28]],
  3778. 24: [0, 1, [22, 28]],
  3779. 26: [0, 1, [22, 36]],
  3780. 27: [[0, 2], 22, 23, [25, 32]]
  3781. },
  3782. 53: {
  3783. 0: [0],
  3784. 1: [[0, 3], [11, 14], 21, 22, [24, 29], 81],
  3785. 3: [[0, 2], [21, 26], 28, 81],
  3786. 4: [[0, 2], [21, 28]],
  3787. 5: [[0, 2], [21, 24]],
  3788. 6: [[0, 2], [21, 30]],
  3789. 7: [[0, 2], [21, 24]],
  3790. 8: [[0, 2], [21, 29]],
  3791. 9: [[0, 2], [21, 27]],
  3792. 23: [0, 1, [22, 29], 31],
  3793. 25: [[0, 4], [22, 32]],
  3794. 26: [0, 1, [21, 28]],
  3795. 27: [0, 1, [22, 30]], 28: [0, 1, 22, 23],
  3796. 29: [0, 1, [22, 32]],
  3797. 31: [0, 2, 3, [22, 24]],
  3798. 34: [0, [21, 23]],
  3799. 33: [0, 21, [23, 25]],
  3800. 35: [0, [21, 28]]
  3801. },
  3802. 54: {
  3803. 0: [0],
  3804. 1: [[0, 2], [21, 27]],
  3805. 21: [0, [21, 29], 32, 33],
  3806. 22: [0, [21, 29], [31, 33]],
  3807. 23: [0, 1, [22, 38]],
  3808. 24: [0, [21, 31]],
  3809. 25: [0, [21, 27]],
  3810. 26: [0, [21, 27]]
  3811. },
  3812. 61: {
  3813. 0: [0],
  3814. 1: [[0, 4], [11, 16], 22, [24, 26]],
  3815. 2: [[0, 4], 22],
  3816. 3: [[0, 4], [21, 24], [26, 31]],
  3817. 4: [[0, 4], [22, 31], 81],
  3818. 5: [[0, 2], [21, 28], 81, 82],
  3819. 6: [[0, 2], [21, 32]],
  3820. 7: [[0, 2], [21, 30]],
  3821. 8: [[0, 2], [21, 31]],
  3822. 9: [[0, 2], [21, 29]],
  3823. 10: [[0, 2], [21, 26]]
  3824. },
  3825. 62: {
  3826. 0: [0],
  3827. 1: [[0, 5], 11, [21, 23]],
  3828. 2: [0, 1],
  3829. 3: [[0, 2], 21],
  3830. 4: [[0, 3], [21, 23]],
  3831. 5: [[0, 3], [21, 25]],
  3832. 6: [[0, 2], [21, 23]],
  3833. 7: [[0, 2], [21, 25]],
  3834. 8: [[0, 2], [21, 26]],
  3835. 9: [[0, 2], [21, 24], 81, 82],
  3836. 10: [[0, 2], [21, 27]],
  3837. 11: [[0, 2], [21, 26]],
  3838. 12: [[0, 2], [21, 28]],
  3839. 24: [0, 21, [24, 29]],
  3840. 26: [0, 21, [23, 30]],
  3841. 29: [0, 1, [21, 27]],
  3842. 30: [0, 1, [21, 27]]
  3843. },
  3844. 63: {
  3845. 0: [0],
  3846. 1: [[0, 5], [21, 23]],
  3847. 2: [0, 2, [21, 25]],
  3848. 21: [0, [21, 23], [26, 28]],
  3849. 22: [0, [21, 24]],
  3850. 23: [0, [21, 24]],
  3851. 25: [0, [21, 25]],
  3852. 26: [0, [21, 26]],
  3853. 27: [0, 1, [21, 26]],
  3854. 28: [[0, 2], [21, 23]]
  3855. },
  3856. 64: {
  3857. 0: [0],
  3858. 1: [0, 1, [4, 6], 21, 22, 81],
  3859. 2: [[0, 3], 5, [21, 23]],
  3860. 3: [[0, 3], [21, 24], 81],
  3861. 4: [[0, 2], [21, 25]],
  3862. 5: [[0, 2], 21, 22]
  3863. },
  3864. 65: {
  3865. 0: [0],
  3866. 1: [[0, 9], 21],
  3867. 2: [[0, 5]],
  3868. 21: [0, 1, 22, 23],
  3869. 22: [0, 1, 22, 23],
  3870. 23: [[0, 3], [23, 25], 27, 28],
  3871. 28: [0, 1, [22, 29]],
  3872. 29: [0, 1, [22, 29]],
  3873. 30: [0, 1, [22, 24]], 31: [0, 1, [21, 31]],
  3874. 32: [0, 1, [21, 27]],
  3875. 40: [0, 2, 3, [21, 28]],
  3876. 42: [[0, 2], 21, [23, 26]],
  3877. 43: [0, 1, [21, 26]],
  3878. 90: [[0, 4]], 27: [[0, 2], 22, 23]
  3879. },
  3880. 71: { 0: [0] },
  3881. 81: { 0: [0] },
  3882. 82: { 0: [0] }
  3883. };
  3884. var provincial = parseInt(value.substr(0, 2), 10),
  3885. prefectural = parseInt(value.substr(2, 2), 10),
  3886. county = parseInt(value.substr(4, 2), 10);
  3887. if (!adminDivisionCodes[provincial] || !adminDivisionCodes[provincial][prefectural]) {
  3888. return false;
  3889. }
  3890. var inRange = false,
  3891. rangeDef = adminDivisionCodes[provincial][prefectural];
  3892. for (var i = 0; i < rangeDef.length; i++) {
  3893. if (($.isArray(rangeDef[i]) && rangeDef[i][0] <= county && county <= rangeDef[i][1])
  3894. || (!$.isArray(rangeDef[i]) && county === rangeDef[i]))
  3895. {
  3896. inRange = true;
  3897. break;
  3898. }
  3899. }
  3900. if (!inRange) {
  3901. return false;
  3902. }
  3903. // Check date of birth
  3904. var dob;
  3905. if (value.length === 18) {
  3906. dob = value.substr(6, 8);
  3907. } else /* length == 15 */ {
  3908. dob = '19' + value.substr(6, 6);
  3909. }
  3910. var year = parseInt(dob.substr(0, 4), 10),
  3911. month = parseInt(dob.substr(4, 2), 10),
  3912. day = parseInt(dob.substr(6, 2), 10);
  3913. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3914. return false;
  3915. }
  3916. // Check checksum (18-digit system only)
  3917. if (value.length === 18) {
  3918. var sum = 0,
  3919. weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  3920. for (i = 0; i < 17; i++) {
  3921. sum += parseInt(value.charAt(i), 10) * weight[i];
  3922. }
  3923. sum = (12 - (sum % 11)) % 11;
  3924. var checksum = (value.charAt(17).toUpperCase() !== 'X') ? parseInt(value.charAt(17), 10) : 10;
  3925. return checksum === sum;
  3926. }
  3927. return true;
  3928. },
  3929. /**
  3930. * Validate Czech national identification number (RC)
  3931. * Examples:
  3932. * - Valid: 7103192745, 991231123
  3933. * - Invalid: 1103492745, 590312123
  3934. *
  3935. * @param {String} value The ID
  3936. * @returns {Boolean}
  3937. */
  3938. _cz: function(value) {
  3939. if (!/^\d{9,10}$/.test(value)) {
  3940. return false;
  3941. }
  3942. var year = 1900 + parseInt(value.substr(0, 2), 10),
  3943. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  3944. day = parseInt(value.substr(4, 2), 10);
  3945. if (value.length === 9) {
  3946. if (year >= 1980) {
  3947. year -= 100;
  3948. }
  3949. if (year > 1953) {
  3950. return false;
  3951. }
  3952. } else if (year < 1954) {
  3953. year += 100;
  3954. }
  3955. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3956. return false;
  3957. }
  3958. // Check that the birth date is not in the future
  3959. if (value.length === 10) {
  3960. var check = parseInt(value.substr(0, 9), 10) % 11;
  3961. if (year < 1985) {
  3962. check = check % 10;
  3963. }
  3964. return (check + '' === value.substr(9, 1));
  3965. }
  3966. return true;
  3967. },
  3968. /**
  3969. * Validate Danish Personal Identification number (CPR)
  3970. * Examples:
  3971. * - Valid: 2110625629, 211062-5629
  3972. * - Invalid: 511062-5629
  3973. *
  3974. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  3975. * @param {String} value The ID
  3976. * @returns {Boolean}
  3977. */
  3978. _dk: function(value) {
  3979. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  3980. return false;
  3981. }
  3982. value = value.replace(/-/g, '');
  3983. var day = parseInt(value.substr(0, 2), 10),
  3984. month = parseInt(value.substr(2, 2), 10),
  3985. year = parseInt(value.substr(4, 2), 10);
  3986. switch (true) {
  3987. case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  3988. year += 1800;
  3989. break;
  3990. case ('0123'.indexOf(value.charAt(6)) !== -1):
  3991. case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  3992. year += 1900;
  3993. break;
  3994. default:
  3995. year += 2000;
  3996. break;
  3997. }
  3998. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  3999. },
  4000. /**
  4001. * Validate Estonian Personal Identification Code (isikukood)
  4002. * Examples:
  4003. * - Valid: 37605030299
  4004. *
  4005. * @see http://et.wikipedia.org/wiki/Isikukood
  4006. * @param {String} value The ID
  4007. * @returns {Boolean}
  4008. */
  4009. _ee: function(value) {
  4010. // Use the same format as Lithuanian Personal Code
  4011. return this._lt(value);
  4012. },
  4013. /**
  4014. * Validate Spanish personal identity code (DNI)
  4015. * Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
  4016. *
  4017. * Examples:
  4018. * - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
  4019. * - Invalid: i) 54362315Z; ii) X-2482300A
  4020. *
  4021. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  4022. * @param {String} value The ID
  4023. * @returns {Boolean}
  4024. */
  4025. _es: function(value) {
  4026. if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
  4027. && !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
  4028. return false;
  4029. }
  4030. value = value.replace(/-/g, '');
  4031. var index = 'XYZ'.indexOf(value.charAt(0));
  4032. if (index !== -1) {
  4033. // It is NIE number
  4034. value = index + value.substr(1) + '';
  4035. }
  4036. var check = parseInt(value.substr(0, 8), 10);
  4037. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4038. return (check === value.substr(8, 1));
  4039. },
  4040. /**
  4041. * Validate Finnish Personal Identity Code (HETU)
  4042. * Examples:
  4043. * - Valid: 311280-888Y, 131052-308T
  4044. * - Invalid: 131052-308U, 310252-308Y
  4045. *
  4046. * @param {String} value The ID
  4047. * @returns {Boolean}
  4048. */
  4049. _fi: function(value) {
  4050. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  4051. return false;
  4052. }
  4053. var day = parseInt(value.substr(0, 2), 10),
  4054. month = parseInt(value.substr(2, 2), 10),
  4055. year = parseInt(value.substr(4, 2), 10),
  4056. centuries = {
  4057. '+': 1800,
  4058. '-': 1900,
  4059. 'A': 2000
  4060. };
  4061. year = centuries[value.charAt(6)] + year;
  4062. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4063. return false;
  4064. }
  4065. var individual = parseInt(value.substr(7, 3), 10);
  4066. if (individual < 2) {
  4067. return false;
  4068. }
  4069. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  4070. n = parseInt(n, 10);
  4071. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  4072. },
  4073. /**
  4074. * Validate Croatian personal identification number (OIB)
  4075. * Examples:
  4076. * - Valid: 33392005961
  4077. * - Invalid: 33392005962
  4078. *
  4079. * @param {String} value The ID
  4080. * @returns {Boolean}
  4081. */
  4082. _hr: function(value) {
  4083. if (!/^[0-9]{11}$/.test(value)) {
  4084. return false;
  4085. }
  4086. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  4087. },
  4088. /**
  4089. * Validate Irish Personal Public Service Number (PPS)
  4090. * Examples:
  4091. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  4092. * - Invalid: 6433435E, 6433435VH
  4093. *
  4094. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  4095. * @param {String} value The ID
  4096. * @returns {Boolean}
  4097. */
  4098. _ie: function(value) {
  4099. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  4100. return false;
  4101. }
  4102. var getCheckDigit = function(value) {
  4103. while (value.length < 7) {
  4104. value = '0' + value;
  4105. }
  4106. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  4107. sum = 0;
  4108. for (var i = 0; i < 7; i++) {
  4109. sum += parseInt(value.charAt(i), 10) * (8 - i);
  4110. }
  4111. sum += 9 * alphabet.indexOf(value.substr(7));
  4112. return alphabet[sum % 23];
  4113. };
  4114. // 2013 format
  4115. if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  4116. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  4117. }
  4118. // The old format
  4119. else {
  4120. return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  4121. }
  4122. },
  4123. /**
  4124. * Validate Iceland national identification number (Kennitala)
  4125. * Examples:
  4126. * - Valid: 120174-3399, 1201743399, 0902862349
  4127. *
  4128. * @see http://en.wikipedia.org/wiki/Kennitala
  4129. * @param {String} value The ID
  4130. * @returns {Boolean}
  4131. */
  4132. _is: function(value) {
  4133. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  4134. return false;
  4135. }
  4136. value = value.replace(/-/g, '');
  4137. var day = parseInt(value.substr(0, 2), 10),
  4138. month = parseInt(value.substr(2, 2), 10),
  4139. year = parseInt(value.substr(4, 2), 10),
  4140. century = parseInt(value.charAt(9), 10);
  4141. year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  4142. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  4143. return false;
  4144. }
  4145. // Validate the check digit
  4146. var sum = 0,
  4147. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  4148. for (var i = 0; i < 8; i++) {
  4149. sum += parseInt(value.charAt(i), 10) * weight[i];
  4150. }
  4151. sum = 11 - sum % 11;
  4152. return (sum + '' === value.charAt(8));
  4153. },
  4154. /**
  4155. * Validate Lithuanian Personal Code (Asmens kodas)
  4156. * Examples:
  4157. * - Valid: 38703181745
  4158. * - Invalid: 38703181746, 78703181745, 38703421745
  4159. *
  4160. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  4161. * @see http://www.adomas.org/midi2007/pcode.html
  4162. * @param {String} value The ID
  4163. * @returns {Boolean}
  4164. */
  4165. _lt: function(value) {
  4166. if (!/^[0-9]{11}$/.test(value)) {
  4167. return false;
  4168. }
  4169. var gender = parseInt(value.charAt(0), 10),
  4170. year = parseInt(value.substr(1, 2), 10),
  4171. month = parseInt(value.substr(3, 2), 10),
  4172. day = parseInt(value.substr(5, 2), 10),
  4173. century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  4174. year = century * 100 + year;
  4175. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  4176. return false;
  4177. }
  4178. // Validate the check digit
  4179. var sum = 0,
  4180. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  4181. for (var i = 0; i < 10; i++) {
  4182. sum += parseInt(value.charAt(i), 10) * weight[i];
  4183. }
  4184. sum = sum % 11;
  4185. if (sum !== 10) {
  4186. return sum + '' === value.charAt(10);
  4187. }
  4188. // Re-calculate the check digit
  4189. sum = 0;
  4190. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  4191. for (i = 0; i < 10; i++) {
  4192. sum += parseInt(value.charAt(i), 10) * weight[i];
  4193. }
  4194. sum = sum % 11;
  4195. if (sum === 10) {
  4196. sum = 0;
  4197. }
  4198. return (sum + '' === value.charAt(10));
  4199. },
  4200. /**
  4201. * Validate Latvian Personal Code (Personas kods)
  4202. * Examples:
  4203. * - Valid: 161175-19997, 16117519997
  4204. * - Invalid: 161375-19997
  4205. *
  4206. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  4207. * @param {String} value The ID
  4208. * @returns {Boolean}
  4209. */
  4210. _lv: function(value) {
  4211. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  4212. return false;
  4213. }
  4214. value = value.replace(/\D/g, '');
  4215. // Check birth date
  4216. var day = parseInt(value.substr(0, 2), 10),
  4217. month = parseInt(value.substr(2, 2), 10),
  4218. year = parseInt(value.substr(4, 2), 10);
  4219. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  4220. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  4221. return false;
  4222. }
  4223. // Check personal code
  4224. var sum = 0,
  4225. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  4226. for (var i = 0; i < 10; i++) {
  4227. sum += parseInt(value.charAt(i), 10) * weight[i];
  4228. }
  4229. sum = (sum + 1) % 11 % 10;
  4230. return (sum + '' === value.charAt(10));
  4231. },
  4232. /**
  4233. * Validate Dutch national identification number (BSN)
  4234. * Examples:
  4235. * - Valid: 111222333, 941331490, 9413.31.490
  4236. * - Invalid: 111252333
  4237. *
  4238. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  4239. * @param {String} value The ID
  4240. * @returns {Boolean}
  4241. */
  4242. _nl: function(value) {
  4243. while (value.length < 9) {
  4244. value = '0' + value;
  4245. }
  4246. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  4247. return false;
  4248. }
  4249. value = value.replace(/\./g, '');
  4250. if (parseInt(value, 10) === 0) {
  4251. return false;
  4252. }
  4253. var sum = 0,
  4254. length = value.length;
  4255. for (var i = 0; i < length - 1; i++) {
  4256. sum += (9 - i) * parseInt(value.charAt(i), 10);
  4257. }
  4258. sum = sum % 11;
  4259. if (sum === 10) {
  4260. sum = 0;
  4261. }
  4262. return (sum + '' === value.charAt(length - 1));
  4263. },
  4264. /**
  4265. * Validate Romanian numerical personal code (CNP)
  4266. * Examples:
  4267. * - Valid: 1630615123457, 1800101221144
  4268. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  4269. *
  4270. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  4271. * @param {String} value The ID
  4272. * @returns {Boolean}
  4273. */
  4274. _ro: function(value) {
  4275. if (!/^[0-9]{13}$/.test(value)) {
  4276. return false;
  4277. }
  4278. var gender = parseInt(value.charAt(0), 10);
  4279. if (gender === 0 || gender === 7 || gender === 8) {
  4280. return false;
  4281. }
  4282. // Determine the date of birth
  4283. var year = parseInt(value.substr(1, 2), 10),
  4284. month = parseInt(value.substr(3, 2), 10),
  4285. day = parseInt(value.substr(5, 2), 10),
  4286. // The year of date is determined base on the gender
  4287. centuries = {
  4288. '1': 1900, // Male born between 1900 and 1999
  4289. '2': 1900, // Female born between 1900 and 1999
  4290. '3': 1800, // Male born between 1800 and 1899
  4291. '4': 1800, // Female born between 1800 and 1899
  4292. '5': 2000, // Male born after 2000
  4293. '6': 2000 // Female born after 2000
  4294. };
  4295. if (day > 31 && month > 12) {
  4296. return false;
  4297. }
  4298. if (gender !== 9) {
  4299. year = centuries[gender + ''] + year;
  4300. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4301. return false;
  4302. }
  4303. }
  4304. // Validate the check digit
  4305. var sum = 0,
  4306. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  4307. length = value.length;
  4308. for (var i = 0; i < length - 1; i++) {
  4309. sum += parseInt(value.charAt(i), 10) * weight[i];
  4310. }
  4311. sum = sum % 11;
  4312. if (sum === 10) {
  4313. sum = 1;
  4314. }
  4315. return (sum + '' === value.charAt(length - 1));
  4316. },
  4317. /**
  4318. * Validate Swedish personal identity number (personnummer)
  4319. * Examples:
  4320. * - Valid: 8112289874, 811228-9874, 811228+9874
  4321. * - Invalid: 811228-9873
  4322. *
  4323. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  4324. * @param {String} value The ID
  4325. * @returns {Boolean}
  4326. */
  4327. _se: function(value) {
  4328. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  4329. return false;
  4330. }
  4331. value = value.replace(/[^0-9]/g, '');
  4332. var year = parseInt(value.substr(0, 2), 10) + 1900,
  4333. month = parseInt(value.substr(2, 2), 10),
  4334. day = parseInt(value.substr(4, 2), 10);
  4335. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4336. return false;
  4337. }
  4338. // Validate the last check digit
  4339. return $.fn.bootstrapValidator.helpers.luhn(value);
  4340. },
  4341. /**
  4342. * Validate Slovak national identifier number (RC)
  4343. * Examples:
  4344. * - Valid: 7103192745, 991231123
  4345. * - Invalid: 7103192746, 1103492745
  4346. *
  4347. * @param {String} value The ID
  4348. * @returns {Boolean}
  4349. */
  4350. _sk: function(value) {
  4351. // Slovakia uses the same format as Czech Republic
  4352. return this._cz(value);
  4353. },
  4354. /**
  4355. * Validate San Marino citizen number
  4356. *
  4357. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  4358. * @param {String} value The ID
  4359. * @returns {Boolean}
  4360. */
  4361. _sm: function(value) {
  4362. return /^\d{5}$/.test(value);
  4363. },
  4364. /**
  4365. * Validate Thailand citizen number
  4366. * Examples:
  4367. * - Valid: 7145620509547, 3688699975685, 2368719339716
  4368. * - Invalid: 1100800092310
  4369. *
  4370. * @see http://en.wikipedia.org/wiki/National_identification_number#Thailand
  4371. * @param {String} value The ID
  4372. * @returns {Boolean}
  4373. */
  4374. _th: function(value) {
  4375. if (value.length !== 13) {
  4376. return false;
  4377. }
  4378. var sum = 0;
  4379. for (var i = 0; i < 12; i++) {
  4380. sum += parseInt(value.charAt(i), 10) * (13 - i);
  4381. }
  4382. return (11 - sum % 11) % 10 === parseInt(value.charAt(12), 10);
  4383. },
  4384. /**
  4385. * Validate South African ID
  4386. * Example:
  4387. * - Valid: 8001015009087
  4388. * - Invalid: 8001015009287, 8001015009086
  4389. *
  4390. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  4391. * @param {String} value The ID
  4392. * @returns {Boolean}
  4393. */
  4394. _za: function(value) {
  4395. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  4396. return false;
  4397. }
  4398. var year = parseInt(value.substr(0, 2), 10),
  4399. currentYear = new Date().getFullYear() % 100,
  4400. month = parseInt(value.substr(2, 2), 10),
  4401. day = parseInt(value.substr(4, 2), 10);
  4402. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  4403. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4404. return false;
  4405. }
  4406. // Validate the last check digit
  4407. return $.fn.bootstrapValidator.helpers.luhn(value);
  4408. }
  4409. };
  4410. }(window.jQuery));
  4411. ;(function($) {
  4412. $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
  4413. 'default': 'Please enter the same value'
  4414. });
  4415. $.fn.bootstrapValidator.validators.identical = {
  4416. html5Attributes: {
  4417. message: 'message',
  4418. field: 'field'
  4419. },
  4420. /**
  4421. * Check if input value equals to value of particular one
  4422. *
  4423. * @param {BootstrapValidator} validator The validator plugin instance
  4424. * @param {jQuery} $field Field element
  4425. * @param {Object} options Consists of the following key:
  4426. * - field: The name of field that will be used to compare with current one
  4427. * @returns {Boolean}
  4428. */
  4429. validate: function(validator, $field, options) {
  4430. var value = $field.val();
  4431. if (value === '') {
  4432. return true;
  4433. }
  4434. var compareWith = validator.getFieldElements(options.field);
  4435. if (compareWith === null || compareWith.length === 0) {
  4436. return true;
  4437. }
  4438. if (value === compareWith.val()) {
  4439. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  4440. return true;
  4441. } else {
  4442. return false;
  4443. }
  4444. }
  4445. };
  4446. }(window.jQuery));
  4447. ;(function($) {
  4448. $.fn.bootstrapValidator.i18n.imei = $.extend($.fn.bootstrapValidator.i18n.imei || {}, {
  4449. 'default': 'Please enter a valid IMEI number'
  4450. });
  4451. $.fn.bootstrapValidator.validators.imei = {
  4452. /**
  4453. * Validate IMEI (International Mobile Station Equipment Identity)
  4454. * Examples:
  4455. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  4456. * - Invalid: 490154203237517
  4457. *
  4458. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  4459. * @param {BootstrapValidator} validator The validator plugin instance
  4460. * @param {jQuery} $field Field element
  4461. * @param {Object} options Can consist of the following keys:
  4462. * - message: The invalid message
  4463. * @returns {Boolean}
  4464. */
  4465. validate: function(validator, $field, options) {
  4466. var value = $field.val();
  4467. if (value === '') {
  4468. return true;
  4469. }
  4470. switch (true) {
  4471. case /^\d{15}$/.test(value):
  4472. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  4473. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  4474. value = value.replace(/[^0-9]/g, '');
  4475. return $.fn.bootstrapValidator.helpers.luhn(value);
  4476. case /^\d{14}$/.test(value):
  4477. case /^\d{16}$/.test(value):
  4478. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  4479. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  4480. return true;
  4481. default:
  4482. return false;
  4483. }
  4484. }
  4485. };
  4486. }(window.jQuery));
  4487. ;(function($) {
  4488. $.fn.bootstrapValidator.i18n.imo = $.extend($.fn.bootstrapValidator.i18n.imo || {}, {
  4489. 'default': 'Please enter a valid IMO number'
  4490. });
  4491. $.fn.bootstrapValidator.validators.imo = {
  4492. /**
  4493. * Validate IMO (International Maritime Organization)
  4494. * Examples:
  4495. * - Valid: IMO 8814275, IMO 9176187
  4496. * - Invalid: IMO 8814274
  4497. *
  4498. * @see http://en.wikipedia.org/wiki/IMO_Number
  4499. * @param {BootstrapValidator} validator The validator plugin instance
  4500. * @param {jQuery} $field Field element
  4501. * @param {Object} options Can consist of the following keys:
  4502. * - message: The invalid message
  4503. * @returns {Boolean}
  4504. */
  4505. validate: function(validator, $field, options) {
  4506. var value = $field.val();
  4507. if (value === '') {
  4508. return true;
  4509. }
  4510. if (!/^IMO \d{7}$/i.test(value)) {
  4511. return false;
  4512. }
  4513. // Grab just the digits
  4514. var sum = 0,
  4515. digits = value.replace(/^.*(\d{7})$/, '$1');
  4516. // Go over each char, multiplying by the inverse of it's position
  4517. // IMO 9176187
  4518. // (9 * 7) + (1 * 6) + (7 * 5) + (6 * 4) + (1 * 3) + (8 * 2) = 147
  4519. // Take the last digit of that, that's the check digit (7)
  4520. for (var i = 6; i >= 1; i--) {
  4521. sum += (digits.slice((6 - i), -i) * (i + 1));
  4522. }
  4523. return sum % 10 === parseInt(digits.charAt(6), 10);
  4524. }
  4525. };
  4526. }(window.jQuery));
  4527. ;(function($) {
  4528. $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
  4529. 'default': 'Please enter a valid number'
  4530. });
  4531. $.fn.bootstrapValidator.validators.integer = {
  4532. enableByHtml5: function($field) {
  4533. return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
  4534. },
  4535. /**
  4536. * Return true if the input value is an integer
  4537. *
  4538. * @param {BootstrapValidator} validator The validator plugin instance
  4539. * @param {jQuery} $field Field element
  4540. * @param {Object} options Can consist of the following key:
  4541. * - message: The invalid message
  4542. * @returns {Boolean}
  4543. */
  4544. validate: function(validator, $field, options) {
  4545. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  4546. return false;
  4547. }
  4548. var value = $field.val();
  4549. if (value === '') {
  4550. return true;
  4551. }
  4552. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  4553. }
  4554. };
  4555. }(window.jQuery));
  4556. ;(function($) {
  4557. $.fn.bootstrapValidator.i18n.ip = $.extend($.fn.bootstrapValidator.i18n.ip || {}, {
  4558. 'default': 'Please enter a valid IP address',
  4559. ipv4: 'Please enter a valid IPv4 address',
  4560. ipv6: 'Please enter a valid IPv6 address'
  4561. });
  4562. $.fn.bootstrapValidator.validators.ip = {
  4563. html5Attributes: {
  4564. message: 'message',
  4565. ipv4: 'ipv4',
  4566. ipv6: 'ipv6'
  4567. },
  4568. /**
  4569. * Return true if the input value is a IP address.
  4570. *
  4571. * @param {BootstrapValidator} validator The validator plugin instance
  4572. * @param {jQuery} $field Field element
  4573. * @param {Object} options Can consist of the following keys:
  4574. * - ipv4: Enable IPv4 validator, default to true
  4575. * - ipv6: Enable IPv6 validator, default to true
  4576. * - message: The invalid message
  4577. * @returns {Boolean|Object}
  4578. */
  4579. validate: function(validator, $field, options) {
  4580. var value = $field.val();
  4581. if (value === '') {
  4582. return true;
  4583. }
  4584. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  4585. var 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]?)$/,
  4586. 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*$/,
  4587. valid = false,
  4588. message;
  4589. switch (true) {
  4590. case (options.ipv4 && !options.ipv6):
  4591. valid = ipv4Regex.test(value);
  4592. message = options.message || $.fn.bootstrapValidator.i18n.ip.ipv4;
  4593. break;
  4594. case (!options.ipv4 && options.ipv6):
  4595. valid = ipv6Regex.test(value);
  4596. message = options.message || $.fn.bootstrapValidator.i18n.ip.ipv6;
  4597. break;
  4598. case (options.ipv4 && options.ipv6):
  4599. /* falls through */
  4600. default:
  4601. valid = ipv4Regex.test(value) || ipv6Regex.test(value);
  4602. message = options.message || $.fn.bootstrapValidator.i18n.ip['default'];
  4603. break;
  4604. }
  4605. return {
  4606. valid: valid,
  4607. message: message
  4608. };
  4609. }
  4610. };
  4611. }(window.jQuery));;(function($) {
  4612. $.fn.bootstrapValidator.i18n.isbn = $.extend($.fn.bootstrapValidator.i18n.isbn || {}, {
  4613. 'default': 'Please enter a valid ISBN number'
  4614. });
  4615. $.fn.bootstrapValidator.validators.isbn = {
  4616. /**
  4617. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  4618. * Examples:
  4619. * - Valid:
  4620. * 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
  4621. * ISBN 13: 978-0-306-40615-7
  4622. * - Invalid:
  4623. * ISBN 10: 99921-58-10-6
  4624. * ISBN 13: 978-0-306-40615-6
  4625. *
  4626. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  4627. * @param {BootstrapValidator} validator The validator plugin instance
  4628. * @param {jQuery} $field Field element
  4629. * @param {Object} [options] Can consist of the following keys:
  4630. * - message: The invalid message
  4631. * @returns {Boolean}
  4632. */
  4633. validate: function(validator, $field, options) {
  4634. var value = $field.val();
  4635. if (value === '') {
  4636. return true;
  4637. }
  4638. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  4639. // Groups are separated by a hyphen or a space
  4640. var type;
  4641. switch (true) {
  4642. case /^\d{9}[\dX]$/.test(value):
  4643. case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  4644. case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  4645. type = 'ISBN10';
  4646. break;
  4647. case /^(978|979)\d{9}[\dX]$/.test(value):
  4648. case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  4649. case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  4650. type = 'ISBN13';
  4651. break;
  4652. default:
  4653. return false;
  4654. }
  4655. // Replace all special characters except digits and X
  4656. value = value.replace(/[^0-9X]/gi, '');
  4657. var chars = value.split(''),
  4658. length = chars.length,
  4659. sum = 0,
  4660. i,
  4661. checksum;
  4662. switch (type) {
  4663. case 'ISBN10':
  4664. sum = 0;
  4665. for (i = 0; i < length - 1; i++) {
  4666. sum += parseInt(chars[i], 10) * (10 - i);
  4667. }
  4668. checksum = 11 - (sum % 11);
  4669. if (checksum === 11) {
  4670. checksum = 0;
  4671. } else if (checksum === 10) {
  4672. checksum = 'X';
  4673. }
  4674. return (checksum + '' === chars[length - 1]);
  4675. case 'ISBN13':
  4676. sum = 0;
  4677. for (i = 0; i < length - 1; i++) {
  4678. sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  4679. }
  4680. checksum = 10 - (sum % 10);
  4681. if (checksum === 10) {
  4682. checksum = '0';
  4683. }
  4684. return (checksum + '' === chars[length - 1]);
  4685. default:
  4686. return false;
  4687. }
  4688. }
  4689. };
  4690. }(window.jQuery));
  4691. ;(function($) {
  4692. $.fn.bootstrapValidator.i18n.isin = $.extend($.fn.bootstrapValidator.i18n.isin || {}, {
  4693. 'default': 'Please enter a valid ISIN number'
  4694. });
  4695. $.fn.bootstrapValidator.validators.isin = {
  4696. // Available country codes
  4697. // See http://isin.net/country-codes/
  4698. 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',
  4699. /**
  4700. * Validate an ISIN (International Securities Identification Number)
  4701. * Examples:
  4702. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  4703. * - Invalid: US0378331004, AA0000XVGZA3
  4704. *
  4705. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  4706. * @param {BootstrapValidator} validator The validator plugin instance
  4707. * @param {jQuery} $field Field element
  4708. * @param {Object} options Can consist of the following keys:
  4709. * - message: The invalid message
  4710. * @returns {Boolean}
  4711. */
  4712. validate: function(validator, $field, options) {
  4713. var value = $field.val();
  4714. if (value === '') {
  4715. return true;
  4716. }
  4717. value = value.toUpperCase();
  4718. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  4719. if (!regex.test(value)) {
  4720. return false;
  4721. }
  4722. var converted = '',
  4723. length = value.length;
  4724. // Convert letters to number
  4725. for (var i = 0; i < length - 1; i++) {
  4726. var c = value.charCodeAt(i);
  4727. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  4728. }
  4729. var digits = '',
  4730. n = converted.length,
  4731. group = (n % 2 !== 0) ? 0 : 1;
  4732. for (i = 0; i < n; i++) {
  4733. digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  4734. }
  4735. var sum = 0;
  4736. for (i = 0; i < digits.length; i++) {
  4737. sum += parseInt(digits.charAt(i), 10);
  4738. }
  4739. sum = (10 - (sum % 10)) % 10;
  4740. return sum + '' === value.charAt(length - 1);
  4741. }
  4742. };
  4743. }(window.jQuery));
  4744. ;(function($) {
  4745. $.fn.bootstrapValidator.i18n.ismn = $.extend($.fn.bootstrapValidator.i18n.ismn || {}, {
  4746. 'default': 'Please enter a valid ISMN number'
  4747. });
  4748. $.fn.bootstrapValidator.validators.ismn = {
  4749. /**
  4750. * Validate ISMN (International Standard Music Number)
  4751. * Examples:
  4752. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  4753. * - Invalid: 9790060115614
  4754. *
  4755. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  4756. * @param {BootstrapValidator} validator The validator plugin instance
  4757. * @param {jQuery} $field Field element
  4758. * @param {Object} options Can consist of the following keys:
  4759. * - message: The invalid message
  4760. * @returns {Boolean}
  4761. */
  4762. validate: function(validator, $field, options) {
  4763. var value = $field.val();
  4764. if (value === '') {
  4765. return true;
  4766. }
  4767. // Groups are separated by a hyphen or a space
  4768. var type;
  4769. switch (true) {
  4770. case /^M\d{9}$/.test(value):
  4771. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  4772. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  4773. type = 'ISMN10';
  4774. break;
  4775. case /^9790\d{9}$/.test(value):
  4776. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  4777. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  4778. type = 'ISMN13';
  4779. break;
  4780. default:
  4781. return false;
  4782. }
  4783. if ('ISMN10' === type) {
  4784. value = '9790' + value.substr(1);
  4785. }
  4786. // Replace all special characters except digits
  4787. value = value.replace(/[^0-9]/gi, '');
  4788. var length = value.length,
  4789. sum = 0,
  4790. weight = [1, 3];
  4791. for (var i = 0; i < length - 1; i++) {
  4792. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  4793. }
  4794. sum = 10 - sum % 10;
  4795. return (sum + '' === value.charAt(length - 1));
  4796. }
  4797. };
  4798. }(window.jQuery));
  4799. ;(function($) {
  4800. $.fn.bootstrapValidator.i18n.issn = $.extend($.fn.bootstrapValidator.i18n.issn || {}, {
  4801. 'default': 'Please enter a valid ISSN number'
  4802. });
  4803. $.fn.bootstrapValidator.validators.issn = {
  4804. /**
  4805. * Validate ISSN (International Standard Serial Number)
  4806. * Examples:
  4807. * - Valid: 0378-5955, 0024-9319, 0032-1478
  4808. * - Invalid: 0032-147X
  4809. *
  4810. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  4811. * @param {BootstrapValidator} validator The validator plugin instance
  4812. * @param {jQuery} $field Field element
  4813. * @param {Object} options Can consist of the following keys:
  4814. * - message: The invalid message
  4815. * @returns {Boolean}
  4816. */
  4817. validate: function(validator, $field, options) {
  4818. var value = $field.val();
  4819. if (value === '') {
  4820. return true;
  4821. }
  4822. // Groups are separated by a hyphen or a space
  4823. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  4824. return false;
  4825. }
  4826. // Replace all special characters except digits and X
  4827. value = value.replace(/[^0-9X]/gi, '');
  4828. var chars = value.split(''),
  4829. length = chars.length,
  4830. sum = 0;
  4831. if (chars[7] === 'X') {
  4832. chars[7] = 10;
  4833. }
  4834. for (var i = 0; i < length; i++) {
  4835. sum += parseInt(chars[i], 10) * (8 - i);
  4836. }
  4837. return (sum % 11 === 0);
  4838. }
  4839. };
  4840. }(window.jQuery));
  4841. ;(function($) {
  4842. $.fn.bootstrapValidator.i18n.keywordColor = $.extend($.fn.bootstrapValidator.i18n.keywordColor || {}, {
  4843. 'default': 'Please enter a valid color keyword'
  4844. });
  4845. $.fn.bootstrapValidator.validators.keywordColor = {
  4846. /**
  4847. * Return true if the input value is a valid keyword color
  4848. *
  4849. * @param {BootstrapValidator} validator The validator plugin instance
  4850. * @param {jQuery} $field Field element
  4851. * @param {Object} options Can consist of the following keys:
  4852. * - message: The invalid message
  4853. * @returns {Boolean}
  4854. */
  4855. validate: function(validator, $field, options) {
  4856. var value = $field.val();
  4857. var colorKeywords = ["transparent", "aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];
  4858. if (value === '') {
  4859. return true;
  4860. }
  4861. return $.inArray(value, colorKeywords) >= 0;
  4862. }
  4863. };
  4864. }(window.jQuery));
  4865. ;(function($) {
  4866. $.fn.bootstrapValidator.i18n.lessThan = $.extend($.fn.bootstrapValidator.i18n.lessThan || {}, {
  4867. 'default': 'Please enter a value less than or equal to %s',
  4868. notInclusive: 'Please enter a value less than %s'
  4869. });
  4870. $.fn.bootstrapValidator.validators.lessThan = {
  4871. html5Attributes: {
  4872. message: 'message',
  4873. value: 'value',
  4874. inclusive: 'inclusive'
  4875. },
  4876. enableByHtml5: function($field) {
  4877. var type = $field.attr('type'),
  4878. max = $field.attr('max');
  4879. if (max && type !== 'date') {
  4880. return {
  4881. value: max
  4882. };
  4883. }
  4884. return false;
  4885. },
  4886. /**
  4887. * Return true if the input value is less than or equal to given number
  4888. *
  4889. * @param {BootstrapValidator} validator The validator plugin instance
  4890. * @param {jQuery} $field Field element
  4891. * @param {Object} options Can consist of the following keys:
  4892. * - value: The number used to compare to. It can be
  4893. * - A number
  4894. * - Name of field which its value defines the number
  4895. * - Name of callback function that returns the number
  4896. * - A callback function that returns the number
  4897. *
  4898. * - inclusive [optional]: Can be true or false. Default is true
  4899. * - message: The invalid message
  4900. * @returns {Boolean|Object}
  4901. */
  4902. validate: function(validator, $field, options) {
  4903. var value = $field.val();
  4904. if (value === '') {
  4905. return true;
  4906. }
  4907. if (!$.isNumeric(value)) {
  4908. return false;
  4909. }
  4910. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
  4911. value = parseFloat(value);
  4912. return (options.inclusive === true || options.inclusive === undefined)
  4913. ? {
  4914. valid: value <= compareTo,
  4915. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan['default'], compareTo)
  4916. }
  4917. : {
  4918. valid: value < compareTo,
  4919. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan.notInclusive, compareTo)
  4920. };
  4921. }
  4922. };
  4923. }(window.jQuery));
  4924. ;(function($) {
  4925. $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
  4926. 'default': 'Please enter a valid MAC address'
  4927. });
  4928. $.fn.bootstrapValidator.validators.mac = {
  4929. /**
  4930. * Return true if the input value is a MAC address.
  4931. *
  4932. * @param {BootstrapValidator} validator The validator plugin instance
  4933. * @param {jQuery} $field Field element
  4934. * @param {Object} options Can consist of the following keys:
  4935. * - message: The invalid message
  4936. * @returns {Boolean}
  4937. */
  4938. validate: function(validator, $field, options) {
  4939. var value = $field.val();
  4940. if (value === '') {
  4941. return true;
  4942. }
  4943. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  4944. }
  4945. };
  4946. }(window.jQuery));
  4947. ;(function($) {
  4948. $.fn.bootstrapValidator.i18n.meid = $.extend($.fn.bootstrapValidator.i18n.meid || {}, {
  4949. 'default': 'Please enter a valid MEID number'
  4950. });
  4951. $.fn.bootstrapValidator.validators.meid = {
  4952. /**
  4953. * Validate MEID (Mobile Equipment Identifier)
  4954. * Examples:
  4955. * - Valid: 293608736500703710, 29360-87365-0070-3710, AF0123450ABCDE, AF-012345-0ABCDE
  4956. * - Invalid: 2936087365007037101
  4957. *
  4958. * @see http://en.wikipedia.org/wiki/Mobile_equipment_identifier
  4959. * @param {BootstrapValidator} validator The validator plugin instance
  4960. * @param {jQuery} $field Field element
  4961. * @param {Object} options Can consist of the following keys:
  4962. * - message: The invalid message
  4963. * @returns {Boolean}
  4964. */
  4965. validate: function(validator, $field, options) {
  4966. var value = $field.val();
  4967. if (value === '') {
  4968. return true;
  4969. }
  4970. switch (true) {
  4971. // 14 digit hex representation (no check digit)
  4972. case /^[0-9A-F]{15}$/i.test(value):
  4973. // 14 digit hex representation + dashes or spaces (no check digit)
  4974. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}[- ][0-9A-F]$/i.test(value):
  4975. // 18 digit decimal representation (no check digit)
  4976. case /^\d{19}$/.test(value):
  4977. // 18 digit decimal representation + dashes or spaces (no check digit)
  4978. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}[- ]\d$/.test(value):
  4979. // Grab the check digit
  4980. var cd = value.charAt(value.length - 1);
  4981. // Strip any non-hex chars
  4982. value = value.replace(/[- ]/g, '');
  4983. // If it's all digits, luhn base 10 is used
  4984. if (value.match(/^\d*$/i)) {
  4985. return $.fn.bootstrapValidator.helpers.luhn(value);
  4986. }
  4987. // Strip the check digit
  4988. value = value.slice(0, -1);
  4989. // Get every other char, and double it
  4990. var cdCalc = '';
  4991. for (var i = 1; i <= 13; i += 2) {
  4992. cdCalc += (parseInt(value.charAt(i), 16) * 2).toString(16);
  4993. }
  4994. // Get the sum of each char in the string
  4995. var sum = 0;
  4996. for (i = 0; i < cdCalc.length; i++) {
  4997. sum += parseInt(cdCalc.charAt(i), 16);
  4998. }
  4999. // If the last digit of the calc is 0, the check digit is 0
  5000. return (sum % 10 === 0)
  5001. ? (cd === '0')
  5002. // Subtract it from the next highest 10s number (64 goes to 70) and subtract the sum
  5003. // Double it and turn it into a hex char
  5004. : (cd === ((Math.floor((sum + 10) / 10) * 10 - sum) * 2).toString(16));
  5005. // 14 digit hex representation (no check digit)
  5006. case /^[0-9A-F]{14}$/i.test(value):
  5007. // 14 digit hex representation + dashes or spaces (no check digit)
  5008. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}$/i.test(value):
  5009. // 18 digit decimal representation (no check digit)
  5010. case /^\d{18}$/.test(value):
  5011. // 18 digit decimal representation + dashes or spaces (no check digit)
  5012. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}$/.test(value):
  5013. return true;
  5014. default:
  5015. return false;
  5016. }
  5017. }
  5018. };
  5019. }(window.jQuery));
  5020. ;(function($) {
  5021. $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
  5022. 'default': 'Please enter a value'
  5023. });
  5024. $.fn.bootstrapValidator.validators.notEmpty = {
  5025. enableByHtml5: function($field) {
  5026. var required = $field.attr('required') + '';
  5027. return ('required' === required || 'true' === required);
  5028. },
  5029. /**
  5030. * Check if input value is empty or not
  5031. *
  5032. * @param {BootstrapValidator} validator The validator plugin instance
  5033. * @param {jQuery} $field Field element
  5034. * @param {Object} options
  5035. * @returns {Boolean}
  5036. */
  5037. validate: function(validator, $field, options) {
  5038. var type = $field.attr('type');
  5039. if ('radio' === type || 'checkbox' === type) {
  5040. return validator
  5041. .getFieldElements($field.attr('data-bv-field'))
  5042. .filter(':checked')
  5043. .length > 0;
  5044. }
  5045. if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  5046. return true;
  5047. }
  5048. return $.trim($field.val()) !== '';
  5049. }
  5050. };
  5051. }(window.jQuery));
  5052. ;(function($) {
  5053. $.fn.bootstrapValidator.i18n.numeric = $.extend($.fn.bootstrapValidator.i18n.numeric || {}, {
  5054. 'default': 'Please enter a valid float number'
  5055. });
  5056. $.fn.bootstrapValidator.validators.numeric = {
  5057. html5Attributes: {
  5058. message: 'message',
  5059. separator: 'separator'
  5060. },
  5061. enableByHtml5: function($field) {
  5062. return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
  5063. },
  5064. /**
  5065. * Validate decimal number
  5066. *
  5067. * @param {BootstrapValidator} validator The validator plugin instance
  5068. * @param {jQuery} $field Field element
  5069. * @param {Object} options Consist of key:
  5070. * - message: The invalid message
  5071. * - separator: The decimal separator. Can be "." (default), ","
  5072. * @returns {Boolean}
  5073. */
  5074. validate: function(validator, $field, options) {
  5075. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  5076. return false;
  5077. }
  5078. var value = $field.val();
  5079. if (value === '') {
  5080. return true;
  5081. }
  5082. var separator = options.separator || '.';
  5083. if (separator !== '.') {
  5084. value = value.replace(separator, '.');
  5085. }
  5086. return !isNaN(parseFloat(value)) && isFinite(value);
  5087. }
  5088. };
  5089. }(window.jQuery));
  5090. ;(function($) {
  5091. $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
  5092. 'default': 'Please enter a valid phone number',
  5093. countryNotSupported: 'The country code %s is not supported',
  5094. country: 'Please enter a valid phone number in %s',
  5095. countries: {
  5096. BR: 'Brazil',
  5097. CN: 'China',
  5098. CZ: 'Czech Republic',
  5099. DK: 'Denmark',
  5100. ES: 'Spain',
  5101. FR: 'France',
  5102. GB: 'United Kingdom',
  5103. MA: 'Morocco',
  5104. PK: 'Pakistan',
  5105. RO: 'Romania',
  5106. RU: 'Russia',
  5107. SK: 'Slovakia',
  5108. TH: 'Thailand',
  5109. US: 'USA',
  5110. VE: 'Venezuela'
  5111. }
  5112. });
  5113. $.fn.bootstrapValidator.validators.phone = {
  5114. html5Attributes: {
  5115. message: 'message',
  5116. country: 'country'
  5117. },
  5118. // The supported countries
  5119. COUNTRY_CODES: ['BR', 'CN', 'CZ', 'DK', 'ES', 'FR', 'GB', 'MA', 'PK', 'RO', 'RU', 'SK', 'TH', 'US', 'VE'],
  5120. /**
  5121. * Return true if the input value contains a valid phone number for the country
  5122. * selected in the options
  5123. *
  5124. * @param {BootstrapValidator} validator Validate plugin instance
  5125. * @param {jQuery} $field Field element
  5126. * @param {Object} options Consist of key:
  5127. * - message: The invalid message
  5128. * - country: The ISO-3166 country code. It can be
  5129. * - A country code
  5130. * - Name of field which its value defines the country code
  5131. * - Name of callback function that returns the country code
  5132. * - A callback function that returns the country code
  5133. *
  5134. * @returns {Boolean|Object}
  5135. */
  5136. validate: function(validator, $field, options) {
  5137. var value = $field.val();
  5138. if (value === '') {
  5139. return true;
  5140. }
  5141. var country = options.country;
  5142. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  5143. // Try to determine the country
  5144. country = validator.getDynamicOption($field, country);
  5145. }
  5146. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  5147. return {
  5148. valid: false,
  5149. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.phone.countryNotSupported, country)
  5150. };
  5151. }
  5152. var isValid = true;
  5153. switch (country.toUpperCase()) {
  5154. case 'BR':
  5155. // Test: http://regexr.com/399m1
  5156. value = $.trim(value);
  5157. 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);
  5158. break;
  5159. case 'CN':
  5160. // http://regexr.com/39dq4
  5161. value = $.trim(value);
  5162. 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);
  5163. break;
  5164. case 'CZ':
  5165. // Test: http://regexr.com/39hhl
  5166. isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  5167. break;
  5168. case 'DK':
  5169. // Mathing DK phone numbers with country code in 1 of 3 formats and an
  5170. // 8 digit phone number not starting with a 0 or 1. Can have 1 space
  5171. // between each character except inside the country code.
  5172. // Test: http://regex101.com/r/sS8fO4/1
  5173. value = $.trim(value);
  5174. isValid = (/^(\+45|0045|\(45\))?\s?[2-9](\s?\d){7}$/).test(value);
  5175. break;
  5176. case 'ES':
  5177. // http://regex101.com/r/rB9mA9/1
  5178. value = $.trim(value);
  5179. isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:9|6)(?:\d\D?){8}$/).test(value);
  5180. break;
  5181. case 'FR':
  5182. // http://regexr.com/39a2p
  5183. value = $.trim(value);
  5184. isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
  5185. break;
  5186. case 'GB':
  5187. // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  5188. // Test: http://regexr.com/38uhv
  5189. value = $.trim(value);
  5190. 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);
  5191. break;
  5192. case 'MA':
  5193. // http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
  5194. // Test: http://regexr.com/399n8
  5195. value = $.trim(value);
  5196. 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);
  5197. break;
  5198. case 'PK':
  5199. // http://regex101.com/r/yH8aV9/2
  5200. value = $.trim(value);
  5201. isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
  5202. break;
  5203. case 'RO':
  5204. // All mobile network and land line
  5205. // http://regexr.com/39fv1
  5206. 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);
  5207. break;
  5208. case 'RU':
  5209. // http://regex101.com/r/gW7yT5/5
  5210. isValid = (/^((8|\+7|007)[\-\.\/ ]?)?([\(\/\.]?\d{3}[\)\/\.]?[\-\.\/ ]?)?[\d\-\.\/ ]{7,10}$/g).test(value);
  5211. break;
  5212. case 'SK':
  5213. // Test: http://regexr.com/39hhl
  5214. isValid = /^(((00)([- ]?)|\+)(420)([- ]?))?((\d{3})([- ]?)){2}(\d{3})$/.test(value);
  5215. break;
  5216. case 'TH':
  5217. // http://regex101.com/r/vM5mZ4/2
  5218. isValid = (/^0\(?([6|8-9]{2})*-([0-9]{3})*-([0-9]{4})$/).test(value);
  5219. break;
  5220. case 'VE':
  5221. // http://regex101.com/r/eM2yY0/6
  5222. value = $.trim(value);
  5223. 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);
  5224. break;
  5225. case 'US':
  5226. /* falls through */
  5227. default:
  5228. // Make sure US phone numbers have 10 digits
  5229. // May start with 1, +1, or 1-; should discard
  5230. // Area code may be delimited with (), & sections may be delimited with . or -
  5231. // Test: http://regexr.com/38mqi
  5232. value = value.replace(/\D/g, '');
  5233. isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
  5234. break;
  5235. }
  5236. return {
  5237. valid: isValid,
  5238. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.phone.country, $.fn.bootstrapValidator.i18n.phone.countries[country])
  5239. };
  5240. }
  5241. };
  5242. }(window.jQuery));
  5243. ;(function($) {
  5244. $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
  5245. 'default': 'Please enter a value matching the pattern'
  5246. });
  5247. $.fn.bootstrapValidator.validators.regexp = {
  5248. html5Attributes: {
  5249. message: 'message',
  5250. regexp: 'regexp'
  5251. },
  5252. enableByHtml5: function($field) {
  5253. var pattern = $field.attr('pattern');
  5254. if (pattern) {
  5255. return {
  5256. regexp: pattern
  5257. };
  5258. }
  5259. return false;
  5260. },
  5261. /**
  5262. * Check if the element value matches given regular expression
  5263. *
  5264. * @param {BootstrapValidator} validator The validator plugin instance
  5265. * @param {jQuery} $field Field element
  5266. * @param {Object} options Consists of the following key:
  5267. * - regexp: The regular expression you need to check
  5268. * @returns {Boolean}
  5269. */
  5270. validate: function(validator, $field, options) {
  5271. var value = $field.val();
  5272. if (value === '') {
  5273. return true;
  5274. }
  5275. var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  5276. return regexp.test(value);
  5277. }
  5278. };
  5279. }(window.jQuery));
  5280. ;(function($) {
  5281. $.fn.bootstrapValidator.i18n.remote = $.extend($.fn.bootstrapValidator.i18n.remote || {}, {
  5282. 'default': 'Please enter a valid value'
  5283. });
  5284. $.fn.bootstrapValidator.validators.remote = {
  5285. html5Attributes: {
  5286. message: 'message',
  5287. name: 'name',
  5288. type: 'type',
  5289. url: 'url',
  5290. delay: 'delay'
  5291. },
  5292. /**
  5293. * Destroy the timer when destroying the bootstrapValidator (using validator.destroy() method)
  5294. */
  5295. destroy: function(validator, $field, options) {
  5296. if ($field.data('bv.remote.timer')) {
  5297. clearTimeout($field.data('bv.remote.timer'));
  5298. $field.removeData('bv.remote.timer');
  5299. }
  5300. },
  5301. /**
  5302. * Request a remote server to check the input value
  5303. *
  5304. * @param {BootstrapValidator} validator Plugin instance
  5305. * @param {jQuery} $field Field element
  5306. * @param {Object} options Can consist of the following keys:
  5307. * - url {String|Function}
  5308. * - type {String} [optional] Can be GET or POST (default)
  5309. * - data {Object|Function} [optional]: By default, it will take the value
  5310. * {
  5311. * <fieldName>: <fieldValue>
  5312. * }
  5313. * - delay
  5314. * - name {String} [optional]: Override the field name for the request.
  5315. * - message: The invalid message
  5316. * - headers: Additional headers
  5317. * @returns {Deferred}
  5318. */
  5319. validate: function(validator, $field, options) {
  5320. var value = $field.val(),
  5321. dfd = new $.Deferred();
  5322. if (value === '') {
  5323. dfd.resolve($field, 'remote', { valid: true });
  5324. return dfd;
  5325. }
  5326. var name = $field.attr('data-bv-field'),
  5327. data = options.data || {},
  5328. url = options.url,
  5329. type = options.type || 'GET',
  5330. headers = options.headers || {};
  5331. // Support dynamic data
  5332. if ('function' === typeof data) {
  5333. data = data.call(this, validator);
  5334. }
  5335. // Support dynamic url
  5336. if ('function' === typeof url) {
  5337. url = url.call(this, validator);
  5338. }
  5339. data[options.name || name] = value;
  5340. function runCallback() {
  5341. var xhr = $.ajax({
  5342. type: type,
  5343. headers: headers,
  5344. url: url,
  5345. dataType: 'json',
  5346. data: data
  5347. });
  5348. xhr.then(function(response) {
  5349. response.valid = response.valid === true || response.valid === 'true';
  5350. dfd.resolve($field, 'remote', response);
  5351. });
  5352. dfd.fail(function() {
  5353. xhr.abort();
  5354. });
  5355. return dfd;
  5356. }
  5357. if (options.delay) {
  5358. // Since the form might have multiple fields with the same name
  5359. // I have to attach the timer to the field element
  5360. if ($field.data('bv.remote.timer')) {
  5361. clearTimeout($field.data('bv.remote.timer'));
  5362. }
  5363. $field.data('bv.remote.timer', setTimeout(runCallback, options.delay));
  5364. return dfd;
  5365. } else {
  5366. return runCallback();
  5367. }
  5368. }
  5369. };
  5370. }(window.jQuery));
  5371. ;(function($) {
  5372. $.fn.bootstrapValidator.i18n.rgbColor = $.extend($.fn.bootstrapValidator.i18n.rgbColor || {}, {
  5373. 'default': 'Please enter a valid rgb color'
  5374. });
  5375. $.fn.bootstrapValidator.validators.rgbColor = {
  5376. /**
  5377. * Return true if the input value is a valid rgb() color
  5378. *
  5379. * @param {BootstrapValidator} validator The validator plugin instance
  5380. * @param {jQuery} $field Field element
  5381. * @param {Object} options Can consist of the following keys:
  5382. * - message: The invalid message
  5383. * @returns {Boolean}
  5384. */
  5385. validate: function(validator, $field, options) {
  5386. var value = $field.val();
  5387. 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*)\)$/;
  5388. var regexPercent = /^rgb\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){2}(\s*(\b(0?\d{1,2}|100)\b%)\s*)\)$/;
  5389. if (value === '') {
  5390. return true;
  5391. }
  5392. return regexInteger.test(value) || regexPercent.test(value);
  5393. }
  5394. };
  5395. }(window.jQuery));
  5396. ;(function($) {
  5397. $.fn.bootstrapValidator.i18n.rgbaColor = $.extend($.fn.bootstrapValidator.i18n.rgbaColor || {}, {
  5398. 'default': 'Please enter a valid rgb color'
  5399. });
  5400. $.fn.bootstrapValidator.validators.rgbaColor = {
  5401. /**
  5402. * Return true if the input value is a valid rgb() color
  5403. *
  5404. * @param {BootstrapValidator} validator The validator plugin instance
  5405. * @param {jQuery} $field Field element
  5406. * @param {Object} options Can consist of the following keys:
  5407. * - message: The invalid message
  5408. * @returns {Boolean}
  5409. */
  5410. validate: function(validator, $field, options) {
  5411. var value = $field.val();
  5412. 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*)\)$/;
  5413. var regexPercent = /^rgba\((\s*(\b(0?\d{1,2}|100)\b%)\s*,){3}(\s*(0?(\.\d+)?|1(\.0+)?)\s*)\)$/;
  5414. if (value === '') {
  5415. return true;
  5416. }
  5417. return regexInteger.test(value) || regexPercent.test(value);
  5418. }
  5419. };
  5420. }(window.jQuery));
  5421. ;(function($) {
  5422. $.fn.bootstrapValidator.i18n.rtn = $.extend($.fn.bootstrapValidator.i18n.rtn || {}, {
  5423. 'default': 'Please enter a valid RTN number'
  5424. });
  5425. $.fn.bootstrapValidator.validators.rtn = {
  5426. /**
  5427. * Validate a RTN (Routing transit number)
  5428. * Examples:
  5429. * - Valid: 021200025, 789456124
  5430. *
  5431. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  5432. * @param {BootstrapValidator} validator The validator plugin instance
  5433. * @param {jQuery} $field Field element
  5434. * @param {Object} options Can consist of the following keys:
  5435. * - message: The invalid message
  5436. * @returns {Boolean}
  5437. */
  5438. validate: function(validator, $field, options) {
  5439. var value = $field.val();
  5440. if (value === '') {
  5441. return true;
  5442. }
  5443. if (!/^\d{9}$/.test(value)) {
  5444. return false;
  5445. }
  5446. var sum = 0;
  5447. for (var i = 0; i < value.length; i += 3) {
  5448. sum += parseInt(value.charAt(i), 10) * 3
  5449. + parseInt(value.charAt(i + 1), 10) * 7
  5450. + parseInt(value.charAt(i + 2), 10);
  5451. }
  5452. return (sum !== 0 && sum % 10 === 0);
  5453. }
  5454. };
  5455. }(window.jQuery));
  5456. ;(function($) {
  5457. $.fn.bootstrapValidator.i18n.sedol = $.extend($.fn.bootstrapValidator.i18n.sedol || {}, {
  5458. 'default': 'Please enter a valid SEDOL number'
  5459. });
  5460. $.fn.bootstrapValidator.validators.sedol = {
  5461. /**
  5462. * Validate a SEDOL (Stock Exchange Daily Official List)
  5463. * Examples:
  5464. * - Valid: 0263494, B0WNLY7
  5465. *
  5466. * @see http://en.wikipedia.org/wiki/SEDOL
  5467. * @param {BootstrapValidator} validator The validator plugin instance
  5468. * @param {jQuery} $field Field element
  5469. * @param {Object} options Can consist of the following keys:
  5470. * - message: The invalid message
  5471. * @returns {Boolean}
  5472. */
  5473. validate: function(validator, $field, options) {
  5474. var value = $field.val();
  5475. if (value === '') {
  5476. return true;
  5477. }
  5478. value = value.toUpperCase();
  5479. if (!/^[0-9A-Z]{7}$/.test(value)) {
  5480. return false;
  5481. }
  5482. var sum = 0,
  5483. weight = [1, 3, 1, 7, 3, 9, 1],
  5484. length = value.length;
  5485. for (var i = 0; i < length - 1; i++) {
  5486. sum += weight[i] * parseInt(value.charAt(i), 36);
  5487. }
  5488. sum = (10 - sum % 10) % 10;
  5489. return sum + '' === value.charAt(length - 1);
  5490. }
  5491. };
  5492. }(window.jQuery));
  5493. ;(function($) {
  5494. $.fn.bootstrapValidator.i18n.siren = $.extend($.fn.bootstrapValidator.i18n.siren || {}, {
  5495. 'default': 'Please enter a valid SIREN number'
  5496. });
  5497. $.fn.bootstrapValidator.validators.siren = {
  5498. /**
  5499. * Check if a string is a siren number
  5500. *
  5501. * @param {BootstrapValidator} validator The validator plugin instance
  5502. * @param {jQuery} $field Field element
  5503. * @param {Object} options Consist of key:
  5504. * - message: The invalid message
  5505. * @returns {Boolean}
  5506. */
  5507. validate: function(validator, $field, options) {
  5508. var value = $field.val();
  5509. if (value === '') {
  5510. return true;
  5511. }
  5512. if (!/^\d{9}$/.test(value)) {
  5513. return false;
  5514. }
  5515. return $.fn.bootstrapValidator.helpers.luhn(value);
  5516. }
  5517. };
  5518. }(window.jQuery));
  5519. ;(function($) {
  5520. $.fn.bootstrapValidator.i18n.siret = $.extend($.fn.bootstrapValidator.i18n.siret || {}, {
  5521. 'default': 'Please enter a valid SIRET number'
  5522. });
  5523. $.fn.bootstrapValidator.validators.siret = {
  5524. /**
  5525. * Check if a string is a siret number
  5526. *
  5527. * @param {BootstrapValidator} validator The validator plugin instance
  5528. * @param {jQuery} $field Field element
  5529. * @param {Object} options Consist of key:
  5530. * - message: The invalid message
  5531. * @returns {Boolean}
  5532. */
  5533. validate: function(validator, $field, options) {
  5534. var value = $field.val();
  5535. if (value === '') {
  5536. return true;
  5537. }
  5538. var sum = 0,
  5539. length = value.length,
  5540. tmp;
  5541. for (var i = 0; i < length; i++) {
  5542. tmp = parseInt(value.charAt(i), 10);
  5543. if ((i % 2) === 0) {
  5544. tmp = tmp * 2;
  5545. if (tmp > 9) {
  5546. tmp -= 9;
  5547. }
  5548. }
  5549. sum += tmp;
  5550. }
  5551. return (sum % 10 === 0);
  5552. }
  5553. };
  5554. }(window.jQuery));
  5555. ;(function($) {
  5556. $.fn.bootstrapValidator.i18n.step = $.extend($.fn.bootstrapValidator.i18n.step || {}, {
  5557. 'default': 'Please enter a valid step of %s'
  5558. });
  5559. $.fn.bootstrapValidator.validators.step = {
  5560. html5Attributes: {
  5561. message: 'message',
  5562. base: 'baseValue',
  5563. step: 'step'
  5564. },
  5565. /**
  5566. * Return true if the input value is valid step one
  5567. *
  5568. * @param {BootstrapValidator} validator The validator plugin instance
  5569. * @param {jQuery} $field Field element
  5570. * @param {Object} options Can consist of the following keys:
  5571. * - baseValue: The base value
  5572. * - step: The step
  5573. * - message: The invalid message
  5574. * @returns {Boolean|Object}
  5575. */
  5576. validate: function(validator, $field, options) {
  5577. var value = $field.val();
  5578. if (value === '') {
  5579. return true;
  5580. }
  5581. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  5582. value = parseFloat(value);
  5583. if (!$.isNumeric(value)) {
  5584. return false;
  5585. }
  5586. var round = function(x, precision) {
  5587. var m = Math.pow(10, precision);
  5588. x = x * m;
  5589. var sign = (x > 0) | -(x < 0),
  5590. isHalf = (x % 1 === 0.5 * sign);
  5591. if (isHalf) {
  5592. return (Math.floor(x) + (sign > 0)) / m;
  5593. } else {
  5594. return Math.round(x) / m;
  5595. }
  5596. },
  5597. floatMod = function(x, y) {
  5598. if (y === 0.0) {
  5599. return 1.0;
  5600. }
  5601. var dotX = (x + '').split('.'),
  5602. dotY = (y + '').split('.'),
  5603. precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  5604. return round(x - y * Math.floor(x / y), precision);
  5605. };
  5606. var mod = floatMod(value - options.baseValue, options.step);
  5607. return {
  5608. valid: mod === 0.0 || mod === options.step,
  5609. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.step['default'], [options.step])
  5610. };
  5611. }
  5612. };
  5613. }(window.jQuery));
  5614. ;(function($) {
  5615. $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
  5616. 'default': 'Please enter only lowercase characters',
  5617. upper: 'Please enter only uppercase characters'
  5618. });
  5619. $.fn.bootstrapValidator.validators.stringCase = {
  5620. html5Attributes: {
  5621. message: 'message',
  5622. 'case': 'case'
  5623. },
  5624. /**
  5625. * Check if a string is a lower or upper case one
  5626. *
  5627. * @param {BootstrapValidator} validator The validator plugin instance
  5628. * @param {jQuery} $field Field element
  5629. * @param {Object} options Consist of key:
  5630. * - message: The invalid message
  5631. * - case: Can be 'lower' (default) or 'upper'
  5632. * @returns {Object}
  5633. */
  5634. validate: function(validator, $field, options) {
  5635. var value = $field.val();
  5636. if (value === '') {
  5637. return true;
  5638. }
  5639. var stringCase = (options['case'] || 'lower').toLowerCase();
  5640. return {
  5641. valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
  5642. message: options.message || (('upper' === stringCase) ? $.fn.bootstrapValidator.i18n.stringCase.upper : $.fn.bootstrapValidator.i18n.stringCase['default'])
  5643. };
  5644. }
  5645. };
  5646. }(window.jQuery));
  5647. ;(function($) {
  5648. $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
  5649. 'default': 'Please enter a value with valid length',
  5650. less: 'Please enter less than %s characters',
  5651. more: 'Please enter more than %s characters',
  5652. between: 'Please enter value between %s and %s characters long'
  5653. });
  5654. $.fn.bootstrapValidator.validators.stringLength = {
  5655. html5Attributes: {
  5656. message: 'message',
  5657. min: 'min',
  5658. max: 'max',
  5659. utf8bytes: 'utf8Bytes'
  5660. },
  5661. enableByHtml5: function($field) {
  5662. var options = {},
  5663. maxLength = $field.attr('maxlength'),
  5664. minLength = $field.attr('minlength');
  5665. if (maxLength) {
  5666. options.max = parseInt(maxLength, 10);
  5667. }
  5668. if (minLength) {
  5669. options.min = parseInt(minLength, 10);
  5670. }
  5671. return $.isEmptyObject(options) ? false : options;
  5672. },
  5673. /**
  5674. * Check if the length of element value is less or more than given number
  5675. *
  5676. * @param {BootstrapValidator} validator The validator plugin instance
  5677. * @param {jQuery} $field Field element
  5678. * @param {Object} options Consists of following keys:
  5679. * - min
  5680. * - max
  5681. * At least one of two keys is required
  5682. * The min, max keys define the number which the field value compares to. min, max can be
  5683. * - A number
  5684. * - Name of field which its value defines the number
  5685. * - Name of callback function that returns the number
  5686. * - A callback function that returns the number
  5687. *
  5688. * - message: The invalid message
  5689. * - utf8bytes: Evaluate string length in UTF-8 bytes, default to false
  5690. * @returns {Object}
  5691. */
  5692. validate: function(validator, $field, options) {
  5693. var value = $field.val();
  5694. if (value === '') {
  5695. return true;
  5696. }
  5697. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  5698. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  5699. // Credit to http://stackoverflow.com/a/23329386 (@lovasoa) for UTF-8 byte length code
  5700. utf8Length = function(str) {
  5701. var s = str.length;
  5702. for (var i = str.length - 1; i >= 0; i--) {
  5703. var code = str.charCodeAt(i);
  5704. if (code > 0x7f && code <= 0x7ff) {
  5705. s++;
  5706. } else if (code > 0x7ff && code <= 0xffff) {
  5707. s += 2;
  5708. }
  5709. if (code >= 0xDC00 && code <= 0xDFFF) {
  5710. i--;
  5711. }
  5712. }
  5713. return s;
  5714. },
  5715. length = options.utf8Bytes ? utf8Length(value) : value.length,
  5716. isValid = true,
  5717. message = options.message || $.fn.bootstrapValidator.i18n.stringLength['default'];
  5718. if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
  5719. isValid = false;
  5720. }
  5721. switch (true) {
  5722. case (!!min && !!max):
  5723. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
  5724. break;
  5725. case (!!min):
  5726. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more, parseInt(min, 10));
  5727. break;
  5728. case (!!max):
  5729. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.less, parseInt(max, 10));
  5730. break;
  5731. default:
  5732. break;
  5733. }
  5734. return { valid: isValid, message: message };
  5735. }
  5736. };
  5737. }(window.jQuery));
  5738. ;(function($) {
  5739. $.fn.bootstrapValidator.i18n.uri = $.extend($.fn.bootstrapValidator.i18n.uri || {}, {
  5740. 'default': 'Please enter a valid URI'
  5741. });
  5742. $.fn.bootstrapValidator.validators.uri = {
  5743. html5Attributes: {
  5744. message: 'message',
  5745. allowlocal: 'allowLocal',
  5746. protocol: 'protocol'
  5747. },
  5748. enableByHtml5: function($field) {
  5749. return ('url' === $field.attr('type'));
  5750. },
  5751. /**
  5752. * Return true if the input value is a valid URL
  5753. *
  5754. * @param {BootstrapValidator} validator The validator plugin instance
  5755. * @param {jQuery} $field Field element
  5756. * @param {Object} options
  5757. * - message: The error message
  5758. * - allowLocal: Allow the private and local network IP. Default to false
  5759. * - protocol: The protocols, separated by a comma. Default to "http, https, ftp"
  5760. * @returns {Boolean}
  5761. */
  5762. validate: function(validator, $field, options) {
  5763. var value = $field.val();
  5764. if (value === '') {
  5765. return true;
  5766. }
  5767. // Credit to https://gist.github.com/dperini/729294
  5768. //
  5769. // Regular Expression for URL validation
  5770. //
  5771. // Author: Diego Perini
  5772. // Updated: 2010/12/05
  5773. //
  5774. // the regular expression composed & commented
  5775. // could be easily tweaked for RFC compliance,
  5776. // it was expressly modified to fit & satisfy
  5777. // these test for an URL shortener:
  5778. //
  5779. // http://mathiasbynens.be/demo/url-regex
  5780. //
  5781. // Notes on possible differences from a standard/generic validation:
  5782. //
  5783. // - utf-8 char class take in consideration the full Unicode range
  5784. // - TLDs are mandatory unless `allowLocal` is true
  5785. // - protocols have been restricted to ftp, http and https only as requested
  5786. //
  5787. // Changes:
  5788. //
  5789. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  5790. // first and last IP address of each class is considered invalid
  5791. // (since they are broadcast/network addresses)
  5792. //
  5793. // - Added exclusion of private, reserved and/or local networks ranges
  5794. // unless `allowLocal` is true
  5795. //
  5796. // - Added possibility of choosing a custom protocol
  5797. //
  5798. var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
  5799. protocol = (options.protocol || 'http, https, ftp').split(',').join('|').replace(/\s/g, ''),
  5800. urlExp = new RegExp(
  5801. "^" +
  5802. // protocol identifier
  5803. "(?:(?:" + protocol + ")://)" +
  5804. // user:pass authentication
  5805. "(?:\\S+(?::\\S*)?@)?" +
  5806. "(?:" +
  5807. // IP address exclusion
  5808. // private & local networks
  5809. (allowLocal
  5810. ? ''
  5811. : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  5812. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  5813. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  5814. // IP address dotted notation octets
  5815. // excludes loopback network 0.0.0.0
  5816. // excludes reserved space >= 224.0.0.0
  5817. // excludes network & broadcast addresses
  5818. // (first & last IP address of each class)
  5819. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  5820. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  5821. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  5822. "|" +
  5823. // host name
  5824. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  5825. // domain name
  5826. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  5827. // TLD identifier
  5828. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  5829. // Allow intranet sites (no TLD) if `allowLocal` is true
  5830. (allowLocal ? '?' : '') +
  5831. ")" +
  5832. // port number
  5833. "(?::\\d{2,5})?" +
  5834. // resource path
  5835. "(?:/[^\\s]*)?" +
  5836. "$", "i"
  5837. );
  5838. return urlExp.test(value);
  5839. }
  5840. };
  5841. }(window.jQuery));
  5842. ;(function($) {
  5843. $.fn.bootstrapValidator.i18n.uuid = $.extend($.fn.bootstrapValidator.i18n.uuid || {}, {
  5844. 'default': 'Please enter a valid UUID number',
  5845. version: 'Please enter a valid UUID version %s number'
  5846. });
  5847. $.fn.bootstrapValidator.validators.uuid = {
  5848. html5Attributes: {
  5849. message: 'message',
  5850. version: 'version'
  5851. },
  5852. /**
  5853. * Return true if and only if the input value is a valid UUID string
  5854. *
  5855. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  5856. * @param {BootstrapValidator} validator The validator plugin instance
  5857. * @param {jQuery} $field Field element
  5858. * @param {Object} options Consist of key:
  5859. * - message: The invalid message
  5860. * - version: Can be 3, 4, 5, null
  5861. * @returns {Boolean|Object}
  5862. */
  5863. validate: function(validator, $field, options) {
  5864. var value = $field.val();
  5865. if (value === '') {
  5866. return true;
  5867. }
  5868. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  5869. var patterns = {
  5870. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  5871. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  5872. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  5873. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  5874. },
  5875. version = options.version ? (options.version + '') : 'all';
  5876. return {
  5877. valid: (null === patterns[version]) ? true : patterns[version].test(value),
  5878. message: options.version
  5879. ? $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.uuid.version, options.version)
  5880. : (options.message || $.fn.bootstrapValidator.i18n.uuid['default'])
  5881. };
  5882. }
  5883. };
  5884. }(window.jQuery));
  5885. ;(function($) {
  5886. $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
  5887. 'default': 'Please enter a valid VAT number',
  5888. countryNotSupported: 'The country code %s is not supported',
  5889. country: 'Please enter a valid VAT number in %s',
  5890. countries: {
  5891. AT: 'Austria',
  5892. BE: 'Belgium',
  5893. BG: 'Bulgaria',
  5894. BR: 'Brazil',
  5895. CH: 'Switzerland',
  5896. CY: 'Cyprus',
  5897. CZ: 'Czech Republic',
  5898. DE: 'Germany',
  5899. DK: 'Denmark',
  5900. EE: 'Estonia',
  5901. ES: 'Spain',
  5902. FI: 'Finland',
  5903. FR: 'France',
  5904. GB: 'United Kingdom',
  5905. GR: 'Greek',
  5906. EL: 'Greek',
  5907. HU: 'Hungary',
  5908. HR: 'Croatia',
  5909. IE: 'Ireland',
  5910. IS: 'Iceland',
  5911. IT: 'Italy',
  5912. LT: 'Lithuania',
  5913. LU: 'Luxembourg',
  5914. LV: 'Latvia',
  5915. MT: 'Malta',
  5916. NL: 'Netherlands',
  5917. NO: 'Norway',
  5918. PL: 'Poland',
  5919. PT: 'Portugal',
  5920. RO: 'Romania',
  5921. RU: 'Russia',
  5922. RS: 'Serbia',
  5923. SE: 'Sweden',
  5924. SI: 'Slovenia',
  5925. SK: 'Slovakia',
  5926. VE: 'Venezuela',
  5927. ZA: 'South Africa'
  5928. }
  5929. });
  5930. $.fn.bootstrapValidator.validators.vat = {
  5931. html5Attributes: {
  5932. message: 'message',
  5933. country: 'country'
  5934. },
  5935. // Supported country codes
  5936. COUNTRY_CODES: [
  5937. 'AT', 'BE', 'BG', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU',
  5938. 'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SE', 'SK', 'SI', 'VE',
  5939. 'ZA'
  5940. ],
  5941. /**
  5942. * Validate an European VAT number
  5943. *
  5944. * @param {BootstrapValidator} validator The validator plugin instance
  5945. * @param {jQuery} $field Field element
  5946. * @param {Object} options Consist of key:
  5947. * - message: The invalid message
  5948. * - country: The ISO 3166-1 country code. It can be
  5949. * - One of country code defined in COUNTRY_CODES
  5950. * - Name of field which its value defines the country code
  5951. * - Name of callback function that returns the country code
  5952. * - A callback function that returns the country code
  5953. * @returns {Boolean|Object}
  5954. */
  5955. validate: function(validator, $field, options) {
  5956. var value = $field.val();
  5957. if (value === '') {
  5958. return true;
  5959. }
  5960. var country = options.country;
  5961. if (!country) {
  5962. country = value.substr(0, 2);
  5963. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  5964. // Determine the country code
  5965. country = validator.getDynamicOption($field, country);
  5966. }
  5967. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  5968. return {
  5969. valid: false,
  5970. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.vat.countryNotSupported, country)
  5971. };
  5972. }
  5973. var method = ['_', country.toLowerCase()].join('');
  5974. return this[method](value)
  5975. ? true
  5976. : {
  5977. valid: false,
  5978. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vat.country, $.fn.bootstrapValidator.i18n.vat.countries[country.toUpperCase()])
  5979. };
  5980. },
  5981. // VAT validators
  5982. /**
  5983. * Validate Austrian VAT number
  5984. * Example:
  5985. * - Valid: ATU13585627
  5986. * - Invalid: ATU13585626
  5987. *
  5988. * @param {String} value VAT number
  5989. * @returns {Boolean}
  5990. */
  5991. _at: function(value) {
  5992. if (/^ATU[0-9]{8}$/.test(value)) {
  5993. value = value.substr(2);
  5994. }
  5995. if (!/^U[0-9]{8}$/.test(value)) {
  5996. return false;
  5997. }
  5998. value = value.substr(1);
  5999. var sum = 0,
  6000. weight = [1, 2, 1, 2, 1, 2, 1],
  6001. temp = 0;
  6002. for (var i = 0; i < 7; i++) {
  6003. temp = parseInt(value.charAt(i), 10) * weight[i];
  6004. if (temp > 9) {
  6005. temp = Math.floor(temp / 10) + temp % 10;
  6006. }
  6007. sum += temp;
  6008. }
  6009. sum = 10 - (sum + 4) % 10;
  6010. if (sum === 10) {
  6011. sum = 0;
  6012. }
  6013. return (sum + '' === value.substr(7, 1));
  6014. },
  6015. /**
  6016. * Validate Belgian VAT number
  6017. * Example:
  6018. * - Valid: BE0428759497
  6019. * - Invalid: BE431150351
  6020. *
  6021. * @param {String} value VAT number
  6022. * @returns {Boolean}
  6023. */
  6024. _be: function(value) {
  6025. if (/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  6026. value = value.substr(2);
  6027. }
  6028. if (!/^[0]{0,1}[0-9]{9}$/.test(value)) {
  6029. return false;
  6030. }
  6031. if (value.length === 9) {
  6032. value = '0' + value;
  6033. }
  6034. if (value.substr(1, 1) === '0') {
  6035. return false;
  6036. }
  6037. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  6038. return (sum % 97 === 0);
  6039. },
  6040. /**
  6041. * Validate Bulgarian VAT number
  6042. * Example:
  6043. * - Valid: BG175074752,
  6044. * BG7523169263, BG8032056031,
  6045. * BG7542011030,
  6046. * BG7111042925
  6047. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  6048. *
  6049. * @param {String} value VAT number
  6050. * @returns {Boolean}
  6051. */
  6052. _bg: function(value) {
  6053. if (/^BG[0-9]{9,10}$/.test(value)) {
  6054. value = value.substr(2);
  6055. }
  6056. if (!/^[0-9]{9,10}$/.test(value)) {
  6057. return false;
  6058. }
  6059. var sum = 0, i = 0;
  6060. // Legal entities
  6061. if (value.length === 9) {
  6062. for (i = 0; i < 8; i++) {
  6063. sum += parseInt(value.charAt(i), 10) * (i + 1);
  6064. }
  6065. sum = sum % 11;
  6066. if (sum === 10) {
  6067. sum = 0;
  6068. for (i = 0; i < 8; i++) {
  6069. sum += parseInt(value.charAt(i), 10) * (i + 3);
  6070. }
  6071. }
  6072. sum = sum % 10;
  6073. return (sum + '' === value.substr(8));
  6074. }
  6075. // Physical persons, foreigners and others
  6076. else if (value.length === 10) {
  6077. // Validate Bulgarian national identification numbers
  6078. var egn = function(value) {
  6079. // Check the birth date
  6080. var year = parseInt(value.substr(0, 2), 10) + 1900,
  6081. month = parseInt(value.substr(2, 2), 10),
  6082. day = parseInt(value.substr(4, 2), 10);
  6083. if (month > 40) {
  6084. year += 100;
  6085. month -= 40;
  6086. } else if (month > 20) {
  6087. year -= 100;
  6088. month -= 20;
  6089. }
  6090. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  6091. return false;
  6092. }
  6093. var sum = 0,
  6094. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  6095. for (var i = 0; i < 9; i++) {
  6096. sum += parseInt(value.charAt(i), 10) * weight[i];
  6097. }
  6098. sum = (sum % 11) % 10;
  6099. return (sum + '' === value.substr(9, 1));
  6100. },
  6101. // Validate Bulgarian personal number of a foreigner
  6102. pnf = function(value) {
  6103. var sum = 0,
  6104. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  6105. for (var i = 0; i < 9; i++) {
  6106. sum += parseInt(value.charAt(i), 10) * weight[i];
  6107. }
  6108. sum = sum % 10;
  6109. return (sum + '' === value.substr(9, 1));
  6110. },
  6111. // Finally, consider it as a VAT number
  6112. vat = function(value) {
  6113. var sum = 0,
  6114. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  6115. for (var i = 0; i < 9; i++) {
  6116. sum += parseInt(value.charAt(i), 10) * weight[i];
  6117. }
  6118. sum = 11 - sum % 11;
  6119. if (sum === 10) {
  6120. return false;
  6121. }
  6122. if (sum === 11) {
  6123. sum = 0;
  6124. }
  6125. return (sum + '' === value.substr(9, 1));
  6126. };
  6127. return (egn(value) || pnf(value) || vat(value));
  6128. }
  6129. return false;
  6130. },
  6131. /**
  6132. * Validate Brazilian VAT number (CNPJ)
  6133. *
  6134. * @param {String} value VAT number
  6135. * @returns {Boolean}
  6136. */
  6137. _br: function(value) {
  6138. if (value === '') {
  6139. return true;
  6140. }
  6141. var cnpj = value.replace(/[^\d]+/g, '');
  6142. if (cnpj === '' || cnpj.length !== 14) {
  6143. return false;
  6144. }
  6145. // Remove invalids CNPJs
  6146. if (cnpj === '00000000000000' || cnpj === '11111111111111' || cnpj === '22222222222222' ||
  6147. cnpj === '33333333333333' || cnpj === '44444444444444' || cnpj === '55555555555555' ||
  6148. cnpj === '66666666666666' || cnpj === '77777777777777' || cnpj === '88888888888888' ||
  6149. cnpj === '99999999999999')
  6150. {
  6151. return false;
  6152. }
  6153. // Validate verification digits
  6154. var length = cnpj.length - 2,
  6155. numbers = cnpj.substring(0, length),
  6156. digits = cnpj.substring(length),
  6157. sum = 0,
  6158. pos = length - 7;
  6159. for (var i = length; i >= 1; i--) {
  6160. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  6161. if (pos < 2) {
  6162. pos = 9;
  6163. }
  6164. }
  6165. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  6166. if (result !== parseInt(digits.charAt(0), 10)) {
  6167. return false;
  6168. }
  6169. length = length + 1;
  6170. numbers = cnpj.substring(0, length);
  6171. sum = 0;
  6172. pos = length - 7;
  6173. for (i = length; i >= 1; i--) {
  6174. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  6175. if (pos < 2) {
  6176. pos = 9;
  6177. }
  6178. }
  6179. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  6180. return (result === parseInt(digits.charAt(1), 10));
  6181. },
  6182. /**
  6183. * Validate Swiss VAT number
  6184. *
  6185. * @param {String} value VAT number
  6186. * @returns {Boolean}
  6187. */
  6188. _ch: function(value) {
  6189. if (/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  6190. value = value.substr(2);
  6191. }
  6192. if (!/^E[0-9]{9}(MWST)?$/.test(value)) {
  6193. return false;
  6194. }
  6195. value = value.substr(1);
  6196. var sum = 0,
  6197. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  6198. for (var i = 0; i < 8; i++) {
  6199. sum += parseInt(value.charAt(i), 10) * weight[i];
  6200. }
  6201. sum = 11 - sum % 11;
  6202. if (sum === 10) {
  6203. return false;
  6204. }
  6205. if (sum === 11) {
  6206. sum = 0;
  6207. }
  6208. return (sum + '' === value.substr(8, 1));
  6209. },
  6210. /**
  6211. * Validate Cypriot VAT number
  6212. * Examples:
  6213. * - Valid: CY10259033P
  6214. * - Invalid: CY10259033Z
  6215. *
  6216. * @param {String} value VAT number
  6217. * @returns {Boolean}
  6218. */
  6219. _cy: function(value) {
  6220. if (/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  6221. value = value.substr(2);
  6222. }
  6223. if (!/^[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  6224. return false;
  6225. }
  6226. // Do not allow to start with "12"
  6227. if (value.substr(0, 2) === '12') {
  6228. return false;
  6229. }
  6230. // Extract the next digit and multiply by the counter.
  6231. var sum = 0,
  6232. translation = {
  6233. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  6234. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  6235. };
  6236. for (var i = 0; i < 8; i++) {
  6237. var temp = parseInt(value.charAt(i), 10);
  6238. if (i % 2 === 0) {
  6239. temp = translation[temp + ''];
  6240. }
  6241. sum += temp;
  6242. }
  6243. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  6244. return (sum + '' === value.substr(8, 1));
  6245. },
  6246. /**
  6247. * Validate Czech Republic VAT number
  6248. * Can be:
  6249. * i) Legal entities (8 digit numbers)
  6250. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  6251. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  6252. *
  6253. * Examples:
  6254. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  6255. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  6256. *
  6257. * @param {String} value VAT number
  6258. * @returns {Boolean}
  6259. */
  6260. _cz: function(value) {
  6261. if (/^CZ[0-9]{8,10}$/.test(value)) {
  6262. value = value.substr(2);
  6263. }
  6264. if (!/^[0-9]{8,10}$/.test(value)) {
  6265. return false;
  6266. }
  6267. var sum = 0,
  6268. i = 0;
  6269. if (value.length === 8) {
  6270. // Do not allow to start with '9'
  6271. if (value.charAt(0) + '' === '9') {
  6272. return false;
  6273. }
  6274. sum = 0;
  6275. for (i = 0; i < 7; i++) {
  6276. sum += parseInt(value.charAt(i), 10) * (8 - i);
  6277. }
  6278. sum = 11 - sum % 11;
  6279. if (sum === 10) {
  6280. sum = 0;
  6281. }
  6282. if (sum === 11) {
  6283. sum = 1;
  6284. }
  6285. return (sum + '' === value.substr(7, 1));
  6286. } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  6287. sum = 0;
  6288. // Skip the first (which is 6)
  6289. for (i = 0; i < 7; i++) {
  6290. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  6291. }
  6292. sum = 11 - sum % 11;
  6293. if (sum === 10) {
  6294. sum = 0;
  6295. }
  6296. if (sum === 11) {
  6297. sum = 1;
  6298. }
  6299. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  6300. return (sum + '' === value.substr(8, 1));
  6301. } else if (value.length === 9 || value.length === 10) {
  6302. // Validate Czech birth number (Rodné číslo), which is also national identifier
  6303. var year = 1900 + parseInt(value.substr(0, 2), 10),
  6304. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  6305. day = parseInt(value.substr(4, 2), 10);
  6306. if (value.length === 9) {
  6307. if (year >= 1980) {
  6308. year -= 100;
  6309. }
  6310. if (year > 1953) {
  6311. return false;
  6312. }
  6313. } else if (year < 1954) {
  6314. year += 100;
  6315. }
  6316. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  6317. return false;
  6318. }
  6319. // Check that the birth date is not in the future
  6320. if (value.length === 10) {
  6321. var check = parseInt(value.substr(0, 9), 10) % 11;
  6322. if (year < 1985) {
  6323. check = check % 10;
  6324. }
  6325. return (check + '' === value.substr(9, 1));
  6326. }
  6327. return true;
  6328. }
  6329. return false;
  6330. },
  6331. /**
  6332. * Validate German VAT number
  6333. * Examples:
  6334. * - Valid: DE136695976
  6335. * - Invalid: DE136695978
  6336. *
  6337. * @param {String} value VAT number
  6338. * @returns {Boolean}
  6339. */
  6340. _de: function(value) {
  6341. if (/^DE[0-9]{9}$/.test(value)) {
  6342. value = value.substr(2);
  6343. }
  6344. if (!/^[0-9]{9}$/.test(value)) {
  6345. return false;
  6346. }
  6347. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  6348. },
  6349. /**
  6350. * Validate Danish VAT number
  6351. * Example:
  6352. * - Valid: DK13585628
  6353. * - Invalid: DK13585627
  6354. *
  6355. * @param {String} value VAT number
  6356. * @returns {Boolean}
  6357. */
  6358. _dk: function(value) {
  6359. if (/^DK[0-9]{8}$/.test(value)) {
  6360. value = value.substr(2);
  6361. }
  6362. if (!/^[0-9]{8}$/.test(value)) {
  6363. return false;
  6364. }
  6365. var sum = 0,
  6366. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  6367. for (var i = 0; i < 8; i++) {
  6368. sum += parseInt(value.charAt(i), 10) * weight[i];
  6369. }
  6370. return (sum % 11 === 0);
  6371. },
  6372. /**
  6373. * Validate Estonian VAT number
  6374. * Examples:
  6375. * - Valid: EE100931558, EE100594102
  6376. * - Invalid: EE100594103
  6377. *
  6378. * @param {String} value VAT number
  6379. * @returns {Boolean}
  6380. */
  6381. _ee: function(value) {
  6382. if (/^EE[0-9]{9}$/.test(value)) {
  6383. value = value.substr(2);
  6384. }
  6385. if (!/^[0-9]{9}$/.test(value)) {
  6386. return false;
  6387. }
  6388. var sum = 0,
  6389. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  6390. for (var i = 0; i < 9; i++) {
  6391. sum += parseInt(value.charAt(i), 10) * weight[i];
  6392. }
  6393. return (sum % 10 === 0);
  6394. },
  6395. /**
  6396. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  6397. * Can be:
  6398. * i) DNI (Documento nacional de identidad), for Spaniards
  6399. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  6400. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  6401. *
  6402. * Examples:
  6403. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  6404. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  6405. *
  6406. * @param {String} value VAT number
  6407. * @returns {Boolean}
  6408. */
  6409. _es: function(value) {
  6410. if (/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  6411. value = value.substr(2);
  6412. }
  6413. if (!/^[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  6414. return false;
  6415. }
  6416. var dni = function(value) {
  6417. var check = parseInt(value.substr(0, 8), 10);
  6418. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  6419. return (check + '' === value.substr(8, 1));
  6420. },
  6421. nie = function(value) {
  6422. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  6423. check = parseInt(check, 10);
  6424. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  6425. return (check + '' === value.substr(8, 1));
  6426. },
  6427. cif = function(value) {
  6428. var first = value.charAt(0), check;
  6429. if ('KLM'.indexOf(first) !== -1) {
  6430. // K: Spanish younger than 14 year old
  6431. // L: Spanish living outside Spain without DNI
  6432. // M: Granted the tax to foreigners who have no NIE
  6433. check = parseInt(value.substr(1, 8), 10);
  6434. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  6435. return (check + '' === value.substr(8, 1));
  6436. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  6437. var sum = 0,
  6438. weight = [2, 1, 2, 1, 2, 1, 2],
  6439. temp = 0;
  6440. for (var i = 0; i < 7; i++) {
  6441. temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  6442. if (temp > 9) {
  6443. temp = Math.floor(temp / 10) + temp % 10;
  6444. }
  6445. sum += temp;
  6446. }
  6447. sum = 10 - sum % 10;
  6448. return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  6449. }
  6450. return false;
  6451. };
  6452. var first = value.charAt(0);
  6453. if (/^[0-9]$/.test(first)) {
  6454. return dni(value);
  6455. } else if (/^[XYZ]$/.test(first)) {
  6456. return nie(value);
  6457. } else {
  6458. return cif(value);
  6459. }
  6460. },
  6461. /**
  6462. * Validate Finnish VAT number
  6463. * Examples:
  6464. * - Valid: FI20774740
  6465. * - Invalid: FI20774741
  6466. *
  6467. * @param {String} value VAT number
  6468. * @returns {Boolean}
  6469. */
  6470. _fi: function(value) {
  6471. if (/^FI[0-9]{8}$/.test(value)) {
  6472. value = value.substr(2);
  6473. }
  6474. if (!/^[0-9]{8}$/.test(value)) {
  6475. return false;
  6476. }
  6477. var sum = 0,
  6478. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  6479. for (var i = 0; i < 8; i++) {
  6480. sum += parseInt(value.charAt(i), 10) * weight[i];
  6481. }
  6482. return (sum % 11 === 0);
  6483. },
  6484. /**
  6485. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  6486. * It's constructed by a SIREN number, prefixed by two characters.
  6487. *
  6488. * Examples:
  6489. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  6490. * - Invalid: FR84323140391
  6491. *
  6492. * @param {String} value VAT number
  6493. * @returns {Boolean}
  6494. */
  6495. _fr: function(value) {
  6496. if (/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  6497. value = value.substr(2);
  6498. }
  6499. if (!/^[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  6500. return false;
  6501. }
  6502. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  6503. return false;
  6504. }
  6505. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  6506. // First two characters are digits
  6507. return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  6508. } else {
  6509. // The first characters cann't be O and I
  6510. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  6511. check;
  6512. // First one is digit
  6513. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  6514. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  6515. } else {
  6516. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  6517. }
  6518. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  6519. }
  6520. },
  6521. /**
  6522. * Validate United Kingdom VAT number
  6523. * Example:
  6524. * - Valid: GB980780684
  6525. * - Invalid: GB802311781
  6526. *
  6527. * @param {String} value VAT number
  6528. * @returns {Boolean}
  6529. */
  6530. _gb: function(value) {
  6531. if (/^GB[0-9]{9}$/.test(value) /* Standard */
  6532. || /^GB[0-9]{12}$/.test(value) /* Branches */
  6533. || /^GBGD[0-9]{3}$/.test(value) /* Government department */
  6534. || /^GBHA[0-9]{3}$/.test(value) /* Health authority */
  6535. || /^GB(GD|HA)8888[0-9]{5}$/.test(value))
  6536. {
  6537. value = value.substr(2);
  6538. }
  6539. if (!/^[0-9]{9}$/.test(value)
  6540. && !/^[0-9]{12}$/.test(value)
  6541. && !/^GD[0-9]{3}$/.test(value)
  6542. && !/^HA[0-9]{3}$/.test(value)
  6543. && !/^(GD|HA)8888[0-9]{5}$/.test(value))
  6544. {
  6545. return false;
  6546. }
  6547. var length = value.length;
  6548. if (length === 5) {
  6549. var firstTwo = value.substr(0, 2),
  6550. lastThree = parseInt(value.substr(2), 10);
  6551. return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  6552. } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  6553. if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  6554. || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  6555. {
  6556. return false;
  6557. }
  6558. return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  6559. } else if (length === 9 || length === 12) {
  6560. var sum = 0,
  6561. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  6562. for (var i = 0; i < 9; i++) {
  6563. sum += parseInt(value.charAt(i), 10) * weight[i];
  6564. }
  6565. sum = sum % 97;
  6566. if (parseInt(value.substr(0, 3), 10) >= 100) {
  6567. return (sum === 0 || sum === 42 || sum === 55);
  6568. } else {
  6569. return (sum === 0);
  6570. }
  6571. }
  6572. return true;
  6573. },
  6574. /**
  6575. * Validate Greek VAT number
  6576. * Examples:
  6577. * - Valid: GR023456780, EL094259216
  6578. * - Invalid: EL123456781
  6579. *
  6580. * @param {String} value VAT number
  6581. * @returns {Boolean}
  6582. */
  6583. _gr: function(value) {
  6584. if (/^(GR|EL)[0-9]{9}$/.test(value)) {
  6585. value = value.substr(2);
  6586. }
  6587. if (!/^[0-9]{9}$/.test(value)) {
  6588. return false;
  6589. }
  6590. if (value.length === 8) {
  6591. value = '0' + value;
  6592. }
  6593. var sum = 0,
  6594. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  6595. for (var i = 0; i < 8; i++) {
  6596. sum += parseInt(value.charAt(i), 10) * weight[i];
  6597. }
  6598. sum = (sum % 11) % 10;
  6599. return (sum + '' === value.substr(8, 1));
  6600. },
  6601. // EL is traditionally prefix of Greek VAT numbers
  6602. _el: function(value) {
  6603. return this._gr(value);
  6604. },
  6605. /**
  6606. * Validate Hungarian VAT number
  6607. * Examples:
  6608. * - Valid: HU12892312
  6609. * - Invalid: HU12892313
  6610. *
  6611. * @param {String} value VAT number
  6612. * @returns {Boolean}
  6613. */
  6614. _hu: function(value) {
  6615. if (/^HU[0-9]{8}$/.test(value)) {
  6616. value = value.substr(2);
  6617. }
  6618. if (!/^[0-9]{8}$/.test(value)) {
  6619. return false;
  6620. }
  6621. var sum = 0,
  6622. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  6623. for (var i = 0; i < 8; i++) {
  6624. sum += parseInt(value.charAt(i), 10) * weight[i];
  6625. }
  6626. return (sum % 10 === 0);
  6627. },
  6628. /**
  6629. * Validate Croatian VAT number
  6630. * Examples:
  6631. * - Valid: HR33392005961
  6632. * - Invalid: HR33392005962
  6633. *
  6634. * @param {String} value VAT number
  6635. * @returns {Boolean}
  6636. */
  6637. _hr: function(value) {
  6638. if (/^HR[0-9]{11}$/.test(value)) {
  6639. value = value.substr(2);
  6640. }
  6641. if (!/^[0-9]{11}$/.test(value)) {
  6642. return false;
  6643. }
  6644. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  6645. },
  6646. /**
  6647. * Validate Irish VAT number
  6648. * Examples:
  6649. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  6650. * - Invalid: IE8D79738J
  6651. *
  6652. * @param {String} value VAT number
  6653. * @returns {Boolean}
  6654. */
  6655. _ie: function(value) {
  6656. if (/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  6657. value = value.substr(2);
  6658. }
  6659. if (!/^[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  6660. return false;
  6661. }
  6662. var getCheckDigit = function(value) {
  6663. while (value.length < 7) {
  6664. value = '0' + value;
  6665. }
  6666. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  6667. sum = 0;
  6668. for (var i = 0; i < 7; i++) {
  6669. sum += parseInt(value.charAt(i), 10) * (8 - i);
  6670. }
  6671. sum += 9 * alphabet.indexOf(value.substr(7));
  6672. return alphabet[sum % 23];
  6673. };
  6674. // The first 7 characters are digits
  6675. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  6676. // New system
  6677. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  6678. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  6679. // Old system
  6680. return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  6681. }
  6682. return true;
  6683. },
  6684. /**
  6685. * Validate Icelandic VAT (VSK) number
  6686. * Examples:
  6687. * - Valid: 12345, 123456
  6688. * - Invalid: 1234567
  6689. *
  6690. * @params {String} value VAT number
  6691. * @returns {Boolean}
  6692. */
  6693. _is: function(value) {
  6694. if (/^IS[0-9]{5,6}$/.test(value)) {
  6695. value = value.substr(2);
  6696. }
  6697. return /^[0-9]{5,6}$/.test(value);
  6698. },
  6699. /**
  6700. * Validate Italian VAT number, which consists of 11 digits.
  6701. * - First 7 digits are a company identifier
  6702. * - Next 3 are the province of residence
  6703. * - The last one is a check digit
  6704. *
  6705. * Examples:
  6706. * - Valid: IT00743110157
  6707. * - Invalid: IT00743110158
  6708. *
  6709. * @param {String} value VAT number
  6710. * @returns {Boolean}
  6711. */
  6712. _it: function(value) {
  6713. if (/^IT[0-9]{11}$/.test(value)) {
  6714. value = value.substr(2);
  6715. }
  6716. if (!/^[0-9]{11}$/.test(value)) {
  6717. return false;
  6718. }
  6719. if (parseInt(value.substr(0, 7), 10) === 0) {
  6720. return false;
  6721. }
  6722. var lastThree = parseInt(value.substr(7, 3), 10);
  6723. if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  6724. return false;
  6725. }
  6726. return $.fn.bootstrapValidator.helpers.luhn(value);
  6727. },
  6728. /**
  6729. * Validate Lithuanian VAT number
  6730. * It can be:
  6731. * - 9 digits, for legal entities
  6732. * - 12 digits, for temporarily registered taxpayers
  6733. *
  6734. * Examples:
  6735. * - Valid: LT119511515, LT100001919017, LT100004801610
  6736. * - Invalid: LT100001919018
  6737. *
  6738. * @param {String} value VAT number
  6739. * @returns {Boolean}
  6740. */
  6741. _lt: function(value) {
  6742. if (/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  6743. value = value.substr(2);
  6744. }
  6745. if (!/^([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  6746. return false;
  6747. }
  6748. var length = value.length,
  6749. sum = 0,
  6750. i;
  6751. for (i = 0; i < length - 1; i++) {
  6752. sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  6753. }
  6754. var check = sum % 11;
  6755. if (check === 10) {
  6756. sum = 0;
  6757. for (i = 0; i < length - 1; i++) {
  6758. sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  6759. }
  6760. }
  6761. check = check % 11 % 10;
  6762. return (check + '' === value.charAt(length - 1));
  6763. },
  6764. /**
  6765. * Validate Luxembourg VAT number
  6766. * Examples:
  6767. * - Valid: LU15027442
  6768. * - Invalid: LU15027443
  6769. *
  6770. * @param {String} value VAT number
  6771. * @returns {Boolean}
  6772. */
  6773. _lu: function(value) {
  6774. if (/^LU[0-9]{8}$/.test(value)) {
  6775. value = value.substr(2);
  6776. }
  6777. if (!/^[0-9]{8}$/.test(value)) {
  6778. return false;
  6779. }
  6780. return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  6781. },
  6782. /**
  6783. * Validate Latvian VAT number
  6784. * Examples:
  6785. * - Valid: LV40003521600, LV16117519997
  6786. * - Invalid: LV40003521601, LV16137519997
  6787. *
  6788. * @param {String} value VAT number
  6789. * @returns {Boolean}
  6790. */
  6791. _lv: function(value) {
  6792. if (/^LV[0-9]{11}$/.test(value)) {
  6793. value = value.substr(2);
  6794. }
  6795. if (!/^[0-9]{11}$/.test(value)) {
  6796. return false;
  6797. }
  6798. var first = parseInt(value.charAt(0), 10),
  6799. sum = 0,
  6800. weight = [],
  6801. i,
  6802. length = value.length;
  6803. if (first > 3) {
  6804. // Legal entity
  6805. sum = 0;
  6806. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  6807. for (i = 0; i < length; i++) {
  6808. sum += parseInt(value.charAt(i), 10) * weight[i];
  6809. }
  6810. sum = sum % 11;
  6811. return (sum === 3);
  6812. } else {
  6813. // Check birth date
  6814. var day = parseInt(value.substr(0, 2), 10),
  6815. month = parseInt(value.substr(2, 2), 10),
  6816. year = parseInt(value.substr(4, 2), 10);
  6817. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  6818. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  6819. return false;
  6820. }
  6821. // Check personal code
  6822. sum = 0;
  6823. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  6824. for (i = 0; i < length - 1; i++) {
  6825. sum += parseInt(value.charAt(i), 10) * weight[i];
  6826. }
  6827. sum = (sum + 1) % 11 % 10;
  6828. return (sum + '' === value.charAt(length - 1));
  6829. }
  6830. },
  6831. /**
  6832. * Validate Maltese VAT number
  6833. * Examples:
  6834. * - Valid: MT11679112
  6835. * - Invalid: MT11679113
  6836. *
  6837. * @param {String} value VAT number
  6838. * @returns {Boolean}
  6839. */
  6840. _mt: function(value) {
  6841. if (/^MT[0-9]{8}$/.test(value)) {
  6842. value = value.substr(2);
  6843. }
  6844. if (!/^[0-9]{8}$/.test(value)) {
  6845. return false;
  6846. }
  6847. var sum = 0,
  6848. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  6849. for (var i = 0; i < 8; i++) {
  6850. sum += parseInt(value.charAt(i), 10) * weight[i];
  6851. }
  6852. return (sum % 37 === 0);
  6853. },
  6854. /**
  6855. * Validate Dutch VAT number
  6856. * Examples:
  6857. * - Valid: NL004495445B01
  6858. * - Invalid: NL123456789B90
  6859. *
  6860. * @param {String} value VAT number
  6861. * @returns {Boolean}
  6862. */
  6863. _nl: function(value) {
  6864. if (/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  6865. value = value.substr(2);
  6866. }
  6867. if (!/^[0-9]{9}B[0-9]{2}$/.test(value)) {
  6868. return false;
  6869. }
  6870. var sum = 0,
  6871. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  6872. for (var i = 0; i < 8; i++) {
  6873. sum += parseInt(value.charAt(i), 10) * weight[i];
  6874. }
  6875. sum = sum % 11;
  6876. if (sum > 9) {
  6877. sum = 0;
  6878. }
  6879. return (sum + '' === value.substr(8, 1));
  6880. },
  6881. /**
  6882. * Validate Norwegian VAT number
  6883. *
  6884. * @see http://www.brreg.no/english/coordination/number.html
  6885. * @param {String} value VAT number
  6886. * @returns {Boolean}
  6887. */
  6888. _no: function(value) {
  6889. if (/^NO[0-9]{9}$/.test(value)) {
  6890. value = value.substr(2);
  6891. }
  6892. if (!/^[0-9]{9}$/.test(value)) {
  6893. return false;
  6894. }
  6895. var sum = 0,
  6896. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  6897. for (var i = 0; i < 8; i++) {
  6898. sum += parseInt(value.charAt(i), 10) * weight[i];
  6899. }
  6900. sum = 11 - sum % 11;
  6901. if (sum === 11) {
  6902. sum = 0;
  6903. }
  6904. return (sum + '' === value.substr(8, 1));
  6905. },
  6906. /**
  6907. * Validate Polish VAT number
  6908. * Examples:
  6909. * - Valid: PL8567346215
  6910. * - Invalid: PL8567346216
  6911. *
  6912. * @param {String} value VAT number
  6913. * @returns {Boolean}
  6914. */
  6915. _pl: function(value) {
  6916. if (/^PL[0-9]{10}$/.test(value)) {
  6917. value = value.substr(2);
  6918. }
  6919. if (!/^[0-9]{10}$/.test(value)) {
  6920. return false;
  6921. }
  6922. var sum = 0,
  6923. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  6924. for (var i = 0; i < 10; i++) {
  6925. sum += parseInt(value.charAt(i), 10) * weight[i];
  6926. }
  6927. return (sum % 11 === 0);
  6928. },
  6929. /**
  6930. * Validate Portuguese VAT number
  6931. * Examples:
  6932. * - Valid: PT501964843
  6933. * - Invalid: PT501964842
  6934. *
  6935. * @param {String} value VAT number
  6936. * @returns {Boolean}
  6937. */
  6938. _pt: function(value) {
  6939. if (/^PT[0-9]{9}$/.test(value)) {
  6940. value = value.substr(2);
  6941. }
  6942. if (!/^[0-9]{9}$/.test(value)) {
  6943. return false;
  6944. }
  6945. var sum = 0,
  6946. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  6947. for (var i = 0; i < 8; i++) {
  6948. sum += parseInt(value.charAt(i), 10) * weight[i];
  6949. }
  6950. sum = 11 - sum % 11;
  6951. if (sum > 9) {
  6952. sum = 0;
  6953. }
  6954. return (sum + '' === value.substr(8, 1));
  6955. },
  6956. /**
  6957. * Validate Romanian VAT number
  6958. * Examples:
  6959. * - Valid: RO18547290
  6960. * - Invalid: RO18547291
  6961. *
  6962. * @param {String} value VAT number
  6963. * @returns {Boolean}
  6964. */
  6965. _ro: function(value) {
  6966. if (/^RO[1-9][0-9]{1,9}$/.test(value)) {
  6967. value = value.substr(2);
  6968. }
  6969. if (!/^[1-9][0-9]{1,9}$/.test(value)) {
  6970. return false;
  6971. }
  6972. var length = value.length,
  6973. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  6974. sum = 0;
  6975. for (var i = 0; i < length - 1; i++) {
  6976. sum += parseInt(value.charAt(i), 10) * weight[i];
  6977. }
  6978. sum = (10 * sum) % 11 % 10;
  6979. return (sum + '' === value.substr(length - 1, 1));
  6980. },
  6981. /**
  6982. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  6983. *
  6984. * @param {String} value VAT number
  6985. * @returns {Boolean}
  6986. */
  6987. _ru: function(value) {
  6988. if (/^RU([0-9]{10}|[0-9]{12})$/.test(value)) {
  6989. value = value.substr(2);
  6990. }
  6991. if (!/^([0-9]{10}|[0-9]{12})$/.test(value)) {
  6992. return false;
  6993. }
  6994. var i = 0;
  6995. if (value.length === 10) {
  6996. var sum = 0,
  6997. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  6998. for (i = 0; i < 10; i++) {
  6999. sum += parseInt(value.charAt(i), 10) * weight[i];
  7000. }
  7001. sum = sum % 11;
  7002. if (sum > 9) {
  7003. sum = sum % 10;
  7004. }
  7005. return (sum + '' === value.substr(9, 1));
  7006. } else if (value.length === 12) {
  7007. var sum1 = 0,
  7008. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  7009. sum2 = 0,
  7010. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  7011. for (i = 0; i < 11; i++) {
  7012. sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  7013. sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  7014. }
  7015. sum1 = sum1 % 11;
  7016. if (sum1 > 9) {
  7017. sum1 = sum1 % 10;
  7018. }
  7019. sum2 = sum2 % 11;
  7020. if (sum2 > 9) {
  7021. sum2 = sum2 % 10;
  7022. }
  7023. return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  7024. }
  7025. return false;
  7026. },
  7027. /**
  7028. * Validate Serbian VAT number
  7029. *
  7030. * @param {String} value VAT number
  7031. * @returns {Boolean}
  7032. */
  7033. _rs: function(value) {
  7034. if (/^RS[0-9]{9}$/.test(value)) {
  7035. value = value.substr(2);
  7036. }
  7037. if (!/^[0-9]{9}$/.test(value)) {
  7038. return false;
  7039. }
  7040. var sum = 10,
  7041. temp = 0;
  7042. for (var i = 0; i < 8; i++) {
  7043. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  7044. if (temp === 0) {
  7045. temp = 10;
  7046. }
  7047. sum = (2 * temp) % 11;
  7048. }
  7049. return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  7050. },
  7051. /**
  7052. * Validate Swedish VAT number
  7053. * Examples:
  7054. * - Valid: SE123456789701
  7055. * - Invalid: SE123456789101
  7056. *
  7057. * @param {String} value VAT number
  7058. * @returns {Boolean}
  7059. */
  7060. _se: function(value) {
  7061. if (/^SE[0-9]{10}01$/.test(value)) {
  7062. value = value.substr(2);
  7063. }
  7064. if (!/^[0-9]{10}01$/.test(value)) {
  7065. return false;
  7066. }
  7067. value = value.substr(0, 10);
  7068. return $.fn.bootstrapValidator.helpers.luhn(value);
  7069. },
  7070. /**
  7071. * Validate Slovenian VAT number
  7072. * Examples:
  7073. * - Valid: SI50223054
  7074. * - Invalid: SI50223055
  7075. *
  7076. * @param {String} value VAT number
  7077. * @returns {Boolean}
  7078. */
  7079. _si: function(value) {
  7080. if (/^SI[0-9]{8}$/.test(value)) {
  7081. value = value.substr(2);
  7082. }
  7083. if (!/^[0-9]{8}$/.test(value)) {
  7084. return false;
  7085. }
  7086. var sum = 0,
  7087. weight = [8, 7, 6, 5, 4, 3, 2];
  7088. for (var i = 0; i < 7; i++) {
  7089. sum += parseInt(value.charAt(i), 10) * weight[i];
  7090. }
  7091. sum = 11 - sum % 11;
  7092. if (sum === 10) {
  7093. sum = 0;
  7094. }
  7095. return (sum + '' === value.substr(7, 1));
  7096. },
  7097. /**
  7098. * Validate Slovak VAT number
  7099. * Examples:
  7100. * - Valid: SK2022749619
  7101. * - Invalid: SK2022749618
  7102. *
  7103. * @param {String} value VAT number
  7104. * @returns {Boolean}
  7105. */
  7106. _sk: function(value) {
  7107. if (/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  7108. value = value.substr(2);
  7109. }
  7110. if (!/^[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  7111. return false;
  7112. }
  7113. return (parseInt(value, 10) % 11 === 0);
  7114. },
  7115. /**
  7116. * Validate Venezuelan VAT number (RIF)
  7117. * Examples:
  7118. * - Valid: VEJ309272292, VEV242818101, VEJ000126518, VEJ000458324, J309272292, V242818101, J000126518, J000458324
  7119. * - Invalid: VEJ309272293, VEV242818100, J000126519, J000458323
  7120. *
  7121. * @param {String} value VAT number
  7122. * @returns {Boolean}
  7123. */
  7124. _ve: function(value) {
  7125. if (/^VE[VEJPG][0-9]{9}$/.test(value)) {
  7126. value = value.substr(2);
  7127. }
  7128. if (!/^[VEJPG][0-9]{9}$/.test(value)) {
  7129. return false;
  7130. }
  7131. var types = {
  7132. 'V': 4,
  7133. 'E': 8,
  7134. 'J': 12,
  7135. 'P': 16,
  7136. 'G': 20
  7137. },
  7138. sum = types[value.charAt(0)],
  7139. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  7140. for (var i = 0; i < 8; i++) {
  7141. sum += parseInt(value.charAt(i + 1), 10) * weight[i];
  7142. }
  7143. sum = 11 - sum % 11;
  7144. if (sum === 11 || sum === 10) {
  7145. sum = 0;
  7146. }
  7147. return (sum + '' === value.substr(9, 1));
  7148. },
  7149. /**
  7150. * Validate South African VAT number
  7151. * Examples:
  7152. * - Valid: 4012345678
  7153. * - Invalid: 40123456789, 3012345678
  7154. *
  7155. * @params {String} value VAT number
  7156. * @returns {Boolean}
  7157. */
  7158. _za: function(value) {
  7159. if (/^ZA4[0-9]{9}$/.test(value)) {
  7160. value = value.substr(2);
  7161. }
  7162. return /^4[0-9]{9}$/.test(value);
  7163. }
  7164. };
  7165. }(window.jQuery));
  7166. ;(function($) {
  7167. $.fn.bootstrapValidator.i18n.vin = $.extend($.fn.bootstrapValidator.i18n.vin || {}, {
  7168. 'default': 'Please enter a valid VIN number'
  7169. });
  7170. $.fn.bootstrapValidator.validators.vin = {
  7171. /**
  7172. * Validate an US VIN (Vehicle Identification Number)
  7173. *
  7174. * @param {BootstrapValidator} validator The validator plugin instance
  7175. * @param {jQuery} $field Field element
  7176. * @param {Object} options Consist of key:
  7177. * - message: The invalid message
  7178. * @returns {Boolean}
  7179. */
  7180. validate: function(validator, $field, options) {
  7181. var value = $field.val();
  7182. if (value === '') {
  7183. return true;
  7184. }
  7185. // Don't accept I, O, Q characters
  7186. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  7187. return false;
  7188. }
  7189. value = value.toUpperCase();
  7190. var chars = {
  7191. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  7192. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  7193. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  7194. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  7195. },
  7196. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  7197. sum = 0,
  7198. length = value.length;
  7199. for (var i = 0; i < length; i++) {
  7200. sum += chars[value.charAt(i) + ''] * weights[i];
  7201. }
  7202. var reminder = sum % 11;
  7203. if (reminder === 10) {
  7204. reminder = 'X';
  7205. }
  7206. return (reminder + '') === value.charAt(8);
  7207. }
  7208. };
  7209. }(window.jQuery));
  7210. ;(function($) {
  7211. $.fn.bootstrapValidator.i18n.zipCode = $.extend($.fn.bootstrapValidator.i18n.zipCode || {}, {
  7212. 'default': 'Please enter a valid postal code',
  7213. countryNotSupported: 'The country code %s is not supported',
  7214. country: 'Please enter a valid postal code in %s',
  7215. countries: {
  7216. BR: 'Brazil',
  7217. CA: 'Canada',
  7218. CZ: 'Czech Republic',
  7219. DK: 'Denmark',
  7220. GB: 'United Kingdom',
  7221. IT: 'Italy',
  7222. MA: 'Morocco',
  7223. NL: 'Netherlands',
  7224. RO: 'Romania',
  7225. RU: 'Russia',
  7226. SE: 'Sweden',
  7227. SG: 'Singapore',
  7228. SK: 'Slovakia',
  7229. US: 'USA'
  7230. }
  7231. });
  7232. $.fn.bootstrapValidator.validators.zipCode = {
  7233. html5Attributes: {
  7234. message: 'message',
  7235. country: 'country'
  7236. },
  7237. COUNTRY_CODES: ['BR', 'CA', 'CZ', 'DK', 'GB', 'IT', 'MA', 'NL', 'RO', 'RU', 'SE', 'SG', 'SK', 'US'],
  7238. /**
  7239. * Return true if and only if the input value is a valid country zip code
  7240. *
  7241. * @param {BootstrapValidator} validator The validator plugin instance
  7242. * @param {jQuery} $field Field element
  7243. * @param {Object} options Consist of key:
  7244. * - message: The invalid message
  7245. * - country: The country
  7246. *
  7247. * The country can be defined by:
  7248. * - An ISO 3166 country code
  7249. * - Name of field which its value defines the country code
  7250. * - Name of callback function that returns the country code
  7251. * - A callback function that returns the country code
  7252. *
  7253. * callback: function(value, validator, $field) {
  7254. * // value is the value of field
  7255. * // validator is the BootstrapValidator instance
  7256. * // $field is jQuery element representing the field
  7257. * }
  7258. *
  7259. * @returns {Boolean|Object}
  7260. */
  7261. validate: function(validator, $field, options) {
  7262. var value = $field.val();
  7263. if (value === '' || !options.country) {
  7264. return true;
  7265. }
  7266. var country = options.country;
  7267. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  7268. // Try to determine the country
  7269. country = validator.getDynamicOption($field, country);
  7270. }
  7271. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  7272. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, country) };
  7273. }
  7274. var isValid = false;
  7275. country = country.toUpperCase();
  7276. switch (country) {
  7277. case 'BR':
  7278. isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
  7279. break;
  7280. case 'CA':
  7281. 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);
  7282. break;
  7283. case 'CZ':
  7284. // Test: http://regexr.com/39hhr
  7285. isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  7286. break;
  7287. case 'DK':
  7288. isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
  7289. break;
  7290. case 'GB':
  7291. isValid = this._gb(value);
  7292. break;
  7293. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  7294. case 'IT':
  7295. isValid = /^(I-|IT-)?\d{5}$/i.test(value);
  7296. break;
  7297. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
  7298. case 'MA':
  7299. isValid = /^[1-9][0-9]{4}$/i.test(value);
  7300. break;
  7301. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  7302. case 'NL':
  7303. isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  7304. break;
  7305. case 'RO':
  7306. isValid = /^(0[1-8]{1}|[1-9]{1}[0-5]{1})?[0-9]{4}$/i.test(value);
  7307. break;
  7308. case 'RU':
  7309. isValid = /^[0-9]{6}$/i.test(value);
  7310. break;
  7311. case 'SE':
  7312. isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  7313. break;
  7314. case 'SG':
  7315. isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  7316. break;
  7317. case 'SK':
  7318. // Test: http://regexr.com/39hhr
  7319. isValid = /^(\d{3})([ ]?)(\d{2})$/.test(value);
  7320. break;
  7321. case 'US':
  7322. /* falls through */
  7323. default:
  7324. isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
  7325. break;
  7326. }
  7327. return {
  7328. valid: isValid,
  7329. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.zipCode.country, $.fn.bootstrapValidator.i18n.zipCode.countries[country])
  7330. };
  7331. },
  7332. /**
  7333. * Validate United Kingdom postcode
  7334. * Examples:
  7335. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  7336. * - Special cases:
  7337. * AI-2640, ASCN 1ZZ, GIR 0AA
  7338. *
  7339. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  7340. * @param {String} value The postcode
  7341. * @returns {Boolean}
  7342. */
  7343. _gb: function(value) {
  7344. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  7345. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  7346. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  7347. fourthChar = '[ABEHMNPRVWXY]',
  7348. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  7349. regexps = [
  7350. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  7351. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  7352. // ANA NAA
  7353. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  7354. // AANA NAA
  7355. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  7356. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  7357. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  7358. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  7359. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  7360. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  7361. /^(AI-2640)$/i // Anguilla
  7362. ];
  7363. for (var i = 0; i < regexps.length; i++) {
  7364. if (regexps[i].test(value)) {
  7365. return true;
  7366. }
  7367. }
  7368. return false;
  7369. }
  7370. };
  7371. }(window.jQuery));