bootstrapValidator.js 259 KB

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