bootstrapValidator.js 299 KB

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