bootstrapValidator.js 269 KB

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