bootstrapValidator.js 317 KB

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