bootstrapValidator.js 306 KB

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