bootstrapValidator.js 318 KB

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