bootstrapValidator.js 259 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850
  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.2-dev, built on 2014-08-24 11:29:16 AM
  6. * @author https://twitter.com/nghuuphuoc
  7. * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
  8. * @license MIT
  9. */
  10. (function($) {
  11. var BootstrapValidator = function(form, options) {
  12. this.$form = $(form);
  13. this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options);
  14. this.$invalidFields = $([]); // Array of invalid fields
  15. this.$submitButton = null; // The submit button which is clicked to submit form
  16. 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. if (!$.isNumeric(value)) {
  1731. return false;
  1732. }
  1733. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  1734. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max);
  1735. value = parseFloat(value);
  1736. return (options.inclusive === true || options.inclusive === undefined)
  1737. ? {
  1738. valid: value >= min && value <= max,
  1739. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between['default'], [min, max])
  1740. }
  1741. : {
  1742. valid: value > min && value < max,
  1743. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.between.notInclusive, [min, max])
  1744. };
  1745. }
  1746. };
  1747. }(window.jQuery));
  1748. ;(function($) {
  1749. $.fn.bootstrapValidator.i18n.callback = $.extend($.fn.bootstrapValidator.i18n.callback || {}, {
  1750. 'default': 'Please enter a valid value'
  1751. });
  1752. $.fn.bootstrapValidator.validators.callback = {
  1753. html5Attributes: {
  1754. message: 'message',
  1755. callback: 'callback'
  1756. },
  1757. /**
  1758. * Return result from the callback method
  1759. *
  1760. * @param {BootstrapValidator} validator The validator plugin instance
  1761. * @param {jQuery} $field Field element
  1762. * @param {Object} options Can consist of the following keys:
  1763. * - callback: The callback method that passes 2 parameters:
  1764. * callback: function(fieldValue, validator, $field) {
  1765. * // fieldValue is the value of field
  1766. * // validator is instance of BootstrapValidator
  1767. * // $field is the field element
  1768. * }
  1769. * - message: The invalid message
  1770. * @returns {Boolean|Deferred}
  1771. */
  1772. validate: function(validator, $field, options) {
  1773. var value = $field.val();
  1774. if (options.callback) {
  1775. var dfd = new $.Deferred(),
  1776. response = $.fn.bootstrapValidator.helpers.call(options.callback, [value, validator, $field]);
  1777. dfd.resolve($field, 'callback', 'boolean' === typeof response ? response : response.valid, 'object' === typeof response && response.message ? response.message : null);
  1778. return dfd;
  1779. }
  1780. return true;
  1781. }
  1782. };
  1783. }(window.jQuery));
  1784. ;(function($) {
  1785. $.fn.bootstrapValidator.i18n.choice = $.extend($.fn.bootstrapValidator.i18n.choice || {}, {
  1786. 'default': 'Please enter a valid value',
  1787. less: 'Please choose %s options at minimum',
  1788. more: 'Please choose %s options at maximum',
  1789. between: 'Please choose %s - %s options'
  1790. });
  1791. $.fn.bootstrapValidator.validators.choice = {
  1792. html5Attributes: {
  1793. message: 'message',
  1794. min: 'min',
  1795. max: 'max'
  1796. },
  1797. /**
  1798. * Check if the number of checked boxes are less or more than a given number
  1799. *
  1800. * @param {BootstrapValidator} validator The validator plugin instance
  1801. * @param {jQuery} $field Field element
  1802. * @param {Object} options Consists of following keys:
  1803. * - min
  1804. * - max
  1805. *
  1806. * At least one of two keys is required
  1807. * The min, max keys define the number which the field value compares to. min, max can be
  1808. * - A number
  1809. * - Name of field which its value defines the number
  1810. * - Name of callback function that returns the number
  1811. * - A callback function that returns the number
  1812. *
  1813. * - message: The invalid message
  1814. * @returns {Object}
  1815. */
  1816. validate: function(validator, $field, options) {
  1817. var numChoices = $field.is('select')
  1818. ? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
  1819. : validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length,
  1820. min = options.min ? ($.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min)) : null,
  1821. max = options.max ? ($.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max)) : null,
  1822. isValid = true,
  1823. message = options.message || $.fn.bootstrapValidator.i18n.choice['default'];
  1824. if ((min && numChoices < parseInt(min, 10)) || (max && numChoices > parseInt(max, 10))) {
  1825. isValid = false;
  1826. }
  1827. switch (true) {
  1828. case (!!min && !!max):
  1829. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.between, [parseInt(min, 10), parseInt(max, 10)]);
  1830. break;
  1831. case (!!min):
  1832. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.less, parseInt(min, 10));
  1833. break;
  1834. case (!!max):
  1835. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.choice.more, parseInt(max, 10));
  1836. break;
  1837. default:
  1838. break;
  1839. }
  1840. return { valid: isValid, message: message };
  1841. }
  1842. };
  1843. }(window.jQuery));
  1844. ;(function($) {
  1845. $.fn.bootstrapValidator.i18n.creditCard = $.extend($.fn.bootstrapValidator.i18n.creditCard || {}, {
  1846. 'default': 'Please enter a valid credit card number'
  1847. });
  1848. $.fn.bootstrapValidator.validators.creditCard = {
  1849. /**
  1850. * Return true if the input value is valid credit card number
  1851. * Based on https://gist.github.com/DiegoSalazar/4075533
  1852. *
  1853. * @param {BootstrapValidator} validator The validator plugin instance
  1854. * @param {jQuery} $field Field element
  1855. * @param {Object} [options] Can consist of the following key:
  1856. * - message: The invalid message
  1857. * @returns {Boolean}
  1858. */
  1859. validate: function(validator, $field, options) {
  1860. var value = $field.val();
  1861. if (value === '') {
  1862. return true;
  1863. }
  1864. // Accept only digits, dashes or spaces
  1865. if (/[^0-9-\s]+/.test(value)) {
  1866. return false;
  1867. }
  1868. value = value.replace(/\D/g, '');
  1869. if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
  1870. return false;
  1871. }
  1872. // Validate the card number based on prefix (IIN ranges) and length
  1873. var cards = {
  1874. AMERICAN_EXPRESS: {
  1875. length: [15],
  1876. prefix: ['34', '37']
  1877. },
  1878. DINERS_CLUB: {
  1879. length: [14],
  1880. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1881. },
  1882. DINERS_CLUB_US: {
  1883. length: [16],
  1884. prefix: ['54', '55']
  1885. },
  1886. DISCOVER: {
  1887. length: [16],
  1888. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1889. '62214', '62215', '62216', '62217', '62218', '62219',
  1890. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1891. '62290', '62291', '622920', '622921', '622922', '622923',
  1892. '622924', '622925', '644', '645', '646', '647', '648',
  1893. '649', '65']
  1894. },
  1895. JCB: {
  1896. length: [16],
  1897. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1898. },
  1899. LASER: {
  1900. length: [16, 17, 18, 19],
  1901. prefix: ['6304', '6706', '6771', '6709']
  1902. },
  1903. MAESTRO: {
  1904. length: [12, 13, 14, 15, 16, 17, 18, 19],
  1905. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  1906. },
  1907. MASTERCARD: {
  1908. length: [16],
  1909. prefix: ['51', '52', '53', '54', '55']
  1910. },
  1911. SOLO: {
  1912. length: [16, 18, 19],
  1913. prefix: ['6334', '6767']
  1914. },
  1915. UNIONPAY: {
  1916. length: [16, 17, 18, 19],
  1917. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  1918. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  1919. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  1920. '622920', '622921', '622922', '622923', '622924', '622925']
  1921. },
  1922. VISA: {
  1923. length: [16],
  1924. prefix: ['4']
  1925. }
  1926. };
  1927. var type, i;
  1928. for (type in cards) {
  1929. for (i in cards[type].prefix) {
  1930. if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  1931. && $.inArray(value.length, cards[type].length) !== -1) // and length
  1932. {
  1933. return true;
  1934. }
  1935. }
  1936. }
  1937. return false;
  1938. }
  1939. };
  1940. }(window.jQuery));
  1941. ;(function($) {
  1942. $.fn.bootstrapValidator.i18n.cusip = $.extend($.fn.bootstrapValidator.i18n.cusip || {}, {
  1943. 'default': 'Please enter a valid CUSIP number'
  1944. });
  1945. $.fn.bootstrapValidator.validators.cusip = {
  1946. /**
  1947. * Validate a CUSIP
  1948. * Examples:
  1949. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  1950. * - Invalid: 31430F200, 022615AC2
  1951. *
  1952. * @see http://en.wikipedia.org/wiki/CUSIP
  1953. * @param {BootstrapValidator} validator The validator plugin instance
  1954. * @param {jQuery} $field Field element
  1955. * @param {Object} [options] Can consist of the following keys:
  1956. * - message: The invalid message
  1957. * @returns {Boolean}
  1958. */
  1959. validate: function(validator, $field, options) {
  1960. var value = $field.val();
  1961. if (value === '') {
  1962. return true;
  1963. }
  1964. value = value.toUpperCase();
  1965. if (!/^[0-9A-Z]{9}$/.test(value)) {
  1966. return false;
  1967. }
  1968. var converted = $.map(value.split(''), function(item) {
  1969. var code = item.charCodeAt(0);
  1970. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  1971. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  1972. ? (code - 'A'.charCodeAt(0) + 10)
  1973. : item;
  1974. }),
  1975. length = converted.length,
  1976. sum = 0;
  1977. for (var i = 0; i < length - 1; i++) {
  1978. var num = parseInt(converted[i], 10);
  1979. if (i % 2 !== 0) {
  1980. num *= 2;
  1981. }
  1982. if (num > 9) {
  1983. num -= 9;
  1984. }
  1985. sum += num;
  1986. }
  1987. sum = (10 - (sum % 10)) % 10;
  1988. return sum === converted[length - 1];
  1989. }
  1990. };
  1991. }(window.jQuery));
  1992. ;(function($) {
  1993. $.fn.bootstrapValidator.i18n.cvv = $.extend($.fn.bootstrapValidator.i18n.cvv || {}, {
  1994. 'default': 'Please enter a valid CVV number'
  1995. });
  1996. $.fn.bootstrapValidator.validators.cvv = {
  1997. html5Attributes: {
  1998. message: 'message',
  1999. ccfield: 'creditCardField'
  2000. },
  2001. /**
  2002. * Return true if the input value is a valid CVV number.
  2003. *
  2004. * @param {BootstrapValidator} validator The validator plugin instance
  2005. * @param {jQuery} $field Field element
  2006. * @param {Object} options Can consist of the following keys:
  2007. * - creditCardField: The credit card number field. It can be null
  2008. * - message: The invalid message
  2009. * @returns {Boolean}
  2010. */
  2011. validate: function(validator, $field, options) {
  2012. var value = $field.val();
  2013. if (value === '') {
  2014. return true;
  2015. }
  2016. if (!/^[0-9]{3,4}$/.test(value)) {
  2017. return false;
  2018. }
  2019. if (!options.creditCardField) {
  2020. return true;
  2021. }
  2022. // Get the credit card number
  2023. var creditCard = validator.getFieldElements(options.creditCardField).val();
  2024. if (creditCard === '') {
  2025. return true;
  2026. }
  2027. creditCard = creditCard.replace(/\D/g, '');
  2028. // Supported credit card types
  2029. var cards = {
  2030. AMERICAN_EXPRESS: {
  2031. length: [15],
  2032. prefix: ['34', '37']
  2033. },
  2034. DINERS_CLUB: {
  2035. length: [14],
  2036. prefix: ['300', '301', '302', '303', '304', '305', '36']
  2037. },
  2038. DINERS_CLUB_US: {
  2039. length: [16],
  2040. prefix: ['54', '55']
  2041. },
  2042. DISCOVER: {
  2043. length: [16],
  2044. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  2045. '62214', '62215', '62216', '62217', '62218', '62219',
  2046. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  2047. '62290', '62291', '622920', '622921', '622922', '622923',
  2048. '622924', '622925', '644', '645', '646', '647', '648',
  2049. '649', '65']
  2050. },
  2051. JCB: {
  2052. length: [16],
  2053. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  2054. },
  2055. LASER: {
  2056. length: [16, 17, 18, 19],
  2057. prefix: ['6304', '6706', '6771', '6709']
  2058. },
  2059. MAESTRO: {
  2060. length: [12, 13, 14, 15, 16, 17, 18, 19],
  2061. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  2062. },
  2063. MASTERCARD: {
  2064. length: [16],
  2065. prefix: ['51', '52', '53', '54', '55']
  2066. },
  2067. SOLO: {
  2068. length: [16, 18, 19],
  2069. prefix: ['6334', '6767']
  2070. },
  2071. UNIONPAY: {
  2072. length: [16, 17, 18, 19],
  2073. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  2074. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  2075. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  2076. '622920', '622921', '622922', '622923', '622924', '622925']
  2077. },
  2078. VISA: {
  2079. length: [16],
  2080. prefix: ['4']
  2081. }
  2082. };
  2083. var type, i, creditCardType = null;
  2084. for (type in cards) {
  2085. for (i in cards[type].prefix) {
  2086. if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  2087. && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
  2088. {
  2089. creditCardType = type;
  2090. break;
  2091. }
  2092. }
  2093. }
  2094. return (creditCardType === null)
  2095. ? false
  2096. : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  2097. }
  2098. };
  2099. }(window.jQuery));
  2100. ;(function($) {
  2101. $.fn.bootstrapValidator.i18n.date = $.extend($.fn.bootstrapValidator.i18n.date || {}, {
  2102. 'default': 'Please enter a valid date'
  2103. });
  2104. $.fn.bootstrapValidator.validators.date = {
  2105. html5Attributes: {
  2106. message: 'message',
  2107. format: 'format',
  2108. separator: 'separator'
  2109. },
  2110. /**
  2111. * Return true if the input value is valid date
  2112. *
  2113. * @param {BootstrapValidator} validator The validator plugin instance
  2114. * @param {jQuery} $field Field element
  2115. * @param {Object} options Can consist of the following keys:
  2116. * - message: The invalid message
  2117. * - separator: Use to separate the date, month, and year.
  2118. * By default, it is /
  2119. * - format: The date format. Default is MM/DD/YYYY
  2120. * The format can be:
  2121. *
  2122. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  2123. * ii) date and time:
  2124. * The time can consist of h, m, s parts which are separated by :
  2125. * ii) date, time and A (indicating AM or PM)
  2126. * @returns {Boolean}
  2127. */
  2128. validate: function(validator, $field, options) {
  2129. var value = $field.val();
  2130. if (value === '') {
  2131. return true;
  2132. }
  2133. options.format = options.format || 'MM/DD/YYYY';
  2134. // #683: Force the format to YYYY-MM-DD as the default browser behaviour when using type="date" attribute
  2135. if ($field.attr('type') === 'date') {
  2136. options.format = 'YYYY-MM-DD';
  2137. }
  2138. var formats = options.format.split(' '),
  2139. dateFormat = formats[0],
  2140. timeFormat = (formats.length > 1) ? formats[1] : null,
  2141. amOrPm = (formats.length > 2) ? formats[2] : null,
  2142. sections = value.split(' '),
  2143. date = sections[0],
  2144. time = (sections.length > 1) ? sections[1] : null;
  2145. if (formats.length !== sections.length) {
  2146. return false;
  2147. }
  2148. // Determine the separator
  2149. var separator = options.separator;
  2150. if (!separator) {
  2151. separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
  2152. }
  2153. if (separator === null || date.indexOf(separator) === -1) {
  2154. return false;
  2155. }
  2156. // Determine the date
  2157. date = date.split(separator);
  2158. dateFormat = dateFormat.split(separator);
  2159. if (date.length !== dateFormat.length) {
  2160. return false;
  2161. }
  2162. var year = date[$.inArray('YYYY', dateFormat)],
  2163. month = date[$.inArray('MM', dateFormat)],
  2164. day = date[$.inArray('DD', dateFormat)];
  2165. if (!year || !month || !day || year.length !== 4) {
  2166. return false;
  2167. }
  2168. // Determine the time
  2169. var minutes = null, hours = null, seconds = null;
  2170. if (timeFormat) {
  2171. timeFormat = timeFormat.split(':');
  2172. time = time.split(':');
  2173. if (timeFormat.length !== time.length) {
  2174. return false;
  2175. }
  2176. hours = time.length > 0 ? time[0] : null;
  2177. minutes = time.length > 1 ? time[1] : null;
  2178. seconds = time.length > 2 ? time[2] : null;
  2179. // Validate seconds
  2180. if (seconds) {
  2181. if (isNaN(seconds) || seconds.length > 2) {
  2182. return false;
  2183. }
  2184. seconds = parseInt(seconds, 10);
  2185. if (seconds < 0 || seconds > 60) {
  2186. return false;
  2187. }
  2188. }
  2189. // Validate hours
  2190. if (hours) {
  2191. if (isNaN(hours) || hours.length > 2) {
  2192. return false;
  2193. }
  2194. hours = parseInt(hours, 10);
  2195. if (hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  2196. return false;
  2197. }
  2198. }
  2199. // Validate minutes
  2200. if (minutes) {
  2201. if (isNaN(minutes) || minutes.length > 2) {
  2202. return false;
  2203. }
  2204. minutes = parseInt(minutes, 10);
  2205. if (minutes < 0 || minutes > 59) {
  2206. return false;
  2207. }
  2208. }
  2209. }
  2210. // Validate day, month, and year
  2211. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  2212. }
  2213. };
  2214. }(window.jQuery));
  2215. ;(function($) {
  2216. $.fn.bootstrapValidator.i18n.different = $.extend($.fn.bootstrapValidator.i18n.different || {}, {
  2217. 'default': 'Please enter a different value'
  2218. });
  2219. $.fn.bootstrapValidator.validators.different = {
  2220. html5Attributes: {
  2221. message: 'message',
  2222. field: 'field'
  2223. },
  2224. /**
  2225. * Return true if the input value is different with given field's value
  2226. *
  2227. * @param {BootstrapValidator} validator The validator plugin instance
  2228. * @param {jQuery} $field Field element
  2229. * @param {Object} options Consists of the following key:
  2230. * - field: The name of field that will be used to compare with current one
  2231. * - message: The invalid message
  2232. * @returns {Boolean}
  2233. */
  2234. validate: function(validator, $field, options) {
  2235. var value = $field.val();
  2236. if (value === '') {
  2237. return true;
  2238. }
  2239. var fields = options.field.split(','),
  2240. isValid = true;
  2241. for (var i = 0; i < fields.length; i++) {
  2242. var compareWith = validator.getFieldElements(fields[i]);
  2243. if (compareWith == null || compareWith.length === 0) {
  2244. continue;
  2245. }
  2246. if (value === compareWith.val()) {
  2247. isValid = false;
  2248. } else {
  2249. validator.updateStatus(fields[i], validator.STATUS_VALID, 'different');
  2250. }
  2251. }
  2252. return isValid;
  2253. }
  2254. };
  2255. }(window.jQuery));
  2256. ;(function($) {
  2257. $.fn.bootstrapValidator.i18n.digits = $.extend($.fn.bootstrapValidator.i18n.digits || {}, {
  2258. 'default': 'Please enter only digits'
  2259. });
  2260. $.fn.bootstrapValidator.validators.digits = {
  2261. /**
  2262. * Return true if the input value contains digits only
  2263. *
  2264. * @param {BootstrapValidator} validator Validate plugin instance
  2265. * @param {jQuery} $field Field element
  2266. * @param {Object} [options]
  2267. * @returns {Boolean}
  2268. */
  2269. validate: function(validator, $field, options) {
  2270. var value = $field.val();
  2271. if (value === '') {
  2272. return true;
  2273. }
  2274. return /^\d+$/.test(value);
  2275. }
  2276. };
  2277. }(window.jQuery));
  2278. ;(function($) {
  2279. $.fn.bootstrapValidator.i18n.ean = $.extend($.fn.bootstrapValidator.i18n.ean || {}, {
  2280. 'default': 'Please enter a valid EAN number'
  2281. });
  2282. $.fn.bootstrapValidator.validators.ean = {
  2283. /**
  2284. * Validate EAN (International Article Number)
  2285. * Examples:
  2286. * - Valid: 73513537, 9780471117094, 4006381333931
  2287. * - Invalid: 73513536
  2288. *
  2289. * @see http://en.wikipedia.org/wiki/European_Article_Number
  2290. * @param {BootstrapValidator} validator The validator plugin instance
  2291. * @param {jQuery} $field Field element
  2292. * @param {Object} options Can consist of the following keys:
  2293. * - message: The invalid message
  2294. * @returns {Boolean}
  2295. */
  2296. validate: function(validator, $field, options) {
  2297. var value = $field.val();
  2298. if (value === '') {
  2299. return true;
  2300. }
  2301. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  2302. return false;
  2303. }
  2304. var length = value.length,
  2305. sum = 0,
  2306. weight = (length === 8) ? [3, 1] : [1, 3];
  2307. for (var i = 0; i < length - 1; i++) {
  2308. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  2309. }
  2310. sum = (10 - sum % 10) % 10;
  2311. return (sum + '' === value.charAt(length - 1));
  2312. }
  2313. };
  2314. }(window.jQuery));
  2315. ;(function($) {
  2316. $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
  2317. 'default': 'Please enter a valid email address'
  2318. });
  2319. $.fn.bootstrapValidator.validators.emailAddress = {
  2320. enableByHtml5: function($field) {
  2321. return ('email' === $field.attr('type'));
  2322. },
  2323. /**
  2324. * Return true if and only if the input value is a valid email address
  2325. *
  2326. * @param {BootstrapValidator} validator Validate plugin instance
  2327. * @param {jQuery} $field Field element
  2328. * @param {Object} [options]
  2329. * @returns {Boolean}
  2330. */
  2331. validate: function(validator, $field, options) {
  2332. var value = $field.val();
  2333. if (value === '') {
  2334. return true;
  2335. }
  2336. // Email address regular expression
  2337. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  2338. 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,}))$/;
  2339. return emailRegExp.test(value);
  2340. }
  2341. };
  2342. }(window.jQuery));
  2343. ;(function($) {
  2344. $.fn.bootstrapValidator.i18n.file = $.extend($.fn.bootstrapValidator.i18n.file || {}, {
  2345. 'default': 'Please choose a valid file'
  2346. });
  2347. $.fn.bootstrapValidator.validators.file = {
  2348. html5Attributes: {
  2349. extension: 'extension',
  2350. maxsize: 'maxSize',
  2351. message: 'message',
  2352. type: 'type'
  2353. },
  2354. /**
  2355. * Validate upload file. Use HTML 5 API if the browser supports
  2356. *
  2357. * @param {BootstrapValidator} validator The validator plugin instance
  2358. * @param {jQuery} $field Field element
  2359. * @param {Object} options Can consist of the following keys:
  2360. * - extension: The allowed extensions, separated by a comma
  2361. * - maxSize: The maximum size in bytes
  2362. * - message: The invalid message
  2363. * - type: The allowed MIME type, separated by a comma
  2364. * @returns {Boolean}
  2365. */
  2366. validate: function(validator, $field, options) {
  2367. var value = $field.val();
  2368. if (value === '') {
  2369. return true;
  2370. }
  2371. var ext,
  2372. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  2373. types = options.type ? options.type.toLowerCase().split(',') : null,
  2374. html5 = (window.File && window.FileList && window.FileReader);
  2375. if (html5) {
  2376. // Get FileList instance
  2377. var files = $field.get(0).files,
  2378. total = files.length;
  2379. for (var i = 0; i < total; i++) {
  2380. // Check file size
  2381. if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
  2382. return false;
  2383. }
  2384. // Check file extension
  2385. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  2386. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2387. return false;
  2388. }
  2389. // Check file type
  2390. if (files[i].type && types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
  2391. return false;
  2392. }
  2393. }
  2394. } else {
  2395. // Check file extension
  2396. ext = value.substr(value.lastIndexOf('.') + 1);
  2397. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2398. return false;
  2399. }
  2400. }
  2401. return true;
  2402. }
  2403. };
  2404. }(window.jQuery));
  2405. ;(function($) {
  2406. $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
  2407. 'default': 'Please enter a value greater than or equal to %s',
  2408. notInclusive: 'Please enter a value greater than %s'
  2409. });
  2410. $.fn.bootstrapValidator.validators.greaterThan = {
  2411. html5Attributes: {
  2412. message: 'message',
  2413. value: 'value',
  2414. inclusive: 'inclusive'
  2415. },
  2416. enableByHtml5: function($field) {
  2417. var type = $field.attr('type'),
  2418. min = $field.attr('min');
  2419. if (min && type !== 'date') {
  2420. return {
  2421. value: min
  2422. };
  2423. }
  2424. return false;
  2425. },
  2426. /**
  2427. * Return true if the input value is greater than or equals to given number
  2428. *
  2429. * @param {BootstrapValidator} validator Validate plugin instance
  2430. * @param {jQuery} $field Field element
  2431. * @param {Object} options Can consist of the following keys:
  2432. * - value: Define the number to compare with. It can be
  2433. * - A number
  2434. * - Name of field which its value defines the number
  2435. * - Name of callback function that returns the number
  2436. * - A callback function that returns the number
  2437. *
  2438. * - inclusive [optional]: Can be true or false. Default is true
  2439. * - message: The invalid message
  2440. * @returns {Boolean|Object}
  2441. */
  2442. validate: function(validator, $field, options) {
  2443. var value = $field.val();
  2444. if (value === '') {
  2445. return true;
  2446. }
  2447. if (!$.isNumeric(value)) {
  2448. return false;
  2449. }
  2450. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
  2451. value = parseFloat(value);
  2452. return (options.inclusive === true || options.inclusive === undefined)
  2453. ? {
  2454. valid: value >= compareTo,
  2455. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan['default'], compareTo)
  2456. }
  2457. : {
  2458. valid: value > compareTo,
  2459. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
  2460. };
  2461. }
  2462. };
  2463. }(window.jQuery));
  2464. ;(function($) {
  2465. $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
  2466. 'default': 'Please enter a valid GRId number'
  2467. });
  2468. $.fn.bootstrapValidator.validators.grid = {
  2469. /**
  2470. * Validate GRId (Global Release Identifier)
  2471. * Examples:
  2472. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  2473. * - Invalid: A1-2425G-ABC1234002-Q
  2474. *
  2475. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  2476. * @param {BootstrapValidator} validator The validator plugin instance
  2477. * @param {jQuery} $field Field element
  2478. * @param {Object} options Can consist of the following keys:
  2479. * - message: The invalid message
  2480. * @returns {Boolean}
  2481. */
  2482. validate: function(validator, $field, options) {
  2483. var value = $field.val();
  2484. if (value === '') {
  2485. return true;
  2486. }
  2487. value = value.toUpperCase();
  2488. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  2489. return false;
  2490. }
  2491. value = value.replace(/\s/g, '').replace(/-/g, '');
  2492. if ('GRID:' === value.substr(0, 5)) {
  2493. value = value.substr(5);
  2494. }
  2495. return $.fn.bootstrapValidator.helpers.mod37And36(value);
  2496. }
  2497. };
  2498. }(window.jQuery));
  2499. ;(function($) {
  2500. $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
  2501. 'default': 'Please enter a valid hexadecimal number'
  2502. });
  2503. $.fn.bootstrapValidator.validators.hex = {
  2504. /**
  2505. * Return true if and only if the input value is a valid hexadecimal number
  2506. *
  2507. * @param {BootstrapValidator} validator The validator plugin instance
  2508. * @param {jQuery} $field Field element
  2509. * @param {Object} options Consist of key:
  2510. * - message: The invalid message
  2511. * @returns {Boolean}
  2512. */
  2513. validate: function(validator, $field, options) {
  2514. var value = $field.val();
  2515. if (value === '') {
  2516. return true;
  2517. }
  2518. return /^[0-9a-fA-F]+$/.test(value);
  2519. }
  2520. };
  2521. }(window.jQuery));
  2522. ;(function($) {
  2523. $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
  2524. 'default': 'Please enter a valid hex color'
  2525. });
  2526. $.fn.bootstrapValidator.validators.hexColor = {
  2527. enableByHtml5: function($field) {
  2528. return ('color' === $field.attr('type'));
  2529. },
  2530. /**
  2531. * Return true if the input value is a valid hex color
  2532. *
  2533. * @param {BootstrapValidator} validator The validator plugin instance
  2534. * @param {jQuery} $field Field element
  2535. * @param {Object} options Can consist of the following keys:
  2536. * - message: The invalid message
  2537. * @returns {Boolean}
  2538. */
  2539. validate: function(validator, $field, options) {
  2540. var value = $field.val();
  2541. if (value === '') {
  2542. return true;
  2543. }
  2544. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2545. }
  2546. };
  2547. }(window.jQuery));
  2548. ;(function($) {
  2549. $.fn.bootstrapValidator.i18n.iban = $.extend($.fn.bootstrapValidator.i18n.iban || {}, {
  2550. 'default': 'Please enter a valid IBAN number',
  2551. countryNotSupported: 'The country code %s is not supported',
  2552. country: 'Please enter a valid IBAN number in %s',
  2553. countries: {
  2554. AD: 'Andorra',
  2555. AE: 'United Arab Emirates',
  2556. AL: 'Albania',
  2557. AO: 'Angola',
  2558. AT: 'Austria',
  2559. AZ: 'Azerbaijan',
  2560. BA: 'Bosnia and Herzegovina',
  2561. BE: 'Belgium',
  2562. BF: 'Burkina Faso',
  2563. BG: 'Bulgaria',
  2564. BH: 'Bahrain',
  2565. BI: 'Burundi',
  2566. BJ: 'Benin',
  2567. BR: 'Brazil',
  2568. CH: 'Switzerland',
  2569. CI: 'Ivory Coast',
  2570. CM: 'Cameroon',
  2571. CR: 'Costa Rica',
  2572. CV: 'Cape Verde',
  2573. CY: 'Cyprus',
  2574. CZ: 'Czech Republic',
  2575. DE: 'Germany',
  2576. DK: 'Denmark',
  2577. DO: 'Dominican Republic',
  2578. DZ: 'Algeria',
  2579. EE: 'Estonia',
  2580. ES: 'Spain',
  2581. FI: 'Finland',
  2582. FO: 'Faroe Islands',
  2583. FR: 'France',
  2584. GB: 'United Kingdom',
  2585. GE: 'Georgia',
  2586. GI: 'Gibraltar',
  2587. GL: 'Greenland',
  2588. GR: 'Greece',
  2589. GT: 'Guatemala',
  2590. HR: 'Croatia',
  2591. HU: 'Hungary',
  2592. IE: 'Ireland',
  2593. IL: 'Israel',
  2594. IR: 'Iran',
  2595. IS: 'Iceland',
  2596. IT: 'Italy',
  2597. JO: 'Jordan',
  2598. KW: 'Kuwait',
  2599. KZ: 'Kazakhstan',
  2600. LB: 'Lebanon',
  2601. LI: 'Liechtenstein',
  2602. LT: 'Lithuania',
  2603. LU: 'Luxembourg',
  2604. LV: 'Latvia',
  2605. MC: 'Monaco',
  2606. MD: 'Moldova',
  2607. ME: 'Montenegro',
  2608. MG: 'Madagascar',
  2609. MK: 'Macedonia',
  2610. ML: 'Mali',
  2611. MR: 'Mauritania',
  2612. MT: 'Malta',
  2613. MU: 'Mauritius',
  2614. MZ: 'Mozambique',
  2615. NL: 'Netherlands',
  2616. NO: 'Norway',
  2617. PK: 'Pakistan',
  2618. PL: 'Poland',
  2619. PS: 'Palestinian',
  2620. PT: 'Portugal',
  2621. QA: 'Qatar',
  2622. RO: 'Romania',
  2623. RS: 'Serbia',
  2624. SA: 'Saudi Arabia',
  2625. SE: 'Sweden',
  2626. SI: 'Slovenia',
  2627. SK: 'Slovakia',
  2628. SM: 'San Marino',
  2629. SN: 'Senegal',
  2630. TN: 'Tunisia',
  2631. TR: 'Turkey',
  2632. VG: 'Virgin Islands, British'
  2633. }
  2634. });
  2635. $.fn.bootstrapValidator.validators.iban = {
  2636. html5Attributes: {
  2637. message: 'message',
  2638. country: 'country'
  2639. },
  2640. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  2641. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  2642. REGEX: {
  2643. AD: 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  2644. AE: 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  2645. AL: 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  2646. AO: 'AO[0-9]{2}[0-9]{21}', // Angola
  2647. AT: 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  2648. AZ: 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  2649. BA: 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  2650. BE: 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  2651. BF: 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  2652. BG: 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  2653. BH: 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  2654. BI: 'BI[0-9]{2}[0-9]{12}', // Burundi
  2655. BJ: 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  2656. BR: 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  2657. CH: 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  2658. CI: 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  2659. CM: 'CM[0-9]{2}[0-9]{23}', // Cameroon
  2660. CR: 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  2661. CV: 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  2662. CY: 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  2663. CZ: 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  2664. DE: 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  2665. DK: 'DK[0-9]{2}[0-9]{14}', // Denmark
  2666. DO: 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  2667. DZ: 'DZ[0-9]{2}[0-9]{20}', // Algeria
  2668. EE: 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  2669. ES: 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  2670. FI: 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  2671. FO: 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  2672. FR: 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  2673. GB: 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  2674. GE: 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  2675. GI: 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  2676. GL: 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland
  2677. GR: 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  2678. GT: 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  2679. HR: 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  2680. HU: 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  2681. IE: 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  2682. IL: 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  2683. IR: 'IR[0-9]{2}[0-9]{22}', // Iran
  2684. IS: 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  2685. IT: 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  2686. JO: 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  2687. KW: 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  2688. KZ: 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  2689. LB: 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  2690. LI: 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  2691. LT: 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  2692. LU: 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  2693. LV: 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  2694. MC: 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  2695. MD: 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  2696. ME: 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  2697. MG: 'MG[0-9]{2}[0-9]{23}', // Madagascar
  2698. MK: 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  2699. ML: 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  2700. MR: 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  2701. MT: 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  2702. MU: 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}', // Mauritius
  2703. MZ: 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  2704. NL: 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  2705. NO: 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  2706. PK: 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  2707. PL: 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  2708. PS: 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  2709. PT: 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  2710. QA: 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  2711. RO: 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  2712. RS: 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  2713. SA: 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  2714. SE: 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  2715. SI: 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  2716. SK: 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  2717. SM: 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  2718. SN: 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  2719. TN: 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  2720. TR: 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  2721. VG: 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  2722. },
  2723. /**
  2724. * Validate an International Bank Account Number (IBAN)
  2725. * To test it, take the sample IBAN from
  2726. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  2727. *
  2728. * @param {BootstrapValidator} validator The validator plugin instance
  2729. * @param {jQuery} $field Field element
  2730. * @param {Object} options Can consist of the following keys:
  2731. * - message: The invalid message
  2732. * - country: The ISO 3166-1 country code. It can be
  2733. * - A country code
  2734. * - Name of field which its value defines the country code
  2735. * - Name of callback function that returns the country code
  2736. * - A callback function that returns the country code
  2737. * @returns {Boolean|Object}
  2738. */
  2739. validate: function(validator, $field, options) {
  2740. var value = $field.val();
  2741. if (value === '') {
  2742. return true;
  2743. }
  2744. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  2745. var country = options.country;
  2746. if (!country) {
  2747. country = value.substr(0, 2);
  2748. } else if (typeof country !== 'string' || !this.REGEX[country]) {
  2749. // Determine the country code
  2750. country = validator.getDynamicOption($field, country);
  2751. }
  2752. if (!this.REGEX[country]) {
  2753. return {
  2754. valid: false,
  2755. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.iban.countryNotSupported, country)
  2756. };
  2757. }
  2758. if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  2759. return {
  2760. valid: false,
  2761. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  2762. };
  2763. }
  2764. value = value.substr(4) + value.substr(0, 4);
  2765. value = $.map(value.split(''), function(n) {
  2766. var code = n.charCodeAt(0);
  2767. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2768. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2769. ? (code - 'A'.charCodeAt(0) + 10)
  2770. : n;
  2771. });
  2772. value = value.join('');
  2773. var temp = parseInt(value.substr(0, 1), 10),
  2774. length = value.length;
  2775. for (var i = 1; i < length; ++i) {
  2776. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  2777. }
  2778. return {
  2779. valid: (temp === 1),
  2780. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.iban.country, $.fn.bootstrapValidator.i18n.iban.countries[country])
  2781. };
  2782. }
  2783. };
  2784. }(window.jQuery));
  2785. ;(function($) {
  2786. $.fn.bootstrapValidator.i18n.id = $.extend($.fn.bootstrapValidator.i18n.id || {}, {
  2787. 'default': 'Please enter a valid identification number',
  2788. countryNotSupported: 'The country code %s is not supported',
  2789. country: 'Please enter a valid %s identification number',
  2790. countries: {
  2791. BA: 'Bosnia and Herzegovina',
  2792. BG: 'Bulgarian',
  2793. BR: 'Brazilian',
  2794. CH: 'Swiss',
  2795. CL: 'Chilean',
  2796. CZ: 'Czech',
  2797. DK: 'Danish',
  2798. EE: 'Estonian',
  2799. ES: 'Spanish',
  2800. FI: 'Finnish',
  2801. HR: 'Croatian',
  2802. IE: 'Irish',
  2803. IS: 'Iceland',
  2804. LT: 'Lithuanian',
  2805. LV: 'Latvian',
  2806. ME: 'Montenegro',
  2807. MK: 'Macedonian',
  2808. NL: 'Dutch',
  2809. RO: 'Romanian',
  2810. RS: 'Serbian',
  2811. SE: 'Swedish',
  2812. SI: 'Slovenian',
  2813. SK: 'Slovak',
  2814. SM: 'San Marino',
  2815. ZA: 'South African'
  2816. }
  2817. });
  2818. $.fn.bootstrapValidator.validators.id = {
  2819. html5Attributes: {
  2820. message: 'message',
  2821. country: 'country'
  2822. },
  2823. // Supported country codes
  2824. COUNTRY_CODES: [
  2825. 'BA', 'BG', 'BR', 'CH', 'CL', 'CZ', 'DK', 'EE', 'ES', 'FI', 'HR', 'IE', 'IS', 'LT', 'LV', 'ME', 'MK', 'NL',
  2826. 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'ZA'
  2827. ],
  2828. /**
  2829. * Validate identification number in different countries
  2830. *
  2831. * @see http://en.wikipedia.org/wiki/National_identification_number
  2832. * @param {BootstrapValidator} validator The validator plugin instance
  2833. * @param {jQuery} $field Field element
  2834. * @param {Object} options Consist of key:
  2835. * - message: The invalid message
  2836. * - country: The ISO 3166-1 country code. It can be
  2837. * - One of country code defined in COUNTRY_CODES
  2838. * - Name of field which its value defines the country code
  2839. * - Name of callback function that returns the country code
  2840. * - A callback function that returns the country code
  2841. * @returns {Boolean|Object}
  2842. */
  2843. validate: function(validator, $field, options) {
  2844. var value = $field.val();
  2845. if (value === '') {
  2846. return true;
  2847. }
  2848. var country = options.country;
  2849. if (!country) {
  2850. country = value.substr(0, 2);
  2851. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  2852. // Determine the country code
  2853. country = validator.getDynamicOption($field, country);
  2854. }
  2855. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  2856. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.id.countryNotSupported, country) };
  2857. }
  2858. var method = ['_', country.toLowerCase()].join('');
  2859. return this[method](value)
  2860. ? true
  2861. : {
  2862. valid: false,
  2863. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.id.country, $.fn.bootstrapValidator.i18n.id.countries[country.toUpperCase()])
  2864. };
  2865. },
  2866. /**
  2867. * Validate Unique Master Citizen Number which uses in
  2868. * - Bosnia and Herzegovina (country code: BA)
  2869. * - Macedonia (MK)
  2870. * - Montenegro (ME)
  2871. * - Serbia (RS)
  2872. * - Slovenia (SI)
  2873. *
  2874. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  2875. * @param {String} value The ID
  2876. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  2877. * @returns {Boolean}
  2878. */
  2879. _validateJMBG: function(value, countryCode) {
  2880. if (!/^\d{13}$/.test(value)) {
  2881. return false;
  2882. }
  2883. var day = parseInt(value.substr(0, 2), 10),
  2884. month = parseInt(value.substr(2, 2), 10),
  2885. year = parseInt(value.substr(4, 3), 10),
  2886. rr = parseInt(value.substr(7, 2), 10),
  2887. k = parseInt(value.substr(12, 1), 10);
  2888. // Validate date of birth
  2889. // FIXME: Validate the year of birth
  2890. if (day > 31 || month > 12) {
  2891. return false;
  2892. }
  2893. // Validate checksum
  2894. var sum = 0;
  2895. for (var i = 0; i < 6; i++) {
  2896. sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  2897. }
  2898. sum = 11 - sum % 11;
  2899. if (sum === 10 || sum === 11) {
  2900. sum = 0;
  2901. }
  2902. if (sum !== k) {
  2903. return false;
  2904. }
  2905. // Validate political region
  2906. // rr is the political region of birth, which can be in ranges:
  2907. // 10-19: Bosnia and Herzegovina
  2908. // 20-29: Montenegro
  2909. // 30-39: Croatia (not used anymore)
  2910. // 41-49: Macedonia
  2911. // 50-59: Slovenia (only 50 is used)
  2912. // 70-79: Central Serbia
  2913. // 80-89: Serbian province of Vojvodina
  2914. // 90-99: Kosovo
  2915. switch (countryCode.toUpperCase()) {
  2916. case 'BA':
  2917. return (10 <= rr && rr <= 19);
  2918. case 'MK':
  2919. return (41 <= rr && rr <= 49);
  2920. case 'ME':
  2921. return (20 <= rr && rr <= 29);
  2922. case 'RS':
  2923. return (70 <= rr && rr <= 99);
  2924. case 'SI':
  2925. return (50 <= rr && rr <= 59);
  2926. default:
  2927. return true;
  2928. }
  2929. },
  2930. _ba: function(value) {
  2931. return this._validateJMBG(value, 'BA');
  2932. },
  2933. _mk: function(value) {
  2934. return this._validateJMBG(value, 'MK');
  2935. },
  2936. _me: function(value) {
  2937. return this._validateJMBG(value, 'ME');
  2938. },
  2939. _rs: function(value) {
  2940. return this._validateJMBG(value, 'RS');
  2941. },
  2942. /**
  2943. * Examples: 0101006500006
  2944. */
  2945. _si: function(value) {
  2946. return this._validateJMBG(value, 'SI');
  2947. },
  2948. /**
  2949. * Validate Bulgarian national identification number (EGN)
  2950. * Examples:
  2951. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  2952. * - Invalid: 8019010008
  2953. *
  2954. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  2955. * @param {String} value The ID
  2956. * @returns {Boolean}
  2957. */
  2958. _bg: function(value) {
  2959. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  2960. return false;
  2961. }
  2962. value = value.replace(/\s/g, '');
  2963. // Check the birth date
  2964. var year = parseInt(value.substr(0, 2), 10) + 1900,
  2965. month = parseInt(value.substr(2, 2), 10),
  2966. day = parseInt(value.substr(4, 2), 10);
  2967. if (month > 40) {
  2968. year += 100;
  2969. month -= 40;
  2970. } else if (month > 20) {
  2971. year -= 100;
  2972. month -= 20;
  2973. }
  2974. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2975. return false;
  2976. }
  2977. var sum = 0,
  2978. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2979. for (var i = 0; i < 9; i++) {
  2980. sum += parseInt(value.charAt(i), 10) * weight[i];
  2981. }
  2982. sum = (sum % 11) % 10;
  2983. return (sum + '' === value.substr(9, 1));
  2984. },
  2985. /**
  2986. * Validate Brazilian national identification number (CPF)
  2987. * Examples:
  2988. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  2989. * - Invalid: 231.002.999-00
  2990. *
  2991. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  2992. * @param {String} value The ID
  2993. * @returns {Boolean}
  2994. */
  2995. _br: function(value) {
  2996. if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  2997. return false;
  2998. }
  2999. if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
  3000. return false;
  3001. }
  3002. value = value.replace(/\./g, '').replace(/-/g, '');
  3003. var d1 = 0;
  3004. for (var i = 0; i < 9; i++) {
  3005. d1 += (10 - i) * parseInt(value.charAt(i), 10);
  3006. }
  3007. d1 = 11 - d1 % 11;
  3008. if (d1 === 10 || d1 === 11) {
  3009. d1 = 0;
  3010. }
  3011. if (d1 + '' !== value.charAt(9)) {
  3012. return false;
  3013. }
  3014. var d2 = 0;
  3015. for (i = 0; i < 10; i++) {
  3016. d2 += (11 - i) * parseInt(value.charAt(i), 10);
  3017. }
  3018. d2 = 11 - d2 % 11;
  3019. if (d2 === 10 || d2 === 11) {
  3020. d2 = 0;
  3021. }
  3022. return (d2 + '' === value.charAt(10));
  3023. },
  3024. /**
  3025. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  3026. * Examples:
  3027. * - Valid: 756.1234.5678.95, 7561234567895
  3028. *
  3029. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  3030. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  3031. * @param {String} value The ID
  3032. * @returns {Boolean}
  3033. */
  3034. _ch: function(value) {
  3035. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  3036. return false;
  3037. }
  3038. value = value.replace(/\D/g, '').substr(3);
  3039. var length = value.length,
  3040. sum = 0,
  3041. weight = (length === 8) ? [3, 1] : [1, 3];
  3042. for (var i = 0; i < length - 1; i++) {
  3043. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3044. }
  3045. sum = 10 - sum % 10;
  3046. return (sum + '' === value.charAt(length - 1));
  3047. },
  3048. /**
  3049. * Validate Chilean national identification number (RUN/RUT)
  3050. * Examples:
  3051. * - Valid: 76086428-5, 22060449-7, 12531909-2
  3052. *
  3053. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  3054. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  3055. * @param {String} value The ID
  3056. * @returns {Boolean}
  3057. */
  3058. _cl: function(value) {
  3059. if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
  3060. return false;
  3061. }
  3062. value = value.replace(/\-/g, '');
  3063. while (value.length < 9) {
  3064. value = '0' + value;
  3065. }
  3066. var sum = 0,
  3067. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  3068. for (var i = 0; i < 8; i++) {
  3069. sum += parseInt(value.charAt(i), 10) * weight[i];
  3070. }
  3071. sum = 11 - sum % 11;
  3072. if (sum === 11) {
  3073. sum = 0;
  3074. } else if (sum === 10) {
  3075. sum = 'K';
  3076. }
  3077. return sum + '' === value.charAt(8).toUpperCase();
  3078. },
  3079. /**
  3080. * Validate Czech national identification number (RC)
  3081. * Examples:
  3082. * - Valid: 7103192745, 991231123
  3083. * - Invalid: 1103492745, 590312123
  3084. *
  3085. * @param {String} value The ID
  3086. * @returns {Boolean}
  3087. */
  3088. _cz: function(value) {
  3089. if (!/^\d{9,10}$/.test(value)) {
  3090. return false;
  3091. }
  3092. var year = 1900 + parseInt(value.substr(0, 2), 10),
  3093. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  3094. day = parseInt(value.substr(4, 2), 10);
  3095. if (value.length === 9) {
  3096. if (year >= 1980) {
  3097. year -= 100;
  3098. }
  3099. if (year > 1953) {
  3100. return false;
  3101. }
  3102. } else if (year < 1954) {
  3103. year += 100;
  3104. }
  3105. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3106. return false;
  3107. }
  3108. // Check that the birth date is not in the future
  3109. if (value.length === 10) {
  3110. var check = parseInt(value.substr(0, 9), 10) % 11;
  3111. if (year < 1985) {
  3112. check = check % 10;
  3113. }
  3114. return (check + '' === value.substr(9, 1));
  3115. }
  3116. return true;
  3117. },
  3118. /**
  3119. * Validate Danish Personal Identification number (CPR)
  3120. * Examples:
  3121. * - Valid: 2110625629, 211062-5629
  3122. * - Invalid: 511062-5629
  3123. *
  3124. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  3125. * @param {String} value The ID
  3126. * @returns {Boolean}
  3127. */
  3128. _dk: function(value) {
  3129. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  3130. return false;
  3131. }
  3132. value = value.replace(/-/g, '');
  3133. var day = parseInt(value.substr(0, 2), 10),
  3134. month = parseInt(value.substr(2, 2), 10),
  3135. year = parseInt(value.substr(4, 2), 10);
  3136. switch (true) {
  3137. case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  3138. year += 1800;
  3139. break;
  3140. case ('0123'.indexOf(value.charAt(6)) !== -1):
  3141. case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  3142. year += 1900;
  3143. break;
  3144. default:
  3145. year += 2000;
  3146. break;
  3147. }
  3148. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  3149. },
  3150. /**
  3151. * Validate Estonian Personal Identification Code (isikukood)
  3152. * Examples:
  3153. * - Valid: 37605030299
  3154. *
  3155. * @see http://et.wikipedia.org/wiki/Isikukood
  3156. * @param {String} value The ID
  3157. * @returns {Boolean}
  3158. */
  3159. _ee: function(value) {
  3160. // Use the same format as Lithuanian Personal Code
  3161. return this._lt(value);
  3162. },
  3163. /**
  3164. * Validate Spanish personal identity code (DNI)
  3165. * Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
  3166. *
  3167. * Examples:
  3168. * - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
  3169. * - Invalid: i) 54362315Z; ii) X-2482300A
  3170. *
  3171. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  3172. * @param {String} value The ID
  3173. * @returns {Boolean}
  3174. */
  3175. _es: function(value) {
  3176. if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
  3177. && !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
  3178. return false;
  3179. }
  3180. value = value.replace(/-/g, '');
  3181. var index = 'XYZ'.indexOf(value.charAt(0));
  3182. if (index !== -1) {
  3183. // It is NIE number
  3184. value = index + value.substr(1) + '';
  3185. }
  3186. var check = parseInt(value.substr(0, 8), 10);
  3187. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  3188. return (check === value.substr(8, 1));
  3189. },
  3190. /**
  3191. * Validate Finnish Personal Identity Code (HETU)
  3192. * Examples:
  3193. * - Valid: 311280-888Y, 131052-308T
  3194. * - Invalid: 131052-308U, 310252-308Y
  3195. *
  3196. * @param {String} value The ID
  3197. * @returns {Boolean}
  3198. */
  3199. _fi: function(value) {
  3200. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  3201. return false;
  3202. }
  3203. var day = parseInt(value.substr(0, 2), 10),
  3204. month = parseInt(value.substr(2, 2), 10),
  3205. year = parseInt(value.substr(4, 2), 10),
  3206. centuries = {
  3207. '+': 1800,
  3208. '-': 1900,
  3209. 'A': 2000
  3210. };
  3211. year = centuries[value.charAt(6)] + year;
  3212. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3213. return false;
  3214. }
  3215. var individual = parseInt(value.substr(7, 3), 10);
  3216. if (individual < 2) {
  3217. return false;
  3218. }
  3219. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  3220. n = parseInt(n, 10);
  3221. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  3222. },
  3223. /**
  3224. * Validate Croatian personal identification number (OIB)
  3225. * Examples:
  3226. * - Valid: 33392005961
  3227. * - Invalid: 33392005962
  3228. *
  3229. * @param {String} value The ID
  3230. * @returns {Boolean}
  3231. */
  3232. _hr: function(value) {
  3233. if (!/^[0-9]{11}$/.test(value)) {
  3234. return false;
  3235. }
  3236. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  3237. },
  3238. /**
  3239. * Validate Irish Personal Public Service Number (PPS)
  3240. * Examples:
  3241. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  3242. * - Invalid: 6433435E, 6433435VH
  3243. *
  3244. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  3245. * @param {String} value The ID
  3246. * @returns {Boolean}
  3247. */
  3248. _ie: function(value) {
  3249. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  3250. return false;
  3251. }
  3252. var getCheckDigit = function(value) {
  3253. while (value.length < 7) {
  3254. value = '0' + value;
  3255. }
  3256. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  3257. sum = 0;
  3258. for (var i = 0; i < 7; i++) {
  3259. sum += parseInt(value.charAt(i), 10) * (8 - i);
  3260. }
  3261. sum += 9 * alphabet.indexOf(value.substr(7));
  3262. return alphabet[sum % 23];
  3263. };
  3264. // 2013 format
  3265. if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  3266. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  3267. }
  3268. // The old format
  3269. else {
  3270. return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  3271. }
  3272. },
  3273. /**
  3274. * Validate Iceland national identification number (Kennitala)
  3275. * Examples:
  3276. * - Valid: 120174-3399, 1201743399, 0902862349
  3277. *
  3278. * @see http://en.wikipedia.org/wiki/Kennitala
  3279. * @param {String} value The ID
  3280. * @returns {Boolean}
  3281. */
  3282. _is: function(value) {
  3283. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  3284. return false;
  3285. }
  3286. value = value.replace(/-/g, '');
  3287. var day = parseInt(value.substr(0, 2), 10),
  3288. month = parseInt(value.substr(2, 2), 10),
  3289. year = parseInt(value.substr(4, 2), 10),
  3290. century = parseInt(value.charAt(9), 10);
  3291. year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  3292. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  3293. return false;
  3294. }
  3295. // Validate the check digit
  3296. var sum = 0,
  3297. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  3298. for (var i = 0; i < 8; i++) {
  3299. sum += parseInt(value.charAt(i), 10) * weight[i];
  3300. }
  3301. sum = 11 - sum % 11;
  3302. return (sum + '' === value.charAt(8));
  3303. },
  3304. /**
  3305. * Validate Lithuanian Personal Code (Asmens kodas)
  3306. * Examples:
  3307. * - Valid: 38703181745
  3308. * - Invalid: 38703181746, 78703181745, 38703421745
  3309. *
  3310. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  3311. * @see http://www.adomas.org/midi2007/pcode.html
  3312. * @param {String} value The ID
  3313. * @returns {Boolean}
  3314. */
  3315. _lt: function(value) {
  3316. if (!/^[0-9]{11}$/.test(value)) {
  3317. return false;
  3318. }
  3319. var gender = parseInt(value.charAt(0), 10),
  3320. year = parseInt(value.substr(1, 2), 10),
  3321. month = parseInt(value.substr(3, 2), 10),
  3322. day = parseInt(value.substr(5, 2), 10),
  3323. century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  3324. year = century * 100 + year;
  3325. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  3326. return false;
  3327. }
  3328. // Validate the check digit
  3329. var sum = 0,
  3330. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  3331. for (var i = 0; i < 10; i++) {
  3332. sum += parseInt(value.charAt(i), 10) * weight[i];
  3333. }
  3334. sum = sum % 11;
  3335. if (sum !== 10) {
  3336. return sum + '' === value.charAt(10);
  3337. }
  3338. // Re-calculate the check digit
  3339. sum = 0;
  3340. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  3341. for (i = 0; i < 10; i++) {
  3342. sum += parseInt(value.charAt(i), 10) * weight[i];
  3343. }
  3344. sum = sum % 11;
  3345. if (sum === 10) {
  3346. sum = 0;
  3347. }
  3348. return (sum + '' === value.charAt(10));
  3349. },
  3350. /**
  3351. * Validate Latvian Personal Code (Personas kods)
  3352. * Examples:
  3353. * - Valid: 161175-19997, 16117519997
  3354. * - Invalid: 161375-19997
  3355. *
  3356. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  3357. * @param {String} value The ID
  3358. * @returns {Boolean}
  3359. */
  3360. _lv: function(value) {
  3361. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  3362. return false;
  3363. }
  3364. value = value.replace(/\D/g, '');
  3365. // Check birth date
  3366. var day = parseInt(value.substr(0, 2), 10),
  3367. month = parseInt(value.substr(2, 2), 10),
  3368. year = parseInt(value.substr(4, 2), 10);
  3369. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  3370. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  3371. return false;
  3372. }
  3373. // Check personal code
  3374. var sum = 0,
  3375. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  3376. for (var i = 0; i < 10; i++) {
  3377. sum += parseInt(value.charAt(i), 10) * weight[i];
  3378. }
  3379. sum = (sum + 1) % 11 % 10;
  3380. return (sum + '' === value.charAt(10));
  3381. },
  3382. /**
  3383. * Validate Dutch national identification number (BSN)
  3384. * Examples:
  3385. * - Valid: 111222333, 941331490, 9413.31.490
  3386. * - Invalid: 111252333
  3387. *
  3388. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  3389. * @param {String} value The ID
  3390. * @returns {Boolean}
  3391. */
  3392. _nl: function(value) {
  3393. while (value.length < 9) {
  3394. value = '0' + value;
  3395. }
  3396. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  3397. return false;
  3398. }
  3399. value = value.replace(/\./g, '');
  3400. if (parseInt(value, 10) === 0) {
  3401. return false;
  3402. }
  3403. var sum = 0,
  3404. length = value.length;
  3405. for (var i = 0; i < length - 1; i++) {
  3406. sum += (9 - i) * parseInt(value.charAt(i), 10);
  3407. }
  3408. sum = sum % 11;
  3409. if (sum === 10) {
  3410. sum = 0;
  3411. }
  3412. return (sum + '' === value.charAt(length - 1));
  3413. },
  3414. /**
  3415. * Validate Romanian numerical personal code (CNP)
  3416. * Examples:
  3417. * - Valid: 1630615123457, 1800101221144
  3418. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  3419. *
  3420. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  3421. * @param {String} value The ID
  3422. * @returns {Boolean}
  3423. */
  3424. _ro: function(value) {
  3425. if (!/^[0-9]{13}$/.test(value)) {
  3426. return false;
  3427. }
  3428. var gender = parseInt(value.charAt(0), 10);
  3429. if (gender === 0 || gender === 7 || gender === 8) {
  3430. return false;
  3431. }
  3432. // Determine the date of birth
  3433. var year = parseInt(value.substr(1, 2), 10),
  3434. month = parseInt(value.substr(3, 2), 10),
  3435. day = parseInt(value.substr(5, 2), 10),
  3436. // The year of date is determined base on the gender
  3437. centuries = {
  3438. '1': 1900, // Male born between 1900 and 1999
  3439. '2': 1900, // Female born between 1900 and 1999
  3440. '3': 1800, // Male born between 1800 and 1899
  3441. '4': 1800, // Female born between 1800 and 1899
  3442. '5': 2000, // Male born after 2000
  3443. '6': 2000 // Female born after 2000
  3444. };
  3445. if (day > 31 && month > 12) {
  3446. return false;
  3447. }
  3448. if (gender !== 9) {
  3449. year = centuries[gender + ''] + year;
  3450. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3451. return false;
  3452. }
  3453. }
  3454. // Validate the check digit
  3455. var sum = 0,
  3456. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  3457. length = value.length;
  3458. for (var i = 0; i < length - 1; i++) {
  3459. sum += parseInt(value.charAt(i), 10) * weight[i];
  3460. }
  3461. sum = sum % 11;
  3462. if (sum === 10) {
  3463. sum = 1;
  3464. }
  3465. return (sum + '' === value.charAt(length - 1));
  3466. },
  3467. /**
  3468. * Validate Swedish personal identity number (personnummer)
  3469. * Examples:
  3470. * - Valid: 8112289874, 811228-9874, 811228+9874
  3471. * - Invalid: 811228-9873
  3472. *
  3473. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  3474. * @param {String} value The ID
  3475. * @returns {Boolean}
  3476. */
  3477. _se: function(value) {
  3478. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  3479. return false;
  3480. }
  3481. value = value.replace(/[^0-9]/g, '');
  3482. var year = parseInt(value.substr(0, 2), 10) + 1900,
  3483. month = parseInt(value.substr(2, 2), 10),
  3484. day = parseInt(value.substr(4, 2), 10);
  3485. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3486. return false;
  3487. }
  3488. // Validate the last check digit
  3489. return $.fn.bootstrapValidator.helpers.luhn(value);
  3490. },
  3491. /**
  3492. * Validate Slovak national identifier number (RC)
  3493. * Examples:
  3494. * - Valid: 7103192745, 991231123
  3495. * - Invalid: 7103192746, 1103492745
  3496. *
  3497. * @param {String} value The ID
  3498. * @returns {Boolean}
  3499. */
  3500. _sk: function(value) {
  3501. // Slovakia uses the same format as Czech Republic
  3502. return this._cz(value);
  3503. },
  3504. /**
  3505. * Validate San Marino citizen number
  3506. *
  3507. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  3508. * @param {String} value The ID
  3509. * @returns {Boolean}
  3510. */
  3511. _sm: function(value) {
  3512. return /^\d{5}$/.test(value);
  3513. },
  3514. /**
  3515. * Validate South African ID
  3516. * Example:
  3517. * - Valid: 8001015009087
  3518. * - Invalid: 8001015009287, 8001015009086
  3519. *
  3520. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  3521. * @param {String} value The ID
  3522. * @returns {Boolean}
  3523. */
  3524. _za: function(value) {
  3525. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  3526. return false;
  3527. }
  3528. var year = parseInt(value.substr(0, 2), 10),
  3529. currentYear = new Date().getFullYear() % 100,
  3530. month = parseInt(value.substr(2, 2), 10),
  3531. day = parseInt(value.substr(4, 2), 10);
  3532. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  3533. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3534. return false;
  3535. }
  3536. // Validate the last check digit
  3537. return $.fn.bootstrapValidator.helpers.luhn(value);
  3538. }
  3539. };
  3540. }(window.jQuery));
  3541. ;(function($) {
  3542. $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
  3543. 'default': 'Please enter the same value'
  3544. });
  3545. $.fn.bootstrapValidator.validators.identical = {
  3546. html5Attributes: {
  3547. message: 'message',
  3548. field: 'field'
  3549. },
  3550. /**
  3551. * Check if input value equals to value of particular one
  3552. *
  3553. * @param {BootstrapValidator} validator The validator plugin instance
  3554. * @param {jQuery} $field Field element
  3555. * @param {Object} options Consists of the following key:
  3556. * - field: The name of field that will be used to compare with current one
  3557. * @returns {Boolean}
  3558. */
  3559. validate: function(validator, $field, options) {
  3560. var value = $field.val();
  3561. if (value === '') {
  3562. return true;
  3563. }
  3564. var compareWith = validator.getFieldElements(options.field);
  3565. if (compareWith === null || compareWith.length === 0) {
  3566. return true;
  3567. }
  3568. if (value === compareWith.val()) {
  3569. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  3570. return true;
  3571. } else {
  3572. return false;
  3573. }
  3574. }
  3575. };
  3576. }(window.jQuery));
  3577. ;(function($) {
  3578. $.fn.bootstrapValidator.i18n.imei = $.extend($.fn.bootstrapValidator.i18n.imei || {}, {
  3579. 'default': 'Please enter a valid IMEI number'
  3580. });
  3581. $.fn.bootstrapValidator.validators.imei = {
  3582. /**
  3583. * Validate IMEI (International Mobile Station Equipment Identity)
  3584. * Examples:
  3585. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  3586. * - Invalid: 490154203237517
  3587. *
  3588. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  3589. * @param {BootstrapValidator} validator The validator plugin instance
  3590. * @param {jQuery} $field Field element
  3591. * @param {Object} options Can consist of the following keys:
  3592. * - message: The invalid message
  3593. * @returns {Boolean}
  3594. */
  3595. validate: function(validator, $field, options) {
  3596. var value = $field.val();
  3597. if (value === '') {
  3598. return true;
  3599. }
  3600. switch (true) {
  3601. case /^\d{15}$/.test(value):
  3602. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  3603. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  3604. value = value.replace(/[^0-9]/g, '');
  3605. return $.fn.bootstrapValidator.helpers.luhn(value);
  3606. case /^\d{14}$/.test(value):
  3607. case /^\d{16}$/.test(value):
  3608. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  3609. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  3610. return true;
  3611. default:
  3612. return false;
  3613. }
  3614. }
  3615. };
  3616. }(window.jQuery));
  3617. ;(function($) {
  3618. $.fn.bootstrapValidator.i18n.imo = $.extend($.fn.bootstrapValidator.i18n.imo || {}, {
  3619. 'default': 'Please enter a valid IMO number'
  3620. });
  3621. $.fn.bootstrapValidator.validators.imo = {
  3622. /**
  3623. * Validate IMO (International Maritime Organization)
  3624. * Examples:
  3625. * - Valid: IMO 8814275, IMO 9176187
  3626. * - Invalid: IMO 8814274
  3627. *
  3628. * @see http://en.wikipedia.org/wiki/IMO_Number
  3629. * @param {BootstrapValidator} validator The validator plugin instance
  3630. * @param {jQuery} $field Field element
  3631. * @param {Object} options Can consist of the following keys:
  3632. * - message: The invalid message
  3633. * @returns {Boolean}
  3634. */
  3635. validate: function(validator, $field, options) {
  3636. var value = $field.val();
  3637. if (value === '') {
  3638. return true;
  3639. }
  3640. if (!/^IMO \d{7}$/i.test(value)) {
  3641. return false;
  3642. }
  3643. // Grab just the digits
  3644. var sum = 0,
  3645. digits = value.replace(/^.*(\d{7})$/, '$1');
  3646. // Go over each char, multiplying by the inverse of it's position
  3647. // IMO 9176187
  3648. // (9 * 7) + (1 * 6) + (7 * 5) + (6 * 4) + (1 * 3) + (8 * 2) = 147
  3649. // Take the last digit of that, that's the check digit (7)
  3650. for (var i = 6; i >= 1; i--) {
  3651. sum += (digits.slice((6 - i), -i) * (i + 1));
  3652. }
  3653. return sum % 10 === parseInt(digits.charAt(6), 10);
  3654. }
  3655. };
  3656. }(window.jQuery));
  3657. ;(function($) {
  3658. $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
  3659. 'default': 'Please enter a valid number'
  3660. });
  3661. $.fn.bootstrapValidator.validators.integer = {
  3662. enableByHtml5: function($field) {
  3663. return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
  3664. },
  3665. /**
  3666. * Return true if the input value is an integer
  3667. *
  3668. * @param {BootstrapValidator} validator The validator plugin instance
  3669. * @param {jQuery} $field Field element
  3670. * @param {Object} options Can consist of the following key:
  3671. * - message: The invalid message
  3672. * @returns {Boolean}
  3673. */
  3674. validate: function(validator, $field, options) {
  3675. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  3676. return false;
  3677. }
  3678. var value = $field.val();
  3679. if (value === '') {
  3680. return true;
  3681. }
  3682. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  3683. }
  3684. };
  3685. }(window.jQuery));
  3686. ;(function($) {
  3687. $.fn.bootstrapValidator.i18n.ip = $.extend($.fn.bootstrapValidator.i18n.ip || {}, {
  3688. 'default': 'Please enter a valid IP address',
  3689. ipv4: 'Please enter a valid IPv4 address',
  3690. ipv6: 'Please enter a valid IPv6 address'
  3691. });
  3692. $.fn.bootstrapValidator.validators.ip = {
  3693. html5Attributes: {
  3694. message: 'message',
  3695. ipv4: 'ipv4',
  3696. ipv6: 'ipv6'
  3697. },
  3698. /**
  3699. * Return true if the input value is a IP address.
  3700. *
  3701. * @param {BootstrapValidator} validator The validator plugin instance
  3702. * @param {jQuery} $field Field element
  3703. * @param {Object} options Can consist of the following keys:
  3704. * - ipv4: Enable IPv4 validator, default to true
  3705. * - ipv6: Enable IPv6 validator, default to true
  3706. * - message: The invalid message
  3707. * @returns {Boolean|Object}
  3708. */
  3709. validate: function(validator, $field, options) {
  3710. var value = $field.val();
  3711. if (value === '') {
  3712. return true;
  3713. }
  3714. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  3715. 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]?)$/,
  3716. 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*$/,
  3717. valid = false,
  3718. message;
  3719. switch (true) {
  3720. case (options.ipv4 && !options.ipv6):
  3721. valid = ipv4Regex.test(value);
  3722. message = options.message || $.fn.bootstrapValidator.i18n.ip.ipv4;
  3723. break;
  3724. case (!options.ipv4 && options.ipv6):
  3725. valid = ipv6Regex.test(value);
  3726. message = options.message || $.fn.bootstrapValidator.i18n.ip.ipv6;
  3727. break;
  3728. case (options.ipv4 && options.ipv6):
  3729. /* falls through */
  3730. default:
  3731. valid = ipv4Regex.test(value) && ipv6Regex.test(value);
  3732. message = options.message || $.fn.bootstrapValidator.i18n.ip['default'];
  3733. break;
  3734. }
  3735. return {
  3736. valid: valid,
  3737. message: message
  3738. };
  3739. }
  3740. };
  3741. }(window.jQuery));;(function($) {
  3742. $.fn.bootstrapValidator.i18n.isbn = $.extend($.fn.bootstrapValidator.i18n.isbn || {}, {
  3743. 'default': 'Please enter a valid ISBN number'
  3744. });
  3745. $.fn.bootstrapValidator.validators.isbn = {
  3746. /**
  3747. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  3748. * Examples:
  3749. * - Valid:
  3750. * 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
  3751. * ISBN 13: 978-0-306-40615-7
  3752. * - Invalid:
  3753. * ISBN 10: 99921-58-10-6
  3754. * ISBN 13: 978-0-306-40615-6
  3755. *
  3756. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  3757. * @param {BootstrapValidator} validator The validator plugin instance
  3758. * @param {jQuery} $field Field element
  3759. * @param {Object} [options] Can consist of the following keys:
  3760. * - message: The invalid message
  3761. * @returns {Boolean}
  3762. */
  3763. validate: function(validator, $field, options) {
  3764. var value = $field.val();
  3765. if (value === '') {
  3766. return true;
  3767. }
  3768. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  3769. // Groups are separated by a hyphen or a space
  3770. var type;
  3771. switch (true) {
  3772. case /^\d{9}[\dX]$/.test(value):
  3773. case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  3774. case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  3775. type = 'ISBN10';
  3776. break;
  3777. case /^(978|979)\d{9}[\dX]$/.test(value):
  3778. case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  3779. case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  3780. type = 'ISBN13';
  3781. break;
  3782. default:
  3783. return false;
  3784. }
  3785. // Replace all special characters except digits and X
  3786. value = value.replace(/[^0-9X]/gi, '');
  3787. var chars = value.split(''),
  3788. length = chars.length,
  3789. sum = 0,
  3790. i,
  3791. checksum;
  3792. switch (type) {
  3793. case 'ISBN10':
  3794. sum = 0;
  3795. for (i = 0; i < length - 1; i++) {
  3796. sum += parseInt(chars[i], 10) * (10 - i);
  3797. }
  3798. checksum = 11 - (sum % 11);
  3799. if (checksum === 11) {
  3800. checksum = 0;
  3801. } else if (checksum === 10) {
  3802. checksum = 'X';
  3803. }
  3804. return (checksum + '' === chars[length - 1]);
  3805. case 'ISBN13':
  3806. sum = 0;
  3807. for (i = 0; i < length - 1; i++) {
  3808. sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  3809. }
  3810. checksum = 10 - (sum % 10);
  3811. if (checksum === 10) {
  3812. checksum = '0';
  3813. }
  3814. return (checksum + '' === chars[length - 1]);
  3815. default:
  3816. return false;
  3817. }
  3818. }
  3819. };
  3820. }(window.jQuery));
  3821. ;(function($) {
  3822. $.fn.bootstrapValidator.i18n.isin = $.extend($.fn.bootstrapValidator.i18n.isin || {}, {
  3823. 'default': 'Please enter a valid ISIN number'
  3824. });
  3825. $.fn.bootstrapValidator.validators.isin = {
  3826. // Available country codes
  3827. // See http://isin.net/country-codes/
  3828. 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',
  3829. /**
  3830. * Validate an ISIN (International Securities Identification Number)
  3831. * Examples:
  3832. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  3833. * - Invalid: US0378331004, AA0000XVGZA3
  3834. *
  3835. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  3836. * @param {BootstrapValidator} validator The validator plugin instance
  3837. * @param {jQuery} $field Field element
  3838. * @param {Object} options Can consist of the following keys:
  3839. * - message: The invalid message
  3840. * @returns {Boolean}
  3841. */
  3842. validate: function(validator, $field, options) {
  3843. var value = $field.val();
  3844. if (value === '') {
  3845. return true;
  3846. }
  3847. value = value.toUpperCase();
  3848. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  3849. if (!regex.test(value)) {
  3850. return false;
  3851. }
  3852. var converted = '',
  3853. length = value.length;
  3854. // Convert letters to number
  3855. for (var i = 0; i < length - 1; i++) {
  3856. var c = value.charCodeAt(i);
  3857. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  3858. }
  3859. var digits = '',
  3860. n = converted.length,
  3861. group = (n % 2 !== 0) ? 0 : 1;
  3862. for (i = 0; i < n; i++) {
  3863. digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  3864. }
  3865. var sum = 0;
  3866. for (i = 0; i < digits.length; i++) {
  3867. sum += parseInt(digits.charAt(i), 10);
  3868. }
  3869. sum = (10 - (sum % 10)) % 10;
  3870. return sum + '' === value.charAt(length - 1);
  3871. }
  3872. };
  3873. }(window.jQuery));
  3874. ;(function($) {
  3875. $.fn.bootstrapValidator.i18n.ismn = $.extend($.fn.bootstrapValidator.i18n.ismn || {}, {
  3876. 'default': 'Please enter a valid ISMN number'
  3877. });
  3878. $.fn.bootstrapValidator.validators.ismn = {
  3879. /**
  3880. * Validate ISMN (International Standard Music Number)
  3881. * Examples:
  3882. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  3883. * - Invalid: 9790060115614
  3884. *
  3885. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  3886. * @param {BootstrapValidator} validator The validator plugin instance
  3887. * @param {jQuery} $field Field element
  3888. * @param {Object} options Can consist of the following keys:
  3889. * - message: The invalid message
  3890. * @returns {Boolean}
  3891. */
  3892. validate: function(validator, $field, options) {
  3893. var value = $field.val();
  3894. if (value === '') {
  3895. return true;
  3896. }
  3897. // Groups are separated by a hyphen or a space
  3898. var type;
  3899. switch (true) {
  3900. case /^M\d{9}$/.test(value):
  3901. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  3902. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3903. type = 'ISMN10';
  3904. break;
  3905. case /^9790\d{9}$/.test(value):
  3906. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  3907. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3908. type = 'ISMN13';
  3909. break;
  3910. default:
  3911. return false;
  3912. }
  3913. if ('ISMN10' === type) {
  3914. value = '9790' + value.substr(1);
  3915. }
  3916. // Replace all special characters except digits
  3917. value = value.replace(/[^0-9]/gi, '');
  3918. var length = value.length,
  3919. sum = 0,
  3920. weight = [1, 3];
  3921. for (var i = 0; i < length - 1; i++) {
  3922. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3923. }
  3924. sum = 10 - sum % 10;
  3925. return (sum + '' === value.charAt(length - 1));
  3926. }
  3927. };
  3928. }(window.jQuery));
  3929. ;(function($) {
  3930. $.fn.bootstrapValidator.i18n.issn = $.extend($.fn.bootstrapValidator.i18n.issn || {}, {
  3931. 'default': 'Please enter a valid ISSN number'
  3932. });
  3933. $.fn.bootstrapValidator.validators.issn = {
  3934. /**
  3935. * Validate ISSN (International Standard Serial Number)
  3936. * Examples:
  3937. * - Valid: 0378-5955, 0024-9319, 0032-1478
  3938. * - Invalid: 0032-147X
  3939. *
  3940. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  3941. * @param {BootstrapValidator} validator The validator plugin instance
  3942. * @param {jQuery} $field Field element
  3943. * @param {Object} options Can consist of the following keys:
  3944. * - message: The invalid message
  3945. * @returns {Boolean}
  3946. */
  3947. validate: function(validator, $field, options) {
  3948. var value = $field.val();
  3949. if (value === '') {
  3950. return true;
  3951. }
  3952. // Groups are separated by a hyphen or a space
  3953. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  3954. return false;
  3955. }
  3956. // Replace all special characters except digits and X
  3957. value = value.replace(/[^0-9X]/gi, '');
  3958. var chars = value.split(''),
  3959. length = chars.length,
  3960. sum = 0;
  3961. if (chars[7] === 'X') {
  3962. chars[7] = 10;
  3963. }
  3964. for (var i = 0; i < length; i++) {
  3965. sum += parseInt(chars[i], 10) * (8 - i);
  3966. }
  3967. return (sum % 11 === 0);
  3968. }
  3969. };
  3970. }(window.jQuery));
  3971. ;(function($) {
  3972. $.fn.bootstrapValidator.i18n.lessThan = $.extend($.fn.bootstrapValidator.i18n.lessThan || {}, {
  3973. 'default': 'Please enter a value less than or equal to %s',
  3974. notInclusive: 'Please enter a value less than %s'
  3975. });
  3976. $.fn.bootstrapValidator.validators.lessThan = {
  3977. html5Attributes: {
  3978. message: 'message',
  3979. value: 'value',
  3980. inclusive: 'inclusive'
  3981. },
  3982. enableByHtml5: function($field) {
  3983. var type = $field.attr('type'),
  3984. max = $field.attr('max');
  3985. if (max && type !== 'date') {
  3986. return {
  3987. value: max
  3988. };
  3989. }
  3990. return false;
  3991. },
  3992. /**
  3993. * Return true if the input value is less than or equal to given number
  3994. *
  3995. * @param {BootstrapValidator} validator The validator plugin instance
  3996. * @param {jQuery} $field Field element
  3997. * @param {Object} options Can consist of the following keys:
  3998. * - value: The number used to compare to. It can be
  3999. * - A number
  4000. * - Name of field which its value defines the number
  4001. * - Name of callback function that returns the number
  4002. * - A callback function that returns the number
  4003. *
  4004. * - inclusive [optional]: Can be true or false. Default is true
  4005. * - message: The invalid message
  4006. * @returns {Boolean|Object}
  4007. */
  4008. validate: function(validator, $field, options) {
  4009. var value = $field.val();
  4010. if (value === '') {
  4011. return true;
  4012. }
  4013. if (!$.isNumeric(value)) {
  4014. return false;
  4015. }
  4016. var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
  4017. value = parseFloat(value);
  4018. return (options.inclusive === true || options.inclusive === undefined)
  4019. ? {
  4020. valid: value <= compareTo,
  4021. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan['default'], compareTo)
  4022. }
  4023. : {
  4024. valid: value < compareTo,
  4025. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.lessThan.notInclusive, compareTo)
  4026. };
  4027. }
  4028. };
  4029. }(window.jQuery));
  4030. ;(function($) {
  4031. $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
  4032. 'default': 'Please enter a valid MAC address'
  4033. });
  4034. $.fn.bootstrapValidator.validators.mac = {
  4035. /**
  4036. * Return true if the input value is a MAC address.
  4037. *
  4038. * @param {BootstrapValidator} validator The validator plugin instance
  4039. * @param {jQuery} $field Field element
  4040. * @param {Object} options Can consist of the following keys:
  4041. * - message: The invalid message
  4042. * @returns {Boolean}
  4043. */
  4044. validate: function(validator, $field, options) {
  4045. var value = $field.val();
  4046. if (value === '') {
  4047. return true;
  4048. }
  4049. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  4050. }
  4051. };
  4052. }(window.jQuery));
  4053. ;(function($) {
  4054. $.fn.bootstrapValidator.i18n.meid = $.extend($.fn.bootstrapValidator.i18n.meid || {}, {
  4055. 'default': 'Please enter a valid MEID number'
  4056. });
  4057. $.fn.bootstrapValidator.validators.meid = {
  4058. /**
  4059. * Validate MEID (Mobile Equipment Identifier)
  4060. * Examples:
  4061. * - Valid: 293608736500703710, 29360-87365-0070-3710, AF0123450ABCDE, AF-012345-0ABCDE
  4062. * - Invalid: 2936087365007037101
  4063. *
  4064. * @see http://en.wikipedia.org/wiki/Mobile_equipment_identifier
  4065. * @param {BootstrapValidator} validator The validator plugin instance
  4066. * @param {jQuery} $field Field element
  4067. * @param {Object} options Can consist of the following keys:
  4068. * - message: The invalid message
  4069. * @returns {Boolean}
  4070. */
  4071. validate: function(validator, $field, options) {
  4072. var value = $field.val();
  4073. if (value === '') {
  4074. return true;
  4075. }
  4076. switch (true) {
  4077. // 14 digit hex representation (no check digit)
  4078. case /^[0-9A-F]{15}$/i.test(value):
  4079. // 14 digit hex representation + dashes or spaces (no check digit)
  4080. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}[- ][0-9A-F]$/i.test(value):
  4081. // 18 digit decimal representation (no check digit)
  4082. case /^\d{19}$/.test(value):
  4083. // 18 digit decimal representation + dashes or spaces (no check digit)
  4084. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}[- ]\d$/.test(value):
  4085. // Grab the check digit
  4086. var cd = value.charAt(value.length - 1);
  4087. // Strip any non-hex chars
  4088. value = value.replace(/[- ]/g, '');
  4089. // If it's all digits, luhn base 10 is used
  4090. if (value.match(/^\d*$/i)) {
  4091. return $.fn.bootstrapValidator.helpers.luhn(value);
  4092. }
  4093. // Strip the check digit
  4094. value = value.slice(0, -1);
  4095. // Get every other char, and double it
  4096. var cdCalc = '';
  4097. for (var i = 1; i <= 13; i += 2) {
  4098. cdCalc += (parseInt(value.charAt(i), 16) * 2).toString(16);
  4099. }
  4100. // Get the sum of each char in the string
  4101. var sum = 0;
  4102. for (i = 0; i < cdCalc.length; i++) {
  4103. sum += parseInt(cdCalc.charAt(i), 16);
  4104. }
  4105. // If the last digit of the calc is 0, the check digit is 0
  4106. return (sum % 10 === 0)
  4107. ? (cd === '0')
  4108. // Subtract it from the next highest 10s number (64 goes to 70) and subtract the sum
  4109. // Double it and turn it into a hex char
  4110. : (cd === ((Math.floor((sum + 10) / 10) * 10 - sum) * 2).toString(16));
  4111. // 14 digit hex representation (no check digit)
  4112. case /^[0-9A-F]{14}$/i.test(value):
  4113. // 14 digit hex representation + dashes or spaces (no check digit)
  4114. case /^[0-9A-F]{2}[- ][0-9A-F]{6}[- ][0-9A-F]{6}$/i.test(value):
  4115. // 18 digit decimal representation (no check digit)
  4116. case /^\d{18}$/.test(value):
  4117. // 18 digit decimal representation + dashes or spaces (no check digit)
  4118. case /^\d{5}[- ]\d{5}[- ]\d{4}[- ]\d{4}$/.test(value):
  4119. return true;
  4120. default:
  4121. return false;
  4122. }
  4123. }
  4124. };
  4125. }(window.jQuery));
  4126. ;(function($) {
  4127. $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
  4128. 'default': 'Please enter a value'
  4129. });
  4130. $.fn.bootstrapValidator.validators.notEmpty = {
  4131. enableByHtml5: function($field) {
  4132. var required = $field.attr('required') + '';
  4133. return ('required' === required || 'true' === required);
  4134. },
  4135. /**
  4136. * Check if input value is empty or not
  4137. *
  4138. * @param {BootstrapValidator} validator The validator plugin instance
  4139. * @param {jQuery} $field Field element
  4140. * @param {Object} options
  4141. * @returns {Boolean}
  4142. */
  4143. validate: function(validator, $field, options) {
  4144. var type = $field.attr('type');
  4145. if ('radio' === type || 'checkbox' === type) {
  4146. return validator
  4147. .getFieldElements($field.attr('data-bv-field'))
  4148. .filter(':checked')
  4149. .length > 0;
  4150. }
  4151. return $.trim($field.val()) !== '';
  4152. }
  4153. };
  4154. }(window.jQuery));
  4155. ;(function($) {
  4156. $.fn.bootstrapValidator.i18n.numeric = $.extend($.fn.bootstrapValidator.i18n.numeric || {}, {
  4157. 'default': 'Please enter a valid float number'
  4158. });
  4159. $.fn.bootstrapValidator.validators.numeric = {
  4160. html5Attributes: {
  4161. message: 'message',
  4162. separator: 'separator'
  4163. },
  4164. enableByHtml5: function($field) {
  4165. return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
  4166. },
  4167. /**
  4168. * Validate decimal number
  4169. *
  4170. * @param {BootstrapValidator} validator The validator plugin instance
  4171. * @param {jQuery} $field Field element
  4172. * @param {Object} options Consist of key:
  4173. * - message: The invalid message
  4174. * - separator: The decimal separator. Can be "." (default), ","
  4175. * @returns {Boolean}
  4176. */
  4177. validate: function(validator, $field, options) {
  4178. if (this.enableByHtml5($field) && $field.get(0).validity && $field.get(0).validity.badInput === true) {
  4179. return false;
  4180. }
  4181. var value = $field.val();
  4182. if (value === '') {
  4183. return true;
  4184. }
  4185. var separator = options.separator || '.';
  4186. if (separator !== '.') {
  4187. value = value.replace(separator, '.');
  4188. }
  4189. return !isNaN(parseFloat(value)) && isFinite(value);
  4190. }
  4191. };
  4192. }(window.jQuery));
  4193. ;(function($) {
  4194. $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
  4195. 'default': 'Please enter a valid phone number',
  4196. countryNotSupported: 'The country code %s is not supported',
  4197. country: 'Please enter a valid phone number in %s',
  4198. countries: {
  4199. BR: 'Brazil',
  4200. ES: 'Spain',
  4201. FR: 'France',
  4202. GB: 'United Kingdom',
  4203. MA: 'Morocco',
  4204. PK: 'Pakistan',
  4205. US: 'USA'
  4206. }
  4207. });
  4208. $.fn.bootstrapValidator.validators.phone = {
  4209. html5Attributes: {
  4210. message: 'message',
  4211. country: 'country'
  4212. },
  4213. // The supported countries
  4214. COUNTRY_CODES: ['BR', 'ES', 'FR', 'GB', 'MA', 'PK', 'US'],
  4215. /**
  4216. * Return true if the input value contains a valid phone number for the country
  4217. * selected in the options
  4218. *
  4219. * @param {BootstrapValidator} validator Validate plugin instance
  4220. * @param {jQuery} $field Field element
  4221. * @param {Object} options Consist of key:
  4222. * - message: The invalid message
  4223. * - country: The ISO-3166 country code. It can be
  4224. * - A country code
  4225. * - Name of field which its value defines the country code
  4226. * - Name of callback function that returns the country code
  4227. * - A callback function that returns the country code
  4228. *
  4229. * @returns {Boolean|Object}
  4230. */
  4231. validate: function(validator, $field, options) {
  4232. var value = $field.val();
  4233. if (value === '') {
  4234. return true;
  4235. }
  4236. var country = options.country;
  4237. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  4238. // Try to determine the country
  4239. country = validator.getDynamicOption($field, country);
  4240. }
  4241. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  4242. return {
  4243. valid: false,
  4244. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.phone.countryNotSupported, country)
  4245. };
  4246. }
  4247. var isValid = true;
  4248. switch (country.toUpperCase()) {
  4249. case 'BR':
  4250. // Test: http://regexr.com/399m1
  4251. value = $.trim(value);
  4252. 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);
  4253. break;
  4254. case 'ES':
  4255. // http://regex101.com/r/rB9mA9/1
  4256. value = $.trim(value);
  4257. isValid = (/^(?:(?:(?:\+|00)34\D?))?(?:9|6)(?:\d\D?){8}$/).test(value);
  4258. break;
  4259. case 'FR':
  4260. // http://regexr.com/39a2p
  4261. value = $.trim(value);
  4262. isValid = (/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/).test(value);
  4263. break;
  4264. case 'GB':
  4265. // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  4266. // Test: http://regexr.com/38uhv
  4267. value = $.trim(value);
  4268. 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);
  4269. break;
  4270. case 'MA':
  4271. // http://en.wikipedia.org/wiki/Telephone_numbers_in_Morocco
  4272. // Test: http://regexr.com/399n8
  4273. value = $.trim(value);
  4274. 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);
  4275. break;
  4276. case 'PK':
  4277. // http://regex101.com/r/yH8aV9/2
  4278. value = $.trim(value);
  4279. isValid = (/^0?3[0-9]{2}[0-9]{7}$/).test(value);
  4280. break;
  4281. case 'US':
  4282. /* falls through */
  4283. default:
  4284. // Make sure US phone numbers have 10 digits
  4285. // May start with 1, +1, or 1-; should discard
  4286. // Area code may be delimited with (), & sections may be delimited with . or -
  4287. // Test: http://regexr.com/38mqi
  4288. value = value.replace(/\D/g, '');
  4289. isValid = (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
  4290. break;
  4291. }
  4292. return {
  4293. valid: isValid,
  4294. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.phone.country, $.fn.bootstrapValidator.i18n.phone.countries[country])
  4295. };
  4296. }
  4297. };
  4298. }(window.jQuery));
  4299. ;(function($) {
  4300. $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
  4301. 'default': 'Please enter a value matching the pattern'
  4302. });
  4303. $.fn.bootstrapValidator.validators.regexp = {
  4304. html5Attributes: {
  4305. message: 'message',
  4306. regexp: 'regexp'
  4307. },
  4308. enableByHtml5: function($field) {
  4309. var pattern = $field.attr('pattern');
  4310. if (pattern) {
  4311. return {
  4312. regexp: pattern
  4313. };
  4314. }
  4315. return false;
  4316. },
  4317. /**
  4318. * Check if the element value matches given regular expression
  4319. *
  4320. * @param {BootstrapValidator} validator The validator plugin instance
  4321. * @param {jQuery} $field Field element
  4322. * @param {Object} options Consists of the following key:
  4323. * - regexp: The regular expression you need to check
  4324. * @returns {Boolean}
  4325. */
  4326. validate: function(validator, $field, options) {
  4327. var value = $field.val();
  4328. if (value === '') {
  4329. return true;
  4330. }
  4331. var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  4332. return regexp.test(value);
  4333. }
  4334. };
  4335. }(window.jQuery));
  4336. ;(function($) {
  4337. $.fn.bootstrapValidator.i18n.remote = $.extend($.fn.bootstrapValidator.i18n.remote || {}, {
  4338. 'default': 'Please enter a valid value'
  4339. });
  4340. $.fn.bootstrapValidator.validators.remote = {
  4341. html5Attributes: {
  4342. message: 'message',
  4343. name: 'name',
  4344. type: 'type',
  4345. url: 'url'
  4346. },
  4347. /**
  4348. * Request a remote server to check the input value
  4349. *
  4350. * @param {BootstrapValidator} validator Plugin instance
  4351. * @param {jQuery} $field Field element
  4352. * @param {Object} options Can consist of the following keys:
  4353. * - url {String|Function}
  4354. * - type {String} [optional] Can be GET or POST (default)
  4355. * - data {Object|Function} [optional]: By default, it will take the value
  4356. * {
  4357. * <fieldName>: <fieldValue>
  4358. * }
  4359. * - name {String} [optional]: Override the field name for the request.
  4360. * - message: The invalid message
  4361. * - headers: Additional headers
  4362. * @returns {Boolean|Deferred}
  4363. */
  4364. validate: function(validator, $field, options) {
  4365. var value = $field.val();
  4366. if (value === '') {
  4367. return true;
  4368. }
  4369. var name = $field.attr('data-bv-field'),
  4370. data = options.data || {},
  4371. url = options.url,
  4372. type = options.type || 'POST',
  4373. headers = options.headers || {};
  4374. // Support dynamic data
  4375. if ('function' === typeof data) {
  4376. data = data.call(this, validator);
  4377. }
  4378. // Support dynamic url
  4379. if ('function' === typeof url) {
  4380. url = url.call(this, validator);
  4381. }
  4382. data[options.name || name] = value;
  4383. var dfd = new $.Deferred();
  4384. var xhr = $.ajax({
  4385. type: type,
  4386. headers: headers,
  4387. url: url,
  4388. dataType: 'json',
  4389. data: data
  4390. });
  4391. xhr.then(function(response) {
  4392. dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true', response.message ? response.message : null);
  4393. });
  4394. dfd.fail(function() {
  4395. xhr.abort();
  4396. });
  4397. return dfd;
  4398. }
  4399. };
  4400. }(window.jQuery));
  4401. ;(function($) {
  4402. $.fn.bootstrapValidator.i18n.rtn = $.extend($.fn.bootstrapValidator.i18n.rtn || {}, {
  4403. 'default': 'Please enter a valid RTN number'
  4404. });
  4405. $.fn.bootstrapValidator.validators.rtn = {
  4406. /**
  4407. * Validate a RTN (Routing transit number)
  4408. * Examples:
  4409. * - Valid: 021200025, 789456124
  4410. *
  4411. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  4412. * @param {BootstrapValidator} validator The validator plugin instance
  4413. * @param {jQuery} $field Field element
  4414. * @param {Object} options Can consist of the following keys:
  4415. * - message: The invalid message
  4416. * @returns {Boolean}
  4417. */
  4418. validate: function(validator, $field, options) {
  4419. var value = $field.val();
  4420. if (value === '') {
  4421. return true;
  4422. }
  4423. if (!/^\d{9}$/.test(value)) {
  4424. return false;
  4425. }
  4426. var sum = 0;
  4427. for (var i = 0; i < value.length; i += 3) {
  4428. sum += parseInt(value.charAt(i), 10) * 3
  4429. + parseInt(value.charAt(i + 1), 10) * 7
  4430. + parseInt(value.charAt(i + 2), 10);
  4431. }
  4432. return (sum !== 0 && sum % 10 === 0);
  4433. }
  4434. };
  4435. }(window.jQuery));
  4436. ;(function($) {
  4437. $.fn.bootstrapValidator.i18n.sedol = $.extend($.fn.bootstrapValidator.i18n.sedol || {}, {
  4438. 'default': 'Please enter a valid SEDOL number'
  4439. });
  4440. $.fn.bootstrapValidator.validators.sedol = {
  4441. /**
  4442. * Validate a SEDOL (Stock Exchange Daily Official List)
  4443. * Examples:
  4444. * - Valid: 0263494, B0WNLY7
  4445. *
  4446. * @see http://en.wikipedia.org/wiki/SEDOL
  4447. * @param {BootstrapValidator} validator The validator plugin instance
  4448. * @param {jQuery} $field Field element
  4449. * @param {Object} options Can consist of the following keys:
  4450. * - message: The invalid message
  4451. * @returns {Boolean}
  4452. */
  4453. validate: function(validator, $field, options) {
  4454. var value = $field.val();
  4455. if (value === '') {
  4456. return true;
  4457. }
  4458. value = value.toUpperCase();
  4459. if (!/^[0-9A-Z]{7}$/.test(value)) {
  4460. return false;
  4461. }
  4462. var sum = 0,
  4463. weight = [1, 3, 1, 7, 3, 9, 1],
  4464. length = value.length;
  4465. for (var i = 0; i < length - 1; i++) {
  4466. sum += weight[i] * parseInt(value.charAt(i), 36);
  4467. }
  4468. sum = (10 - sum % 10) % 10;
  4469. return sum + '' === value.charAt(length - 1);
  4470. }
  4471. };
  4472. }(window.jQuery));
  4473. ;(function($) {
  4474. $.fn.bootstrapValidator.i18n.siren = $.extend($.fn.bootstrapValidator.i18n.siren || {}, {
  4475. 'default': 'Please enter a valid SIREN number'
  4476. });
  4477. $.fn.bootstrapValidator.validators.siren = {
  4478. /**
  4479. * Check if a string is a siren number
  4480. *
  4481. * @param {BootstrapValidator} validator The validator plugin instance
  4482. * @param {jQuery} $field Field element
  4483. * @param {Object} options Consist of key:
  4484. * - message: The invalid message
  4485. * @returns {Boolean}
  4486. */
  4487. validate: function(validator, $field, options) {
  4488. var value = $field.val();
  4489. if (value === '') {
  4490. return true;
  4491. }
  4492. if (!/^\d{9}$/.test(value)) {
  4493. return false;
  4494. }
  4495. return $.fn.bootstrapValidator.helpers.luhn(value);
  4496. }
  4497. };
  4498. }(window.jQuery));
  4499. ;(function($) {
  4500. $.fn.bootstrapValidator.i18n.siret = $.extend($.fn.bootstrapValidator.i18n.siret || {}, {
  4501. 'default': 'Please enter a valid SIRET number'
  4502. });
  4503. $.fn.bootstrapValidator.validators.siret = {
  4504. /**
  4505. * Check if a string is a siret number
  4506. *
  4507. * @param {BootstrapValidator} validator The validator plugin instance
  4508. * @param {jQuery} $field Field element
  4509. * @param {Object} options Consist of key:
  4510. * - message: The invalid message
  4511. * @returns {Boolean}
  4512. */
  4513. validate: function(validator, $field, options) {
  4514. var value = $field.val();
  4515. if (value === '') {
  4516. return true;
  4517. }
  4518. var sum = 0,
  4519. length = value.length,
  4520. tmp;
  4521. for (var i = 0; i < length; i++) {
  4522. tmp = parseInt(value.charAt(i), 10);
  4523. if ((i % 2) === 0) {
  4524. tmp = tmp * 2;
  4525. if (tmp > 9) {
  4526. tmp -= 9;
  4527. }
  4528. }
  4529. sum += tmp;
  4530. }
  4531. return (sum % 10 === 0);
  4532. }
  4533. };
  4534. }(window.jQuery));
  4535. ;(function($) {
  4536. $.fn.bootstrapValidator.i18n.step = $.extend($.fn.bootstrapValidator.i18n.step || {}, {
  4537. 'default': 'Please enter a valid step of %s'
  4538. });
  4539. $.fn.bootstrapValidator.validators.step = {
  4540. html5Attributes: {
  4541. message: 'message',
  4542. base: 'baseValue',
  4543. step: 'step'
  4544. },
  4545. /**
  4546. * Return true if the input value is valid step one
  4547. *
  4548. * @param {BootstrapValidator} validator The validator plugin instance
  4549. * @param {jQuery} $field Field element
  4550. * @param {Object} options Can consist of the following keys:
  4551. * - baseValue: The base value
  4552. * - step: The step
  4553. * - message: The invalid message
  4554. * @returns {Boolean|Object}
  4555. */
  4556. validate: function(validator, $field, options) {
  4557. var value = $field.val();
  4558. if (value === '') {
  4559. return true;
  4560. }
  4561. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  4562. value = parseFloat(value);
  4563. if (!$.isNumeric(value)) {
  4564. return false;
  4565. }
  4566. var round = function(x, precision) {
  4567. var m = Math.pow(10, precision);
  4568. x = x * m;
  4569. var sign = (x > 0) | -(x < 0),
  4570. isHalf = (x % 1 === 0.5 * sign);
  4571. if (isHalf) {
  4572. return (Math.floor(x) + (sign > 0)) / m;
  4573. } else {
  4574. return Math.round(x) / m;
  4575. }
  4576. },
  4577. floatMod = function(x, y) {
  4578. if (y === 0.0) {
  4579. return 1.0;
  4580. }
  4581. var dotX = (x + '').split('.'),
  4582. dotY = (y + '').split('.'),
  4583. precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  4584. return round(x - y * Math.floor(x / y), precision);
  4585. };
  4586. var mod = floatMod(value - options.baseValue, options.step);
  4587. return {
  4588. valid: mod === 0.0 || mod === options.step,
  4589. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.step['default'], [options.step])
  4590. };
  4591. }
  4592. };
  4593. }(window.jQuery));
  4594. ;(function($) {
  4595. $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
  4596. 'default': 'Please enter only lowercase characters',
  4597. upper: 'Please enter only uppercase characters'
  4598. });
  4599. $.fn.bootstrapValidator.validators.stringCase = {
  4600. html5Attributes: {
  4601. message: 'message',
  4602. 'case': 'case'
  4603. },
  4604. /**
  4605. * Check if a string is a lower or upper case one
  4606. *
  4607. * @param {BootstrapValidator} validator The validator plugin instance
  4608. * @param {jQuery} $field Field element
  4609. * @param {Object} options Consist of key:
  4610. * - message: The invalid message
  4611. * - case: Can be 'lower' (default) or 'upper'
  4612. * @returns {Object}
  4613. */
  4614. validate: function(validator, $field, options) {
  4615. var value = $field.val();
  4616. if (value === '') {
  4617. return true;
  4618. }
  4619. var stringCase = (options['case'] || 'lower').toLowerCase();
  4620. return {
  4621. valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
  4622. message: options.message || (('upper' === stringCase) ? $.fn.bootstrapValidator.i18n.stringCase.upper : $.fn.bootstrapValidator.i18n.stringCase['default'])
  4623. };
  4624. }
  4625. };
  4626. }(window.jQuery));
  4627. ;(function($) {
  4628. $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
  4629. 'default': 'Please enter a value with valid length',
  4630. less: 'Please enter less than %s characters',
  4631. more: 'Please enter more than %s characters',
  4632. between: 'Please enter value between %s and %s characters long'
  4633. });
  4634. $.fn.bootstrapValidator.validators.stringLength = {
  4635. html5Attributes: {
  4636. message: 'message',
  4637. min: 'min',
  4638. max: 'max'
  4639. },
  4640. enableByHtml5: function($field) {
  4641. var maxLength = $field.attr('maxlength');
  4642. if (maxLength) {
  4643. return {
  4644. max: parseInt(maxLength, 10)
  4645. };
  4646. }
  4647. return false;
  4648. },
  4649. /**
  4650. * Check if the length of element value is less or more than given number
  4651. *
  4652. * @param {BootstrapValidator} validator The validator plugin instance
  4653. * @param {jQuery} $field Field element
  4654. * @param {Object} options Consists of following keys:
  4655. * - min
  4656. * - max
  4657. * At least one of two keys is required
  4658. * The min, max keys define the number which the field value compares to. min, max can be
  4659. * - A number
  4660. * - Name of field which its value defines the number
  4661. * - Name of callback function that returns the number
  4662. * - A callback function that returns the number
  4663. *
  4664. * - message: The invalid message
  4665. * @returns {Object}
  4666. */
  4667. validate: function(validator, $field, options) {
  4668. var value = $field.val();
  4669. if (value === '') {
  4670. return true;
  4671. }
  4672. var min = $.isNumeric(options.min) ? options.min : validator.getDynamicOption($field, options.min),
  4673. max = $.isNumeric(options.max) ? options.max : validator.getDynamicOption($field, options.max),
  4674. length = value.length,
  4675. isValid = true,
  4676. message = options.message || $.fn.bootstrapValidator.i18n.stringLength['default'];
  4677. if ((min && length < parseInt(min, 10)) || (max && length > parseInt(max, 10))) {
  4678. isValid = false;
  4679. }
  4680. switch (true) {
  4681. case (!!min && !!max):
  4682. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.between, [parseInt(min, 10), parseInt(max, 10)]);
  4683. break;
  4684. case (!!min):
  4685. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.more, parseInt(min, 10));
  4686. break;
  4687. case (!!max):
  4688. message = $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.stringLength.less, parseInt(max, 10));
  4689. break;
  4690. default:
  4691. break;
  4692. }
  4693. return { valid: isValid, message: message };
  4694. }
  4695. };
  4696. }(window.jQuery));
  4697. ;(function($) {
  4698. $.fn.bootstrapValidator.i18n.uri = $.extend($.fn.bootstrapValidator.i18n.uri || {}, {
  4699. 'default': 'Please enter a valid URI'
  4700. });
  4701. $.fn.bootstrapValidator.validators.uri = {
  4702. html5Attributes: {
  4703. message: 'message',
  4704. allowlocal: 'allowLocal'
  4705. },
  4706. enableByHtml5: function($field) {
  4707. return ('url' === $field.attr('type'));
  4708. },
  4709. /**
  4710. * Return true if the input value is a valid URL
  4711. *
  4712. * @param {BootstrapValidator} validator The validator plugin instance
  4713. * @param {jQuery} $field Field element
  4714. * @param {Object} options
  4715. * - message: The error message
  4716. * - allowLocal: Allow the private and local network IP. Default to false
  4717. * @returns {Boolean}
  4718. */
  4719. validate: function(validator, $field, options) {
  4720. var value = $field.val();
  4721. if (value === '') {
  4722. return true;
  4723. }
  4724. // Credit to https://gist.github.com/dperini/729294
  4725. //
  4726. // Regular Expression for URL validation
  4727. //
  4728. // Author: Diego Perini
  4729. // Updated: 2010/12/05
  4730. //
  4731. // the regular expression composed & commented
  4732. // could be easily tweaked for RFC compliance,
  4733. // it was expressly modified to fit & satisfy
  4734. // these test for an URL shortener:
  4735. //
  4736. // http://mathiasbynens.be/demo/url-regex
  4737. //
  4738. // Notes on possible differences from a standard/generic validation:
  4739. //
  4740. // - utf-8 char class take in consideration the full Unicode range
  4741. // - TLDs are mandatory unless `allowLocal` is true
  4742. // - protocols have been restricted to ftp, http and https only as requested
  4743. //
  4744. // Changes:
  4745. //
  4746. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  4747. // first and last IP address of each class is considered invalid
  4748. // (since they are broadcast/network addresses)
  4749. //
  4750. // - Added exclusion of private, reserved and/or local networks ranges
  4751. // unless `allowLocal` is true
  4752. //
  4753. var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
  4754. urlExp = new RegExp(
  4755. "^" +
  4756. // protocol identifier
  4757. "(?:(?:https?|ftp)://)" +
  4758. // user:pass authentication
  4759. "(?:\\S+(?::\\S*)?@)?" +
  4760. "(?:" +
  4761. // IP address exclusion
  4762. // private & local networks
  4763. (allowLocal
  4764. ? ''
  4765. : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  4766. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  4767. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  4768. // IP address dotted notation octets
  4769. // excludes loopback network 0.0.0.0
  4770. // excludes reserved space >= 224.0.0.0
  4771. // excludes network & broadcast addresses
  4772. // (first & last IP address of each class)
  4773. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  4774. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  4775. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  4776. "|" +
  4777. // host name
  4778. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  4779. // domain name
  4780. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  4781. // TLD identifier
  4782. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  4783. // Allow intranet sites (no TLD) if `allowLocal` is true
  4784. (allowLocal ? '?' : '') +
  4785. ")" +
  4786. // port number
  4787. "(?::\\d{2,5})?" +
  4788. // resource path
  4789. "(?:/[^\\s]*)?" +
  4790. "$", "i"
  4791. );
  4792. return urlExp.test(value);
  4793. }
  4794. };
  4795. }(window.jQuery));
  4796. ;(function($) {
  4797. $.fn.bootstrapValidator.i18n.uuid = $.extend($.fn.bootstrapValidator.i18n.uuid || {}, {
  4798. 'default': 'Please enter a valid UUID number',
  4799. version: 'Please enter a valid UUID version %s number'
  4800. });
  4801. $.fn.bootstrapValidator.validators.uuid = {
  4802. html5Attributes: {
  4803. message: 'message',
  4804. version: 'version'
  4805. },
  4806. /**
  4807. * Return true if and only if the input value is a valid UUID string
  4808. *
  4809. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  4810. * @param {BootstrapValidator} validator The validator plugin instance
  4811. * @param {jQuery} $field Field element
  4812. * @param {Object} options Consist of key:
  4813. * - message: The invalid message
  4814. * - version: Can be 3, 4, 5, null
  4815. * @returns {Boolean|Object}
  4816. */
  4817. validate: function(validator, $field, options) {
  4818. var value = $field.val();
  4819. if (value === '') {
  4820. return true;
  4821. }
  4822. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  4823. var patterns = {
  4824. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  4825. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  4826. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  4827. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  4828. },
  4829. version = options.version ? (options.version + '') : 'all';
  4830. return {
  4831. valid: (null === patterns[version]) ? true : patterns[version].test(value),
  4832. message: options.version
  4833. ? $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.uuid.version, options.version)
  4834. : (options.message || $.fn.bootstrapValidator.i18n.uuid['default'])
  4835. };
  4836. }
  4837. };
  4838. }(window.jQuery));
  4839. ;(function($) {
  4840. $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
  4841. 'default': 'Please enter a valid VAT number',
  4842. countryNotSupported: 'The country code %s is not supported',
  4843. country: 'Please enter a valid %s VAT number',
  4844. countries: {
  4845. AT: 'Austrian',
  4846. BE: 'Belgian',
  4847. BG: 'Bulgarian',
  4848. BR: 'Brazilian',
  4849. CH: 'Swiss',
  4850. CY: 'Cypriot',
  4851. CZ: 'Czech',
  4852. DE: 'German',
  4853. DK: 'Danish',
  4854. EE: 'Estonian',
  4855. ES: 'Spanish',
  4856. FI: 'Finnish',
  4857. FR: 'French',
  4858. GB: 'United Kingdom',
  4859. GR: 'Greek',
  4860. EL: 'Greek',
  4861. HU: 'Hungarian',
  4862. HR: 'Croatian',
  4863. IE: 'Irish',
  4864. IS: 'Iceland',
  4865. IT: 'Italian',
  4866. LT: 'Lithuanian',
  4867. LU: 'Luxembourg',
  4868. LV: 'Latvian',
  4869. MT: 'Maltese',
  4870. NL: 'Dutch',
  4871. NO: 'Norwegian',
  4872. PL: 'Polish',
  4873. PT: 'Portuguese',
  4874. RO: 'Romanian',
  4875. RU: 'Russian',
  4876. RS: 'Serbian',
  4877. SE: 'Swedish',
  4878. SI: 'Slovenian',
  4879. SK: 'Slovak',
  4880. ZA: 'South African'
  4881. }
  4882. });
  4883. $.fn.bootstrapValidator.validators.vat = {
  4884. html5Attributes: {
  4885. message: 'message',
  4886. country: 'country'
  4887. },
  4888. // Supported country codes
  4889. COUNTRY_CODES: [
  4890. 'AT', 'BE', 'BG', 'BR', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU',
  4891. 'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'RS', 'SE', 'SK', 'SI', 'ZA'
  4892. ],
  4893. /**
  4894. * Validate an European VAT number
  4895. *
  4896. * @param {BootstrapValidator} validator The validator plugin instance
  4897. * @param {jQuery} $field Field element
  4898. * @param {Object} options Consist of key:
  4899. * - message: The invalid message
  4900. * - country: The ISO 3166-1 country code. It can be
  4901. * - One of country code defined in COUNTRY_CODES
  4902. * - Name of field which its value defines the country code
  4903. * - Name of callback function that returns the country code
  4904. * - A callback function that returns the country code
  4905. * @returns {Boolean|Object}
  4906. */
  4907. validate: function(validator, $field, options) {
  4908. var value = $field.val();
  4909. if (value === '') {
  4910. return true;
  4911. }
  4912. var country = options.country;
  4913. if (!country) {
  4914. country = value.substr(0, 2);
  4915. } else if (typeof country !== 'string' || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  4916. // Determine the country code
  4917. country = validator.getDynamicOption($field, country);
  4918. }
  4919. if ($.inArray(country, this.COUNTRY_CODES) === -1) {
  4920. return {
  4921. valid: false,
  4922. message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.vat.countryNotSupported, country)
  4923. };
  4924. }
  4925. var method = ['_', country.toLowerCase()].join('');
  4926. return this[method](value)
  4927. ? true
  4928. : {
  4929. valid: false,
  4930. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.vat.country, $.fn.bootstrapValidator.i18n.vat.countries[country.toUpperCase()])
  4931. };
  4932. },
  4933. // VAT validators
  4934. /**
  4935. * Validate Austrian VAT number
  4936. * Example:
  4937. * - Valid: ATU13585627
  4938. * - Invalid: ATU13585626
  4939. *
  4940. * @param {String} value VAT number
  4941. * @returns {Boolean}
  4942. */
  4943. _at: function(value) {
  4944. if (!/^ATU[0-9]{8}$/.test(value)) {
  4945. return false;
  4946. }
  4947. value = value.substr(3);
  4948. var sum = 0,
  4949. weight = [1, 2, 1, 2, 1, 2, 1],
  4950. temp = 0;
  4951. for (var i = 0; i < 7; i++) {
  4952. temp = parseInt(value.charAt(i), 10) * weight[i];
  4953. if (temp > 9) {
  4954. temp = Math.floor(temp / 10) + temp % 10;
  4955. }
  4956. sum += temp;
  4957. }
  4958. sum = 10 - (sum + 4) % 10;
  4959. if (sum === 10) {
  4960. sum = 0;
  4961. }
  4962. return (sum + '' === value.substr(7, 1));
  4963. },
  4964. /**
  4965. * Validate Belgian VAT number
  4966. * Example:
  4967. * - Valid: BE0428759497
  4968. * - Invalid: BE431150351
  4969. *
  4970. * @param {String} value VAT number
  4971. * @returns {Boolean}
  4972. */
  4973. _be: function(value) {
  4974. if (!/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  4975. return false;
  4976. }
  4977. value = value.substr(2);
  4978. if (value.length === 9) {
  4979. value = '0' + value;
  4980. }
  4981. if (value.substr(1, 1) === '0') {
  4982. return false;
  4983. }
  4984. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  4985. return (sum % 97 === 0);
  4986. },
  4987. /**
  4988. * Validate Bulgarian VAT number
  4989. * Example:
  4990. * - Valid: BG175074752,
  4991. * BG7523169263, BG8032056031,
  4992. * BG7542011030,
  4993. * BG7111042925
  4994. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  4995. *
  4996. * @param {String} value VAT number
  4997. * @returns {Boolean}
  4998. */
  4999. _bg: function(value) {
  5000. if (!/^BG[0-9]{9,10}$/.test(value)) {
  5001. return false;
  5002. }
  5003. value = value.substr(2);
  5004. var sum = 0, i = 0;
  5005. // Legal entities
  5006. if (value.length === 9) {
  5007. for (i = 0; i < 8; i++) {
  5008. sum += parseInt(value.charAt(i), 10) * (i + 1);
  5009. }
  5010. sum = sum % 11;
  5011. if (sum === 10) {
  5012. sum = 0;
  5013. for (i = 0; i < 8; i++) {
  5014. sum += parseInt(value.charAt(i), 10) * (i + 3);
  5015. }
  5016. }
  5017. sum = sum % 10;
  5018. return (sum + '' === value.substr(8));
  5019. }
  5020. // Physical persons, foreigners and others
  5021. else if (value.length === 10) {
  5022. // Validate Bulgarian national identification numbers
  5023. var egn = function(value) {
  5024. // Check the birth date
  5025. var year = parseInt(value.substr(0, 2), 10) + 1900,
  5026. month = parseInt(value.substr(2, 2), 10),
  5027. day = parseInt(value.substr(4, 2), 10);
  5028. if (month > 40) {
  5029. year += 100;
  5030. month -= 40;
  5031. } else if (month > 20) {
  5032. year -= 100;
  5033. month -= 20;
  5034. }
  5035. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  5036. return false;
  5037. }
  5038. var sum = 0,
  5039. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  5040. for (var i = 0; i < 9; i++) {
  5041. sum += parseInt(value.charAt(i), 10) * weight[i];
  5042. }
  5043. sum = (sum % 11) % 10;
  5044. return (sum + '' === value.substr(9, 1));
  5045. },
  5046. // Validate Bulgarian personal number of a foreigner
  5047. pnf = function(value) {
  5048. var sum = 0,
  5049. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  5050. for (var i = 0; i < 9; i++) {
  5051. sum += parseInt(value.charAt(i), 10) * weight[i];
  5052. }
  5053. sum = sum % 10;
  5054. return (sum + '' === value.substr(9, 1));
  5055. },
  5056. // Finally, consider it as a VAT number
  5057. vat = function(value) {
  5058. var sum = 0,
  5059. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  5060. for (var i = 0; i < 9; i++) {
  5061. sum += parseInt(value.charAt(i), 10) * weight[i];
  5062. }
  5063. sum = 11 - sum % 11;
  5064. if (sum === 10) {
  5065. return false;
  5066. }
  5067. if (sum === 11) {
  5068. sum = 0;
  5069. }
  5070. return (sum + '' === value.substr(9, 1));
  5071. };
  5072. return (egn(value) || pnf(value) || vat(value));
  5073. }
  5074. return false;
  5075. },
  5076. /**
  5077. * Validate Brazilian VAT number (CNPJ)
  5078. *
  5079. * @param {String} value VAT number
  5080. * @returns {Boolean}
  5081. */
  5082. _br: function(value) {
  5083. if (value === '') {
  5084. return true;
  5085. }
  5086. var cnpj = value.replace(/[^\d]+/g, '');
  5087. if (cnpj === '' || cnpj.length !== 14) {
  5088. return false;
  5089. }
  5090. // Remove invalids CNPJs
  5091. if (cnpj === '00000000000000' || cnpj === '11111111111111' || cnpj === '22222222222222' ||
  5092. cnpj === '33333333333333' || cnpj === '44444444444444' || cnpj === '55555555555555' ||
  5093. cnpj === '66666666666666' || cnpj === '77777777777777' || cnpj === '88888888888888' ||
  5094. cnpj === '99999999999999')
  5095. {
  5096. return false;
  5097. }
  5098. // Validate verification digits
  5099. var length = cnpj.length - 2,
  5100. numbers = cnpj.substring(0, length),
  5101. digits = cnpj.substring(length),
  5102. sum = 0,
  5103. pos = length - 7;
  5104. for (var i = length; i >= 1; i--) {
  5105. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  5106. if (pos < 2) {
  5107. pos = 9;
  5108. }
  5109. }
  5110. var result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  5111. if (result !== parseInt(digits.charAt(0), 10)) {
  5112. return false;
  5113. }
  5114. length = length + 1;
  5115. numbers = cnpj.substring(0, length);
  5116. sum = 0;
  5117. pos = length - 7;
  5118. for (i = length; i >= 1; i--) {
  5119. sum += parseInt(numbers.charAt(length - i), 10) * pos--;
  5120. if (pos < 2) {
  5121. pos = 9;
  5122. }
  5123. }
  5124. result = sum % 11 < 2 ? 0 : 11 - sum % 11;
  5125. return (result === parseInt(digits.charAt(1), 10));
  5126. },
  5127. /**
  5128. * Validate Swiss VAT number
  5129. *
  5130. * @param {String} value VAT number
  5131. * @returns {Boolean}
  5132. */
  5133. _ch: function(value) {
  5134. if (!/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  5135. return false;
  5136. }
  5137. value = value.substr(3);
  5138. var sum = 0,
  5139. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  5140. for (var i = 0; i < 8; i++) {
  5141. sum += parseInt(value.charAt(i), 10) * weight[i];
  5142. }
  5143. sum = 11 - sum % 11;
  5144. if (sum === 10) {
  5145. return false;
  5146. }
  5147. if (sum === 11) {
  5148. sum = 0;
  5149. }
  5150. return (sum + '' === value.substr(8, 1));
  5151. },
  5152. /**
  5153. * Validate Cypriot VAT number
  5154. * Examples:
  5155. * - Valid: CY10259033P
  5156. * - Invalid: CY10259033Z
  5157. *
  5158. * @param {String} value VAT number
  5159. * @returns {Boolean}
  5160. */
  5161. _cy: function(value) {
  5162. if (!/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  5163. return false;
  5164. }
  5165. value = value.substr(2);
  5166. // Do not allow to start with "12"
  5167. if (value.substr(0, 2) === '12') {
  5168. return false;
  5169. }
  5170. // Extract the next digit and multiply by the counter.
  5171. var sum = 0,
  5172. translation = {
  5173. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  5174. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  5175. };
  5176. for (var i = 0; i < 8; i++) {
  5177. var temp = parseInt(value.charAt(i), 10);
  5178. if (i % 2 === 0) {
  5179. temp = translation[temp + ''];
  5180. }
  5181. sum += temp;
  5182. }
  5183. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  5184. return (sum + '' === value.substr(8, 1));
  5185. },
  5186. /**
  5187. * Validate Czech Republic VAT number
  5188. * Can be:
  5189. * i) Legal entities (8 digit numbers)
  5190. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  5191. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  5192. *
  5193. * Examples:
  5194. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  5195. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  5196. *
  5197. * @param {String} value VAT number
  5198. * @returns {Boolean}
  5199. */
  5200. _cz: function(value) {
  5201. if (!/^CZ[0-9]{8,10}$/.test(value)) {
  5202. return false;
  5203. }
  5204. value = value.substr(2);
  5205. var sum = 0,
  5206. i = 0;
  5207. if (value.length === 8) {
  5208. // Do not allow to start with '9'
  5209. if (value.charAt(0) + '' === '9') {
  5210. return false;
  5211. }
  5212. sum = 0;
  5213. for (i = 0; i < 7; i++) {
  5214. sum += parseInt(value.charAt(i), 10) * (8 - i);
  5215. }
  5216. sum = 11 - sum % 11;
  5217. if (sum === 10) {
  5218. sum = 0;
  5219. }
  5220. if (sum === 11) {
  5221. sum = 1;
  5222. }
  5223. return (sum + '' === value.substr(7, 1));
  5224. } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  5225. sum = 0;
  5226. // Skip the first (which is 6)
  5227. for (i = 0; i < 7; i++) {
  5228. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  5229. }
  5230. sum = 11 - sum % 11;
  5231. if (sum === 10) {
  5232. sum = 0;
  5233. }
  5234. if (sum === 11) {
  5235. sum = 1;
  5236. }
  5237. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  5238. return (sum + '' === value.substr(8, 1));
  5239. } else if (value.length === 9 || value.length === 10) {
  5240. // Validate Czech birth number (Rodné číslo), which is also national identifier
  5241. var year = 1900 + parseInt(value.substr(0, 2), 10),
  5242. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  5243. day = parseInt(value.substr(4, 2), 10);
  5244. if (value.length === 9) {
  5245. if (year >= 1980) {
  5246. year -= 100;
  5247. }
  5248. if (year > 1953) {
  5249. return false;
  5250. }
  5251. } else if (year < 1954) {
  5252. year += 100;
  5253. }
  5254. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  5255. return false;
  5256. }
  5257. // Check that the birth date is not in the future
  5258. if (value.length === 10) {
  5259. var check = parseInt(value.substr(0, 9), 10) % 11;
  5260. if (year < 1985) {
  5261. check = check % 10;
  5262. }
  5263. return (check + '' === value.substr(9, 1));
  5264. }
  5265. return true;
  5266. }
  5267. return false;
  5268. },
  5269. /**
  5270. * Validate German VAT number
  5271. * Examples:
  5272. * - Valid: DE136695976
  5273. * - Invalid: DE136695978
  5274. *
  5275. * @param {String} value VAT number
  5276. * @returns {Boolean}
  5277. */
  5278. _de: function(value) {
  5279. if (!/^DE[0-9]{9}$/.test(value)) {
  5280. return false;
  5281. }
  5282. value = value.substr(2);
  5283. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  5284. },
  5285. /**
  5286. * Validate Danish VAT number
  5287. * Example:
  5288. * - Valid: DK13585628
  5289. * - Invalid: DK13585627
  5290. *
  5291. * @param {String} value VAT number
  5292. * @returns {Boolean}
  5293. */
  5294. _dk: function(value) {
  5295. if (!/^DK[0-9]{8}$/.test(value)) {
  5296. return false;
  5297. }
  5298. value = value.substr(2);
  5299. var sum = 0,
  5300. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  5301. for (var i = 0; i < 8; i++) {
  5302. sum += parseInt(value.charAt(i), 10) * weight[i];
  5303. }
  5304. return (sum % 11 === 0);
  5305. },
  5306. /**
  5307. * Validate Estonian VAT number
  5308. * Examples:
  5309. * - Valid: EE100931558, EE100594102
  5310. * - Invalid: EE100594103
  5311. *
  5312. * @param {String} value VAT number
  5313. * @returns {Boolean}
  5314. */
  5315. _ee: function(value) {
  5316. if (!/^EE[0-9]{9}$/.test(value)) {
  5317. return false;
  5318. }
  5319. value = value.substr(2);
  5320. var sum = 0,
  5321. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  5322. for (var i = 0; i < 9; i++) {
  5323. sum += parseInt(value.charAt(i), 10) * weight[i];
  5324. }
  5325. return (sum % 10 === 0);
  5326. },
  5327. /**
  5328. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  5329. * Can be:
  5330. * i) DNI (Documento nacional de identidad), for Spaniards
  5331. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  5332. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  5333. *
  5334. * Examples:
  5335. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  5336. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  5337. *
  5338. * @param {String} value VAT number
  5339. * @returns {Boolean}
  5340. */
  5341. _es: function(value) {
  5342. if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  5343. return false;
  5344. }
  5345. value = value.substr(2);
  5346. var dni = function(value) {
  5347. var check = parseInt(value.substr(0, 8), 10);
  5348. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5349. return (check + '' === value.substr(8, 1));
  5350. },
  5351. nie = function(value) {
  5352. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  5353. check = parseInt(check, 10);
  5354. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5355. return (check + '' === value.substr(8, 1));
  5356. },
  5357. cif = function(value) {
  5358. var first = value.charAt(0), check;
  5359. if ('KLM'.indexOf(first) !== -1) {
  5360. // K: Spanish younger than 14 year old
  5361. // L: Spanish living outside Spain without DNI
  5362. // M: Granted the tax to foreigners who have no NIE
  5363. check = parseInt(value.substr(1, 8), 10);
  5364. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  5365. return (check + '' === value.substr(8, 1));
  5366. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  5367. var sum = 0,
  5368. weight = [2, 1, 2, 1, 2, 1, 2],
  5369. temp = 0;
  5370. for (var i = 0; i < 7; i++) {
  5371. temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  5372. if (temp > 9) {
  5373. temp = Math.floor(temp / 10) + temp % 10;
  5374. }
  5375. sum += temp;
  5376. }
  5377. sum = 10 - sum % 10;
  5378. return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  5379. }
  5380. return false;
  5381. };
  5382. var first = value.charAt(0);
  5383. if (/^[0-9]$/.test(first)) {
  5384. return dni(value);
  5385. } else if (/^[XYZ]$/.test(first)) {
  5386. return nie(value);
  5387. } else {
  5388. return cif(value);
  5389. }
  5390. },
  5391. /**
  5392. * Validate Finnish VAT number
  5393. * Examples:
  5394. * - Valid: FI20774740
  5395. * - Invalid: FI20774741
  5396. *
  5397. * @param {String} value VAT number
  5398. * @returns {Boolean}
  5399. */
  5400. _fi: function(value) {
  5401. if (!/^FI[0-9]{8}$/.test(value)) {
  5402. return false;
  5403. }
  5404. value = value.substr(2);
  5405. var sum = 0,
  5406. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  5407. for (var i = 0; i < 8; i++) {
  5408. sum += parseInt(value.charAt(i), 10) * weight[i];
  5409. }
  5410. return (sum % 11 === 0);
  5411. },
  5412. /**
  5413. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  5414. * It's constructed by a SIREN number, prefixed by two characters.
  5415. *
  5416. * Examples:
  5417. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  5418. * - Invalid: FR84323140391
  5419. *
  5420. * @param {String} value VAT number
  5421. * @returns {Boolean}
  5422. */
  5423. _fr: function(value) {
  5424. if (!/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  5425. return false;
  5426. }
  5427. value = value.substr(2);
  5428. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  5429. return false;
  5430. }
  5431. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  5432. // First two characters are digits
  5433. return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  5434. } else {
  5435. // The first characters cann't be O and I
  5436. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  5437. check;
  5438. // First one is digit
  5439. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  5440. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  5441. } else {
  5442. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  5443. }
  5444. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  5445. }
  5446. },
  5447. /**
  5448. * Validate United Kingdom VAT number
  5449. * Example:
  5450. * - Valid: GB980780684
  5451. * - Invalid: GB802311781
  5452. *
  5453. * @param {String} value VAT number
  5454. * @returns {Boolean}
  5455. */
  5456. _gb: function(value) {
  5457. if (!/^GB[0-9]{9}$/.test(value) /* Standard */
  5458. && !/^GB[0-9]{12}$/.test(value) /* Branches */
  5459. && !/^GBGD[0-9]{3}$/.test(value) /* Government department */
  5460. && !/^GBHA[0-9]{3}$/.test(value) /* Health authority */
  5461. && !/^GB(GD|HA)8888[0-9]{5}$/.test(value))
  5462. {
  5463. return false;
  5464. }
  5465. value = value.substr(2);
  5466. var length = value.length;
  5467. if (length === 5) {
  5468. var firstTwo = value.substr(0, 2),
  5469. lastThree = parseInt(value.substr(2), 10);
  5470. return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  5471. } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  5472. if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  5473. || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  5474. {
  5475. return false;
  5476. }
  5477. return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  5478. } else if (length === 9 || length === 12) {
  5479. var sum = 0,
  5480. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  5481. for (var i = 0; i < 9; i++) {
  5482. sum += parseInt(value.charAt(i), 10) * weight[i];
  5483. }
  5484. sum = sum % 97;
  5485. if (parseInt(value.substr(0, 3), 10) >= 100) {
  5486. return (sum === 0 || sum === 42 || sum === 55);
  5487. } else {
  5488. return (sum === 0);
  5489. }
  5490. }
  5491. return true;
  5492. },
  5493. /**
  5494. * Validate Greek VAT number
  5495. * Examples:
  5496. * - Valid: GR023456780, EL094259216
  5497. * - Invalid: EL123456781
  5498. *
  5499. * @param {String} value VAT number
  5500. * @returns {Boolean}
  5501. */
  5502. _gr: function(value) {
  5503. if (!/^GR[0-9]{9}$/.test(value)) {
  5504. return false;
  5505. }
  5506. value = value.substr(2);
  5507. if (value.length === 8) {
  5508. value = '0' + value;
  5509. }
  5510. var sum = 0,
  5511. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  5512. for (var i = 0; i < 8; i++) {
  5513. sum += parseInt(value.charAt(i), 10) * weight[i];
  5514. }
  5515. sum = (sum % 11) % 10;
  5516. return (sum + '' === value.substr(8, 1));
  5517. },
  5518. // EL is traditionally prefix of Greek VAT numbers
  5519. _el: function(value) {
  5520. if (!/^EL[0-9]{9}$/.test(value)) {
  5521. return false;
  5522. }
  5523. value = 'GR' + value.substr(2);
  5524. return this._gr(value);
  5525. },
  5526. /**
  5527. * Validate Hungarian VAT number
  5528. * Examples:
  5529. * - Valid: HU12892312
  5530. * - Invalid: HU12892313
  5531. *
  5532. * @param {String} value VAT number
  5533. * @returns {Boolean}
  5534. */
  5535. _hu: function(value) {
  5536. if (!/^HU[0-9]{8}$/.test(value)) {
  5537. return false;
  5538. }
  5539. value = value.substr(2);
  5540. var sum = 0,
  5541. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  5542. for (var i = 0; i < 8; i++) {
  5543. sum += parseInt(value.charAt(i), 10) * weight[i];
  5544. }
  5545. return (sum % 10 === 0);
  5546. },
  5547. /**
  5548. * Validate Croatian VAT number
  5549. * Examples:
  5550. * - Valid: HR33392005961
  5551. * - Invalid: HR33392005962
  5552. *
  5553. * @param {String} value VAT number
  5554. * @returns {Boolean}
  5555. */
  5556. _hr: function(value) {
  5557. if (!/^HR[0-9]{11}$/.test(value)) {
  5558. return false;
  5559. }
  5560. value = value.substr(2);
  5561. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  5562. },
  5563. /**
  5564. * Validate Irish VAT number
  5565. * Examples:
  5566. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  5567. * - Invalid: IE8D79738J
  5568. *
  5569. * @param {String} value VAT number
  5570. * @returns {Boolean}
  5571. */
  5572. _ie: function(value) {
  5573. if (!/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  5574. return false;
  5575. }
  5576. value = value.substr(2);
  5577. var getCheckDigit = function(value) {
  5578. while (value.length < 7) {
  5579. value = '0' + value;
  5580. }
  5581. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  5582. sum = 0;
  5583. for (var i = 0; i < 7; i++) {
  5584. sum += parseInt(value.charAt(i), 10) * (8 - i);
  5585. }
  5586. sum += 9 * alphabet.indexOf(value.substr(7));
  5587. return alphabet[sum % 23];
  5588. };
  5589. // The first 7 characters are digits
  5590. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  5591. // New system
  5592. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  5593. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  5594. // Old system
  5595. return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  5596. }
  5597. return true;
  5598. },
  5599. /**
  5600. * Validate Icelandic VAT (VSK) number
  5601. * Examples:
  5602. * - Valid: 12345, 123456
  5603. * - Invalid: 1234567
  5604. *
  5605. * @params {String} value VAT number
  5606. * @returns {Boolean}
  5607. */
  5608. _is: function(value) {
  5609. return /^IS\d{5,6}$/.test(value);
  5610. },
  5611. /**
  5612. * Validate Italian VAT number, which consists of 11 digits.
  5613. * - First 7 digits are a company identifier
  5614. * - Next 3 are the province of residence
  5615. * - The last one is a check digit
  5616. *
  5617. * Examples:
  5618. * - Valid: IT00743110157
  5619. * - Invalid: IT00743110158
  5620. *
  5621. * @param {String} value VAT number
  5622. * @returns {Boolean}
  5623. */
  5624. _it: function(value) {
  5625. if (!/^IT[0-9]{11}$/.test(value)) {
  5626. return false;
  5627. }
  5628. value = value.substr(2);
  5629. if (parseInt(value.substr(0, 7), 10) === 0) {
  5630. return false;
  5631. }
  5632. var lastThree = parseInt(value.substr(7, 3), 10);
  5633. if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  5634. return false;
  5635. }
  5636. return $.fn.bootstrapValidator.helpers.luhn(value);
  5637. },
  5638. /**
  5639. * Validate Lithuanian VAT number
  5640. * It can be:
  5641. * - 9 digits, for legal entities
  5642. * - 12 digits, for temporarily registered taxpayers
  5643. *
  5644. * Examples:
  5645. * - Valid: LT119511515, LT100001919017, LT100004801610
  5646. * - Invalid: LT100001919018
  5647. *
  5648. * @param {String} value VAT number
  5649. * @returns {Boolean}
  5650. */
  5651. _lt: function(value) {
  5652. if (!/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  5653. return false;
  5654. }
  5655. value = value.substr(2);
  5656. var length = value.length,
  5657. sum = 0,
  5658. i;
  5659. for (i = 0; i < length - 1; i++) {
  5660. sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  5661. }
  5662. var check = sum % 11;
  5663. if (check === 10) {
  5664. sum = 0;
  5665. for (i = 0; i < length - 1; i++) {
  5666. sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  5667. }
  5668. }
  5669. check = check % 11 % 10;
  5670. return (check + '' === value.charAt(length - 1));
  5671. },
  5672. /**
  5673. * Validate Luxembourg VAT number
  5674. * Examples:
  5675. * - Valid: LU15027442
  5676. * - Invalid: LU15027443
  5677. *
  5678. * @param {String} value VAT number
  5679. * @returns {Boolean}
  5680. */
  5681. _lu: function(value) {
  5682. if (!/^LU[0-9]{8}$/.test(value)) {
  5683. return false;
  5684. }
  5685. value = value.substr(2);
  5686. return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  5687. },
  5688. /**
  5689. * Validate Latvian VAT number
  5690. * Examples:
  5691. * - Valid: LV40003521600, LV16117519997
  5692. * - Invalid: LV40003521601, LV16137519997
  5693. *
  5694. * @param {String} value VAT number
  5695. * @returns {Boolean}
  5696. */
  5697. _lv: function(value) {
  5698. if (!/^LV[0-9]{11}$/.test(value)) {
  5699. return false;
  5700. }
  5701. value = value.substr(2);
  5702. var first = parseInt(value.charAt(0), 10),
  5703. sum = 0,
  5704. weight = [],
  5705. i,
  5706. length = value.length;
  5707. if (first > 3) {
  5708. // Legal entity
  5709. sum = 0;
  5710. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  5711. for (i = 0; i < length; i++) {
  5712. sum += parseInt(value.charAt(i), 10) * weight[i];
  5713. }
  5714. sum = sum % 11;
  5715. return (sum === 3);
  5716. } else {
  5717. // Check birth date
  5718. var day = parseInt(value.substr(0, 2), 10),
  5719. month = parseInt(value.substr(2, 2), 10),
  5720. year = parseInt(value.substr(4, 2), 10);
  5721. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  5722. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  5723. return false;
  5724. }
  5725. // Check personal code
  5726. sum = 0;
  5727. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  5728. for (i = 0; i < length - 1; i++) {
  5729. sum += parseInt(value.charAt(i), 10) * weight[i];
  5730. }
  5731. sum = (sum + 1) % 11 % 10;
  5732. return (sum + '' === value.charAt(length - 1));
  5733. }
  5734. },
  5735. /**
  5736. * Validate Maltese VAT number
  5737. * Examples:
  5738. * - Valid: MT11679112
  5739. * - Invalid: MT11679113
  5740. *
  5741. * @param {String} value VAT number
  5742. * @returns {Boolean}
  5743. */
  5744. _mt: function(value) {
  5745. if (!/^MT[0-9]{8}$/.test(value)) {
  5746. return false;
  5747. }
  5748. value = value.substr(2);
  5749. var sum = 0,
  5750. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  5751. for (var i = 0; i < 8; i++) {
  5752. sum += parseInt(value.charAt(i), 10) * weight[i];
  5753. }
  5754. return (sum % 37 === 0);
  5755. },
  5756. /**
  5757. * Validate Dutch VAT number
  5758. * Examples:
  5759. * - Valid: NL004495445B01
  5760. * - Invalid: NL123456789B90
  5761. *
  5762. * @param {String} value VAT number
  5763. * @returns {Boolean}
  5764. */
  5765. _nl: function(value) {
  5766. if (!/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  5767. return false;
  5768. }
  5769. value = value.substr(2);
  5770. var sum = 0,
  5771. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  5772. for (var i = 0; i < 8; i++) {
  5773. sum += parseInt(value.charAt(i), 10) * weight[i];
  5774. }
  5775. sum = sum % 11;
  5776. if (sum > 9) {
  5777. sum = 0;
  5778. }
  5779. return (sum + '' === value.substr(8, 1));
  5780. },
  5781. /**
  5782. * Validate Norwegian VAT number
  5783. *
  5784. * @see http://www.brreg.no/english/coordination/number.html
  5785. * @param {String} value VAT number
  5786. * @returns {Boolean}
  5787. */
  5788. _no: function(value) {
  5789. if (!/^NO[0-9]{9}$/.test(value)) {
  5790. return false;
  5791. }
  5792. value = value.substr(2);
  5793. var sum = 0,
  5794. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  5795. for (var i = 0; i < 8; i++) {
  5796. sum += parseInt(value.charAt(i), 10) * weight[i];
  5797. }
  5798. sum = 11 - sum % 11;
  5799. if (sum === 11) {
  5800. sum = 0;
  5801. }
  5802. return (sum + '' === value.substr(8, 1));
  5803. },
  5804. /**
  5805. * Validate Polish VAT number
  5806. * Examples:
  5807. * - Valid: PL8567346215
  5808. * - Invalid: PL8567346216
  5809. *
  5810. * @param {String} value VAT number
  5811. * @returns {Boolean}
  5812. */
  5813. _pl: function(value) {
  5814. if (!/^PL[0-9]{10}$/.test(value)) {
  5815. return false;
  5816. }
  5817. value = value.substr(2);
  5818. var sum = 0,
  5819. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  5820. for (var i = 0; i < 10; i++) {
  5821. sum += parseInt(value.charAt(i), 10) * weight[i];
  5822. }
  5823. return (sum % 11 === 0);
  5824. },
  5825. /**
  5826. * Validate Portuguese VAT number
  5827. * Examples:
  5828. * - Valid: PT501964843
  5829. * - Invalid: PT501964842
  5830. *
  5831. * @param {String} value VAT number
  5832. * @returns {Boolean}
  5833. */
  5834. _pt: function(value) {
  5835. if (!/^PT[0-9]{9}$/.test(value)) {
  5836. return false;
  5837. }
  5838. value = value.substr(2);
  5839. var sum = 0,
  5840. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  5841. for (var i = 0; i < 8; i++) {
  5842. sum += parseInt(value.charAt(i), 10) * weight[i];
  5843. }
  5844. sum = 11 - sum % 11;
  5845. if (sum > 9) {
  5846. sum = 0;
  5847. }
  5848. return (sum + '' === value.substr(8, 1));
  5849. },
  5850. /**
  5851. * Validate Romanian VAT number
  5852. * Examples:
  5853. * - Valid: RO18547290
  5854. * - Invalid: RO18547291
  5855. *
  5856. * @param {String} value VAT number
  5857. * @returns {Boolean}
  5858. */
  5859. _ro: function(value) {
  5860. if (!/^RO[1-9][0-9]{1,9}$/.test(value)) {
  5861. return false;
  5862. }
  5863. value = value.substr(2);
  5864. var length = value.length,
  5865. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  5866. sum = 0;
  5867. for (var i = 0; i < length - 1; i++) {
  5868. sum += parseInt(value.charAt(i), 10) * weight[i];
  5869. }
  5870. sum = (10 * sum) % 11 % 10;
  5871. return (sum + '' === value.substr(length - 1, 1));
  5872. },
  5873. /**
  5874. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  5875. *
  5876. * @param {String} value VAT number
  5877. * @returns {Boolean}
  5878. */
  5879. _ru: function(value) {
  5880. if (!/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
  5881. return false;
  5882. }
  5883. value = value.substr(2);
  5884. var i = 0;
  5885. if (value.length === 10) {
  5886. var sum = 0,
  5887. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  5888. for (i = 0; i < 10; i++) {
  5889. sum += parseInt(value.charAt(i), 10) * weight[i];
  5890. }
  5891. sum = sum % 11;
  5892. if (sum > 9) {
  5893. sum = sum % 10;
  5894. }
  5895. return (sum + '' === value.substr(9, 1));
  5896. } else if (value.length === 12) {
  5897. var sum1 = 0,
  5898. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  5899. sum2 = 0,
  5900. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  5901. for (i = 0; i < 11; i++) {
  5902. sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  5903. sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  5904. }
  5905. sum1 = sum1 % 11;
  5906. if (sum1 > 9) {
  5907. sum1 = sum1 % 10;
  5908. }
  5909. sum2 = sum2 % 11;
  5910. if (sum2 > 9) {
  5911. sum2 = sum2 % 10;
  5912. }
  5913. return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  5914. }
  5915. return false;
  5916. },
  5917. /**
  5918. * Validate Serbian VAT number
  5919. *
  5920. * @param {String} value VAT number
  5921. * @returns {Boolean}
  5922. */
  5923. _rs: function(value) {
  5924. if (!/^RS[0-9]{9}$/.test(value)) {
  5925. return false;
  5926. }
  5927. value = value.substr(2);
  5928. var sum = 10,
  5929. temp = 0;
  5930. for (var i = 0; i < 8; i++) {
  5931. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  5932. if (temp === 0) {
  5933. temp = 10;
  5934. }
  5935. sum = (2 * temp) % 11;
  5936. }
  5937. return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  5938. },
  5939. /**
  5940. * Validate Swedish VAT number
  5941. * Examples:
  5942. * - Valid: SE123456789701
  5943. * - Invalid: SE123456789101
  5944. *
  5945. * @param {String} value VAT number
  5946. * @returns {Boolean}
  5947. */
  5948. _se: function(value) {
  5949. if (!/^SE[0-9]{10}01$/.test(value)) {
  5950. return false;
  5951. }
  5952. value = value.substr(2, 10);
  5953. return $.fn.bootstrapValidator.helpers.luhn(value);
  5954. },
  5955. /**
  5956. * Validate Slovenian VAT number
  5957. * Examples:
  5958. * - Valid: SI50223054
  5959. * - Invalid: SI50223055
  5960. *
  5961. * @param {String} value VAT number
  5962. * @returns {Boolean}
  5963. */
  5964. _si: function(value) {
  5965. if (!/^SI[0-9]{8}$/.test(value)) {
  5966. return false;
  5967. }
  5968. value = value.substr(2);
  5969. var sum = 0,
  5970. weight = [8, 7, 6, 5, 4, 3, 2];
  5971. for (var i = 0; i < 7; i++) {
  5972. sum += parseInt(value.charAt(i), 10) * weight[i];
  5973. }
  5974. sum = 11 - sum % 11;
  5975. if (sum === 10) {
  5976. sum = 0;
  5977. }
  5978. return (sum + '' === value.substr(7, 1));
  5979. },
  5980. /**
  5981. * Validate Slovak VAT number
  5982. * Examples:
  5983. * - Valid: SK2022749619
  5984. * - Invalid: SK2022749618
  5985. *
  5986. * @param {String} value VAT number
  5987. * @returns {Boolean}
  5988. */
  5989. _sk: function(value) {
  5990. if (!/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  5991. return false;
  5992. }
  5993. return (parseInt(value.substr(2), 10) % 11 === 0);
  5994. },
  5995. /**
  5996. * Validate South African VAT number
  5997. * Examples:
  5998. * - Valid: 4012345678
  5999. * - Invalid: 40123456789, 3012345678
  6000. *
  6001. * @params {String} value VAT number
  6002. * @returns {Boolean}
  6003. */
  6004. _za: function(value) {
  6005. return /^ZA4\d{9}$/.test(value);
  6006. }
  6007. };
  6008. }(window.jQuery));
  6009. ;(function($) {
  6010. $.fn.bootstrapValidator.i18n.vin = $.extend($.fn.bootstrapValidator.i18n.vin || {}, {
  6011. 'default': 'Please enter a valid VIN number'
  6012. });
  6013. $.fn.bootstrapValidator.validators.vin = {
  6014. /**
  6015. * Validate an US VIN (Vehicle Identification Number)
  6016. *
  6017. * @param {BootstrapValidator} validator The validator plugin instance
  6018. * @param {jQuery} $field Field element
  6019. * @param {Object} options Consist of key:
  6020. * - message: The invalid message
  6021. * @returns {Boolean}
  6022. */
  6023. validate: function(validator, $field, options) {
  6024. var value = $field.val();
  6025. if (value === '') {
  6026. return true;
  6027. }
  6028. // Don't accept I, O, Q characters
  6029. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  6030. return false;
  6031. }
  6032. value = value.toUpperCase();
  6033. var chars = {
  6034. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  6035. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  6036. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  6037. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  6038. },
  6039. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  6040. sum = 0,
  6041. length = value.length;
  6042. for (var i = 0; i < length; i++) {
  6043. sum += chars[value.charAt(i) + ''] * weights[i];
  6044. }
  6045. var reminder = sum % 11;
  6046. if (reminder === 10) {
  6047. reminder = 'X';
  6048. }
  6049. return (reminder + '') === value.charAt(8);
  6050. }
  6051. };
  6052. }(window.jQuery));
  6053. ;(function($) {
  6054. $.fn.bootstrapValidator.i18n.zipCode = $.extend($.fn.bootstrapValidator.i18n.zipCode || {}, {
  6055. 'default': 'Please enter a valid zip code',
  6056. countryNotSupported: 'The country code %s is not supported',
  6057. country: 'Please enter a valid %s',
  6058. countries: {
  6059. BR: 'Brazilian postal code',
  6060. CA: 'Canadian postal code',
  6061. DK: 'Danish postal code',
  6062. GB: 'United Kingdom postal code',
  6063. IT: 'Italian postal code',
  6064. MA: 'Moroccan postal code',
  6065. NL: 'Dutch postal code',
  6066. SE: 'Swiss postal code',
  6067. SG: 'Singapore postal code',
  6068. US: 'US zip code'
  6069. }
  6070. });
  6071. $.fn.bootstrapValidator.validators.zipCode = {
  6072. html5Attributes: {
  6073. message: 'message',
  6074. country: 'country'
  6075. },
  6076. COUNTRY_CODES: ['BR', 'CA', 'DK', 'GB', 'IT', 'MA', 'NL', 'SE', 'SG', 'US'],
  6077. /**
  6078. * Return true if and only if the input value is a valid country zip code
  6079. *
  6080. * @param {BootstrapValidator} validator The validator plugin instance
  6081. * @param {jQuery} $field Field element
  6082. * @param {Object} options Consist of key:
  6083. * - message: The invalid message
  6084. * - country: The country
  6085. *
  6086. * The country can be defined by:
  6087. * - An ISO 3166 country code
  6088. * - Name of field which its value defines the country code
  6089. * - Name of callback function that returns the country code
  6090. * - A callback function that returns the country code
  6091. *
  6092. * callback: function(value, validator, $field) {
  6093. * // value is the value of field
  6094. * // validator is the BootstrapValidator instance
  6095. * // $field is jQuery element representing the field
  6096. * }
  6097. *
  6098. * @returns {Boolean|Object}
  6099. */
  6100. validate: function(validator, $field, options) {
  6101. var value = $field.val();
  6102. if (value === '' || !options.country) {
  6103. return true;
  6104. }
  6105. var country = options.country;
  6106. if (typeof country !== 'string' || $.inArray(country, this.COUNTRY_CODES) === -1) {
  6107. // Try to determine the country
  6108. country = validator.getDynamicOption($field, country);
  6109. }
  6110. if (!country || $.inArray(country.toUpperCase(), this.COUNTRY_CODES) === -1) {
  6111. return { valid: false, message: $.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.zipCode.countryNotSupported, country) };
  6112. }
  6113. var isValid = false;
  6114. country = country.toUpperCase();
  6115. switch (country) {
  6116. case 'BR':
  6117. isValid = /^(\d{2})([\.]?)(\d{3})([\-]?)(\d{3})$/.test(value);
  6118. break;
  6119. case 'CA':
  6120. 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);
  6121. break;
  6122. case 'DK':
  6123. isValid = /^(DK(-|\s)?)?\d{4}$/i.test(value);
  6124. break;
  6125. case 'GB':
  6126. isValid = this._gb(value);
  6127. break;
  6128. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  6129. case 'IT':
  6130. isValid = /^(I-|IT-)?\d{5}$/i.test(value);
  6131. break;
  6132. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Morocco
  6133. case 'MA':
  6134. isValid = /^[1-9][0-9]{4}$/i.test(value);
  6135. break;
  6136. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  6137. case 'NL':
  6138. isValid = /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  6139. break;
  6140. case 'SE':
  6141. isValid = /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  6142. break;
  6143. case 'SG':
  6144. isValid = /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  6145. break;
  6146. case 'US':
  6147. /* falls through */
  6148. default:
  6149. isValid = /^\d{4,5}([\-]?\d{4})?$/.test(value);
  6150. break;
  6151. }
  6152. return {
  6153. valid: isValid,
  6154. message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.zipCode.country, $.fn.bootstrapValidator.i18n.zipCode.countries[country])
  6155. };
  6156. },
  6157. /**
  6158. * Validate United Kingdom postcode
  6159. * Examples:
  6160. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  6161. * - Special cases:
  6162. * AI-2640, ASCN 1ZZ, GIR 0AA
  6163. *
  6164. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  6165. * @param {String} value The postcode
  6166. * @returns {Boolean}
  6167. */
  6168. _gb: function(value) {
  6169. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  6170. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  6171. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  6172. fourthChar = '[ABEHMNPRVWXY]',
  6173. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  6174. regexps = [
  6175. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  6176. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  6177. // ANA NAA
  6178. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  6179. // AANA NAA
  6180. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  6181. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  6182. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  6183. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  6184. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  6185. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  6186. /^(AI-2640)$/i // Anguilla
  6187. ];
  6188. for (var i = 0; i < regexps.length; i++) {
  6189. if (regexps[i].test(value)) {
  6190. return true;
  6191. }
  6192. }
  6193. return false;
  6194. }
  6195. };
  6196. }(window.jQuery));