bootstrapValidator.js 272 KB

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