bootstrapValidator.js 259 KB

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