bootstrapValidator.js 316 KB

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