bootstrapValidator.js 311 KB

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