bootstrapValidator.js 240 KB

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