bootstrapValidator.js 298 KB

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