bootstrapValidator.js 259 KB

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