bootstrapValidator.js 244 KB

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