bootstrapValidator.js 244 KB

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