bootstrapValidator.js 225 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073
  1. /**
  2. * BootstrapValidator (http://bootstrapvalidator.com)
  3. *
  4. * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  5. *
  6. * @version v0.5.0-dev
  7. * @author https://twitter.com/nghuuphuoc
  8. * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
  9. * @license MIT
  10. */
  11. /**
  12. * BootstrapValidator (http://bootstrapvalidator.com)
  13. *
  14. * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  15. *
  16. * @author http://twitter.com/nghuuphuoc
  17. * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
  18. * @license MIT
  19. */
  20. (function($) {
  21. var BootstrapValidator = function(form, options) {
  22. this.$form = $(form);
  23. this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options);
  24. this.$invalidFields = $([]); // Array of invalid fields
  25. this.$submitButton = null; // The submit button which is clicked to submit form
  26. // Validating status
  27. this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
  28. this.STATUS_VALIDATING = 'VALIDATING';
  29. this.STATUS_INVALID = 'INVALID';
  30. this.STATUS_VALID = 'VALID';
  31. // Determine the event that is fired when user change the field value
  32. // Most modern browsers supports input event except IE 7, 8.
  33. // IE 9 supports input event but the event is still not fired if I press the backspace key.
  34. // Get IE version
  35. // https://gist.github.com/padolsey/527683/#comment-7595
  36. var ieVersion = (function() {
  37. var v = 3, div = document.createElement('div'), a = div.all || [];
  38. while (div.innerHTML = '<!--[if gt IE '+(++v)+']><br><![endif]-->', a[0]) {}
  39. return v > 4 ? v : !v;
  40. }());
  41. var el = document.createElement('div');
  42. this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input';
  43. // The flag to indicate that the form is ready to submit when a remote/callback validator returns
  44. this._submitIfValid = null;
  45. // Field elements
  46. this._cacheFields = {};
  47. this._init();
  48. };
  49. BootstrapValidator.prototype = {
  50. constructor: BootstrapValidator,
  51. /**
  52. * Init form
  53. */
  54. _init: function() {
  55. var that = this,
  56. options = {
  57. excluded: this.$form.attr('data-bv-excluded'),
  58. trigger: this.$form.attr('data-bv-trigger'),
  59. message: this.$form.attr('data-bv-message'),
  60. container: this.$form.attr('data-bv-container'),
  61. group: this.$form.attr('data-bv-group'),
  62. submitButtons: this.$form.attr('data-bv-submitbuttons'),
  63. threshold: this.$form.attr('data-bv-threshold'),
  64. live: this.$form.attr('data-bv-live'),
  65. fields: {},
  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. };
  72. this.$form
  73. // Disable client side validation in HTML 5
  74. .attr('novalidate', 'novalidate')
  75. .addClass(this.options.elementClass)
  76. // Disable the default submission first
  77. .on('submit.bv', function(e) {
  78. e.preventDefault();
  79. that.validate();
  80. })
  81. .on('click.bv', this.options.submitButtons, function() {
  82. that.$submitButton = $(this);
  83. // The user just click the submit button
  84. that._submitIfValid = true;
  85. })
  86. // Find all fields which have either "name" or "data-bv-field" attribute
  87. .find('[name], [data-bv-field]')
  88. .each(function() {
  89. var $field = $(this);
  90. if (that._isExcluded($field)) {
  91. return;
  92. }
  93. var field = $field.attr('name') || $field.attr('data-bv-field'),
  94. opts = that._parseOptions($field);
  95. if (opts) {
  96. $field.attr('data-bv-field', field);
  97. options.fields[field] = $.extend({}, opts, options.fields[field]);
  98. }
  99. });
  100. this.options = $.extend(true, this.options, options);
  101. for (var field in this.options.fields) {
  102. this._initField(field);
  103. }
  104. this.$form.trigger($.Event('init.form.bv'), {
  105. options: this.options
  106. });
  107. },
  108. /**
  109. * Parse the validator options from HTML attributes
  110. *
  111. * @param {jQuery} $field The field element
  112. * @returns {Object}
  113. */
  114. _parseOptions: function($field) {
  115. var field = $field.attr('name') || $field.attr('data-bv-field'),
  116. validators = {},
  117. validator,
  118. v, // Validator name
  119. enabled,
  120. optionName,
  121. optionValue,
  122. html5AttrName,
  123. html5AttrMap;
  124. for (v in $.fn.bootstrapValidator.validators) {
  125. validator = $.fn.bootstrapValidator.validators[v];
  126. enabled = $field.attr('data-bv-' + v.toLowerCase()) + '';
  127. html5AttrMap = ('function' === typeof validator.enableByHtml5) ? validator.enableByHtml5($field) : null;
  128. if ((html5AttrMap && enabled !== 'false')
  129. || (html5AttrMap !== true && ('' === enabled || 'true' === enabled)))
  130. {
  131. // Try to parse the options via attributes
  132. validator.html5Attributes = validator.html5Attributes || { message: 'message' };
  133. validators[v] = $.extend({}, html5AttrMap === true ? {} : html5AttrMap, validators[v]);
  134. for (html5AttrName in validator.html5Attributes) {
  135. optionName = validator.html5Attributes[html5AttrName];
  136. optionValue = $field.attr('data-bv-' + v.toLowerCase() + '-' + html5AttrName);
  137. if (optionValue) {
  138. if ('true' === optionValue) {
  139. optionValue = true;
  140. } else if ('false' === optionValue) {
  141. optionValue = false;
  142. }
  143. validators[v][optionName] = optionValue;
  144. }
  145. }
  146. }
  147. }
  148. var opts = {
  149. feedbackIcons: $field.attr('data-bv-feedbackicons'),
  150. trigger: $field.attr('data-bv-trigger'),
  151. message: $field.attr('data-bv-message'),
  152. container: $field.attr('data-bv-container'),
  153. group: $field.attr('data-bv-group'),
  154. selector: $field.attr('data-bv-selector'),
  155. threshold: $field.attr('data-bv-threshold'),
  156. validators: validators
  157. },
  158. emptyOptions = $.isEmptyObject(opts), // Check if the field options are set using HTML attributes
  159. emptyValidators = $.isEmptyObject(validators); // Check if the field validators are set using HTML attributes
  160. if (!emptyValidators || (!emptyOptions && this.options.fields && this.options.fields[field])) {
  161. opts.validators = validators;
  162. return opts;
  163. } else {
  164. return null;
  165. }
  166. },
  167. /**
  168. * Init field
  169. *
  170. * @param {String|jQuery} field The field name or field element
  171. */
  172. _initField: function(field) {
  173. var fields = $([]);
  174. switch (typeof field) {
  175. case 'object':
  176. fields = field;
  177. field = field.attr('data-bv-field');
  178. break;
  179. case 'string':
  180. fields = this.getFieldElements(field);
  181. fields.attr('data-bv-field', field);
  182. break;
  183. default:
  184. break;
  185. }
  186. if (this.options.fields[field] === null || this.options.fields[field].validators === null) {
  187. return;
  188. }
  189. // We don't need to validate non-existing fields
  190. if (fields.length === 0) {
  191. delete this.options.fields[field];
  192. return;
  193. }
  194. var validatorName;
  195. for (validatorName in this.options.fields[field].validators) {
  196. if (!$.fn.bootstrapValidator.validators[validatorName]) {
  197. delete this.options.fields[field].validators[validatorName];
  198. }
  199. }
  200. if (this.options.fields[field].enabled === null) {
  201. this.options.fields[field].enabled = true;
  202. }
  203. var that = this,
  204. total = fields.length,
  205. type = fields.attr('type'),
  206. updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
  207. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent;
  208. for (var i = 0; i < total; i++) {
  209. var $field = fields.eq(i),
  210. group = this.options.fields[field].group || this.options.group,
  211. $parent = $field.parents(group),
  212. // Allow user to indicate where the error messages are shown
  213. container = this.options.fields[field].container || this.options.container,
  214. $message = (container && container !== 'tooltip' && container !== 'popover') ? $(container) : this._getMessageContainer($field, group);
  215. if (container && container !== 'tooltip' && container !== 'popover') {
  216. $message.addClass('has-error');
  217. }
  218. // Remove all error messages and feedback icons
  219. $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove();
  220. $parent.find('i[data-bv-icon-for="' + field + '"]').remove();
  221. // Whenever the user change the field value, mark it as not validated yet
  222. $field.off(event + '.update.bv').on(event + '.update.bv', function() {
  223. // Reset the flag
  224. that._submitIfValid = false;
  225. that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
  226. });
  227. // Create help block elements for showing the error messages
  228. $field.data('bv.messages', $message);
  229. for (validatorName in this.options.fields[field].validators) {
  230. $field.data('bv.result.' + validatorName, this.STATUS_NOT_VALIDATED);
  231. if (!updateAll || i === total - 1) {
  232. $('<small/>')
  233. .css('display', 'none')
  234. .addClass('help-block')
  235. .attr('data-bv-validator', validatorName)
  236. .attr('data-bv-for', field)
  237. .attr('data-bv-result', this.STATUS_NOT_VALIDATED)
  238. .html(this._getMessage(field, validatorName))
  239. .appendTo($message);
  240. }
  241. }
  242. // Prepare the feedback icons
  243. // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
  244. if (this.options.fields[field].feedbackIcons !== false && this.options.fields[field].feedbackIcons !== 'false'
  245. && this.options.feedbackIcons
  246. && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid
  247. && (!updateAll || i === total - 1))
  248. {
  249. $parent.removeClass('has-success').removeClass('has-error').addClass('has-feedback');
  250. var $icon = $('<i/>')
  251. .css('display', 'none')
  252. .addClass('form-control-feedback')
  253. .attr('data-bv-icon-for', field)
  254. // Place it after the label containing the checkbox/radio
  255. // so when clicking the icon, it doesn't effect to the checkbox/radio element
  256. .insertAfter(('checkbox' === type || 'radio' === type) ? $field.parent() : $field);
  257. // The feedback icon does not render correctly if there is no label
  258. // https://github.com/twbs/bootstrap/issues/12873
  259. if ($parent.find('label').length === 0) {
  260. $icon.css('top', 0);
  261. }
  262. // Fix feedback icons in input-group
  263. if ($parent.find('.input-group-addon').length !== 0) {
  264. $icon.css({
  265. 'top': 0,
  266. 'z-index': 100
  267. });
  268. }
  269. }
  270. }
  271. // Set live mode
  272. var trigger = this.options.fields[field].trigger || this.options.trigger || event,
  273. events = $.map(trigger.split(' '), function(item) {
  274. return item + '.live.bv';
  275. }).join(' ');
  276. switch (this.options.live) {
  277. case 'submitted':
  278. break;
  279. case 'disabled':
  280. fields.off(events);
  281. break;
  282. case 'enabled':
  283. /* falls through */
  284. default:
  285. fields.off(events).on(events, function() {
  286. if (that._exceedThreshold($(this))) {
  287. that.validateField($(this));
  288. }
  289. });
  290. break;
  291. }
  292. this.$form.trigger($.Event('init.field.bv'), {
  293. field: field,
  294. element: fields
  295. });
  296. },
  297. /**
  298. * Get the error message for given field and validator
  299. *
  300. * @param {String} field The field name
  301. * @param {String} validatorName The validator name
  302. * @returns {String}
  303. */
  304. _getMessage: function(field, validatorName) {
  305. if (!this.options.fields[field] || !$.fn.bootstrapValidator.validators[validatorName]
  306. || !this.options.fields[field].validators || !this.options.fields[field].validators[validatorName])
  307. {
  308. return '';
  309. }
  310. var options = this.options.fields[field].validators[validatorName];
  311. switch (true) {
  312. case (!!options.message):
  313. return options.message;
  314. case (!!$.fn.bootstrapValidator.i18n[validatorName]):
  315. return ('function' === typeof $.fn.bootstrapValidator.i18n[validatorName].getMessage)
  316. ? $.fn.bootstrapValidator.i18n[validatorName].getMessage(options)
  317. : $.fn.bootstrapValidator.i18n[validatorName]['default'];
  318. case (!!this.options.fields[field].message):
  319. return this.options.fields[field].message;
  320. default:
  321. return this.options.message;
  322. }
  323. },
  324. /**
  325. * Get the element to place the error messages
  326. *
  327. * @param {jQuery} $field The field element
  328. * @param {String} group
  329. * @returns {jQuery}
  330. */
  331. _getMessageContainer: function($field, group) {
  332. var $parent = $field.parent();
  333. if ($parent.is(group)) {
  334. return $parent;
  335. }
  336. var cssClasses = $parent.attr('class');
  337. if (!cssClasses) {
  338. return this._getMessageContainer($parent, group);
  339. }
  340. cssClasses = cssClasses.split(' ');
  341. var n = cssClasses.length;
  342. for (var i = 0; i < n; i++) {
  343. if (/^col-(xs|sm|md|lg)-\d+$/.test(cssClasses[i]) || /^col-(xs|sm|md|lg)-offset-\d+$/.test(cssClasses[i])) {
  344. return $parent;
  345. }
  346. }
  347. return this._getMessageContainer($parent, group);
  348. },
  349. /**
  350. * Called when all validations are completed
  351. */
  352. _submit: function() {
  353. var isValid = this.isValid(),
  354. eventType = isValid ? 'success.form.bv' : 'error.form.bv',
  355. e = $.Event(eventType);
  356. this.$form.trigger(e);
  357. // Call default handler
  358. // Check if whether the submit button is clicked
  359. if (this.$submitButton) {
  360. isValid ? this._onSuccess(e) : this._onError(e);
  361. }
  362. },
  363. /**
  364. * Check if the field is excluded.
  365. * Returning true means that the field will not be validated
  366. *
  367. * @param {jQuery} $field The field element
  368. * @returns {Boolean}
  369. */
  370. _isExcluded: function($field) {
  371. if (this.options.excluded) {
  372. // Convert to array first
  373. if ('string' === typeof this.options.excluded) {
  374. this.options.excluded = $.map(this.options.excluded.split(','), function(item) {
  375. // Trim the spaces
  376. return $.trim(item);
  377. });
  378. }
  379. var length = this.options.excluded.length;
  380. for (var i = 0; i < length; i++) {
  381. if (('string' === typeof this.options.excluded[i] && $field.is(this.options.excluded[i]))
  382. || ('function' === typeof this.options.excluded[i] && this.options.excluded[i].call(this, $field, this) === true))
  383. {
  384. return true;
  385. }
  386. }
  387. }
  388. return false;
  389. },
  390. /**
  391. * Check if the number of characters of field value exceed the threshold or not
  392. *
  393. * @param {jQuery} $field The field element
  394. * @returns {Boolean}
  395. */
  396. _exceedThreshold: function($field) {
  397. var field = $field.attr('data-bv-field'),
  398. threshold = this.options.fields[field].threshold || this.options.threshold;
  399. if (!threshold) {
  400. return true;
  401. }
  402. var cannotType = $.inArray($field.attr('type'), ['button', 'checkbox', 'file', 'hidden', 'image', 'radio', 'reset', 'submit']) !== -1;
  403. return (cannotType || $field.val().length >= threshold);
  404. },
  405. // --- Events ---
  406. /**
  407. * The default handler of error.form.bv event.
  408. * It will be called when there is a invalid field
  409. *
  410. * @param {jQuery.Event} e The jQuery event object
  411. */
  412. _onError: function(e) {
  413. if (e.isDefaultPrevented()) {
  414. return;
  415. }
  416. if ('submitted' === this.options.live) {
  417. // Enable live mode
  418. this.options.live = 'enabled';
  419. var that = this;
  420. for (var field in this.options.fields) {
  421. (function(f) {
  422. var fields = that.getFieldElements(f);
  423. if (fields.length) {
  424. var type = $(fields[0]).attr('type'),
  425. event = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === $(fields[0]).get(0).tagName) ? 'change' : that._changeEvent,
  426. trigger = that.options.fields[field].trigger || that.options.trigger || event,
  427. events = $.map(trigger.split(' '), function(item) {
  428. return item + '.live.bv';
  429. }).join(' ');
  430. fields.off(events).on(events, function() {
  431. if (that._exceedThreshold($(this))) {
  432. that.validateField($(this));
  433. }
  434. });
  435. }
  436. })(field);
  437. }
  438. }
  439. var $invalidField = this.$invalidFields.eq(0);
  440. if ($invalidField) {
  441. // Activate the tab containing the invalid field if exists
  442. var $tabPane = $invalidField.parents('.tab-pane'), tabId;
  443. if ($tabPane && (tabId = $tabPane.attr('id'))) {
  444. $('a[href="#' + tabId + '"][data-toggle="tab"]').tab('show');
  445. }
  446. // Focus to the first invalid field
  447. $invalidField.focus();
  448. }
  449. },
  450. /**
  451. * The default handler of success.form.bv event.
  452. * It will be called when all the fields are valid
  453. *
  454. * @param {jQuery.Event} e The jQuery event object
  455. */
  456. _onSuccess: function(e) {
  457. if (e.isDefaultPrevented()) {
  458. return;
  459. }
  460. // Call the custom submission if enabled
  461. if (this.options.submitHandler && 'function' === typeof this.options.submitHandler) {
  462. // If you want to submit the form inside your submit handler, please call defaultSubmit() method
  463. this.options.submitHandler.call(this, this, this.$form);
  464. } else {
  465. this.disableSubmitButtons(true).defaultSubmit();
  466. }
  467. },
  468. /**
  469. * Called after validating a field element
  470. *
  471. * @param {jQuery} $field The field element
  472. * @param {String} [validatorName] The validator name
  473. */
  474. _onFieldValidated: function($field, validatorName) {
  475. var field = $field.attr('data-bv-field'),
  476. validators = this.options.fields[field].validators,
  477. counter = {},
  478. numValidators = 0;
  479. // Trigger an event after given validator completes
  480. if (validatorName) {
  481. var data = {
  482. field: field,
  483. element: $field,
  484. validator: validatorName
  485. };
  486. switch ($field.data('bv.result.' + validatorName)) {
  487. case this.STATUS_INVALID:
  488. this.$form.trigger($.Event('error.validator.bv'), data);
  489. break;
  490. case this.STATUS_VALID:
  491. this.$form.trigger($.Event('success.validator.bv'), data);
  492. break;
  493. default:
  494. break;
  495. }
  496. }
  497. counter[this.STATUS_NOT_VALIDATED] = 0;
  498. counter[this.STATUS_VALIDATING] = 0;
  499. counter[this.STATUS_INVALID] = 0;
  500. counter[this.STATUS_VALID] = 0;
  501. for (var v in validators) {
  502. numValidators++;
  503. var result = $field.data('bv.result.' + v);
  504. if (result) {
  505. counter[result]++;
  506. }
  507. }
  508. if (counter[this.STATUS_VALID] === numValidators) {
  509. // Remove from the list of invalid fields
  510. this.$invalidFields = this.$invalidFields.not($field);
  511. this.$form.trigger($.Event('success.field.bv'), {
  512. field: field,
  513. element: $field
  514. });
  515. }
  516. // If all validators are completed and there is at least one validator which doesn't pass
  517. else if (counter[this.STATUS_NOT_VALIDATED] === 0 && counter[this.STATUS_VALIDATING] === 0 && counter[this.STATUS_INVALID] > 0) {
  518. // Add to the list of invalid fields
  519. this.$invalidFields = this.$invalidFields.add($field);
  520. this.$form.trigger($.Event('error.field.bv'), {
  521. field: field,
  522. element: $field
  523. });
  524. }
  525. },
  526. // --- Public methods ---
  527. /**
  528. * Retrieve the field elements by given name
  529. *
  530. * @param {String} field The field name
  531. * @returns {null|jQuery[]}
  532. */
  533. getFieldElements: function(field) {
  534. if (!this._cacheFields[field]) {
  535. this._cacheFields[field] = (this.options.fields[field] && this.options.fields[field].selector)
  536. ? $(this.options.fields[field].selector)
  537. : this.$form.find('[name="' + field + '"]');
  538. }
  539. return this._cacheFields[field];
  540. },
  541. /**
  542. * Disable/enable submit buttons
  543. *
  544. * @param {Boolean} disabled Can be true or false
  545. * @returns {BootstrapValidator}
  546. */
  547. disableSubmitButtons: function(disabled) {
  548. if (!disabled) {
  549. this.$form.find(this.options.submitButtons).removeAttr('disabled');
  550. } else if (this.options.live !== 'disabled') {
  551. // Don't disable if the live validating mode is disabled
  552. this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
  553. }
  554. return this;
  555. },
  556. /**
  557. * Validate the form
  558. *
  559. * @returns {BootstrapValidator}
  560. */
  561. validate: function() {
  562. if (!this.options.fields) {
  563. return this;
  564. }
  565. this.disableSubmitButtons(true);
  566. for (var field in this.options.fields) {
  567. this.validateField(field);
  568. }
  569. this._submit();
  570. return this;
  571. },
  572. /**
  573. * Validate given field
  574. *
  575. * @param {String|jQuery} field The field name or field element
  576. * @returns {BootstrapValidator}
  577. */
  578. validateField: function(field) {
  579. var fields = $([]);
  580. switch (typeof field) {
  581. case 'object':
  582. fields = field;
  583. field = field.attr('data-bv-field');
  584. break;
  585. case 'string':
  586. fields = this.getFieldElements(field);
  587. break;
  588. default:
  589. break;
  590. }
  591. if (this.options.fields[field] && this.options.fields[field].enabled === false) {
  592. return this;
  593. }
  594. var that = this,
  595. type = fields.attr('type'),
  596. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  597. updateAll = ('radio' === type || 'checkbox' === type),
  598. validators = this.options.fields[field].validators,
  599. validatorName,
  600. validateResult;
  601. for (var i = 0; i < total; i++) {
  602. var $field = fields.eq(i);
  603. if (this._isExcluded($field)) {
  604. continue;
  605. }
  606. for (validatorName in validators) {
  607. if ($field.data('bv.dfs.' + validatorName)) {
  608. $field.data('bv.dfs.' + validatorName).reject();
  609. }
  610. // Don't validate field if it is already done
  611. var result = $field.data('bv.result.' + validatorName);
  612. if (result === this.STATUS_VALID || result === this.STATUS_INVALID) {
  613. this._onFieldValidated($field, validatorName);
  614. continue;
  615. }
  616. $field.data('bv.result.' + validatorName, this.STATUS_VALIDATING);
  617. validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);
  618. // validateResult can be a $.Deferred object ...
  619. if ('object' === typeof validateResult) {
  620. this.updateStatus(updateAll ? field : $field, this.STATUS_VALIDATING, validatorName);
  621. $field.data('bv.dfs.' + validatorName, validateResult);
  622. validateResult.done(function($f, v, isValid, message) {
  623. // v is validator name
  624. $f.removeData('bv.dfs.' + v);
  625. if (message) {
  626. // Update the error message
  627. $field.data('bv.messages').find('.help-block[data-bv-validator="' + v + '"][data-bv-for="' + $f.attr('data-bv-field') + '"]').html(message);
  628. }
  629. that.updateStatus(updateAll ? $f.attr('data-bv-field') : $f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
  630. if (isValid && that._submitIfValid === true) {
  631. // If a remote validator returns true and the form is ready to submit, then do it
  632. that._submit();
  633. }
  634. });
  635. }
  636. // ... or a boolean value
  637. else if ('boolean' === typeof validateResult) {
  638. this.updateStatus(updateAll ? field : $field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
  639. }
  640. }
  641. }
  642. return this;
  643. },
  644. /**
  645. * Update all validating results of field
  646. *
  647. * @param {String|jQuery} field The field name or field element
  648. * @param {String} status The status. Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
  649. * @param {String} [validatorName] The validator name. If null, the method updates validity result for all validators
  650. * @returns {BootstrapValidator}
  651. */
  652. updateStatus: function(field, status, validatorName) {
  653. var fields = $([]);
  654. switch (typeof field) {
  655. case 'object':
  656. fields = field;
  657. field = field.attr('data-bv-field');
  658. break;
  659. case 'string':
  660. fields = this.getFieldElements(field);
  661. break;
  662. default:
  663. break;
  664. }
  665. var that = this,
  666. type = fields.attr('type'),
  667. group = this.options.fields[field].group || this.options.group,
  668. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  669. for (var i = 0; i < total; i++) {
  670. var $field = fields.eq(i),
  671. $parent = $field.parents(group),
  672. $message = $field.data('bv.messages'),
  673. $allErrors = $message.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]'),
  674. $errors = validatorName ? $allErrors.filter('[data-bv-validator="' + validatorName + '"]') : $allErrors,
  675. $icon = $parent.find('.form-control-feedback[data-bv-icon-for="' + field + '"]'),
  676. container = this.options.fields[field].container || this.options.container,
  677. isValidField = null;
  678. // Update status
  679. if (validatorName) {
  680. $field.data('bv.result.' + validatorName, status);
  681. } else {
  682. for (var v in this.options.fields[field].validators) {
  683. $field.data('bv.result.' + v, status);
  684. }
  685. }
  686. // Show/hide error elements and feedback icons
  687. $errors.attr('data-bv-result', status);
  688. // Determine the tab containing the element
  689. var $tabPane = $field.parents('.tab-pane'),
  690. tabId, $tab;
  691. if ($tabPane && (tabId = $tabPane.attr('id'))) {
  692. $tab = $('a[href="#' + tabId + '"][data-toggle="tab"]').parent();
  693. }
  694. switch (status) {
  695. case this.STATUS_VALIDATING:
  696. isValidField = null;
  697. this.disableSubmitButtons(true);
  698. $parent.removeClass('has-success').removeClass('has-error');
  699. if ($icon) {
  700. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();
  701. }
  702. if ($tab) {
  703. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
  704. }
  705. break;
  706. case this.STATUS_INVALID:
  707. isValidField = false;
  708. this.disableSubmitButtons(true);
  709. $parent.removeClass('has-success').addClass('has-error');
  710. if ($icon) {
  711. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
  712. }
  713. if ($tab) {
  714. $tab.removeClass('bv-tab-success').addClass('bv-tab-error');
  715. }
  716. break;
  717. case this.STATUS_VALID:
  718. // If the field is valid (passes all validators)
  719. isValidField = ($allErrors.filter('[data-bv-result="' + this.STATUS_NOT_VALIDATED +'"]').length === 0)
  720. ? ($allErrors.filter('[data-bv-result="' + this.STATUS_VALID +'"]').length === $allErrors.length) // All validators are completed
  721. : null; // There are some validators that have not done
  722. if (isValidField !== null) {
  723. this.disableSubmitButtons(this.$submitButton ? !this.isValid() : !isValidField);
  724. if ($icon) {
  725. $icon
  726. .removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).removeClass(this.options.feedbackIcons.valid)
  727. .addClass(isValidField ? this.options.feedbackIcons.valid : this.options.feedbackIcons.invalid)
  728. .show();
  729. }
  730. }
  731. $parent.removeClass('has-error has-success').addClass(this.isValidContainer($parent) ? 'has-success' : 'has-error');
  732. if ($tab) {
  733. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error').addClass(this.isValidContainer($tabPane) ? 'bv-tab-success' : 'bv-tab-error');
  734. }
  735. break;
  736. case this.STATUS_NOT_VALIDATED:
  737. /* falls through */
  738. default:
  739. isValidField = null;
  740. this.disableSubmitButtons(false);
  741. $parent.removeClass('has-success').removeClass('has-error');
  742. if ($icon) {
  743. $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide();
  744. }
  745. if ($tab) {
  746. $tab.removeClass('bv-tab-success').removeClass('bv-tab-error');
  747. }
  748. break;
  749. }
  750. switch (true) {
  751. // Only show the first error message if it is placed inside a tooltip ...
  752. case ($icon && 'tooltip' === container):
  753. (isValidField === false)
  754. ? $icon.css('cursor', 'pointer').tooltip('destroy').tooltip({
  755. html: true,
  756. placement: 'top',
  757. title: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html()
  758. })
  759. : $icon.css('cursor', '').tooltip('destroy');
  760. break;
  761. // ... or popover
  762. case ($icon && 'popover' === container):
  763. (isValidField === false)
  764. ? $icon.css('cursor', 'pointer').popover('destroy').popover({
  765. content: $allErrors.filter('[data-bv-result="' + that.STATUS_INVALID + '"]').eq(0).html(),
  766. html: true,
  767. placement: 'top',
  768. trigger: 'hover click'
  769. })
  770. : $icon.css('cursor', '').popover('destroy');
  771. break;
  772. default:
  773. (status === this.STATUS_INVALID) ? $errors.show() : $errors.hide();
  774. break;
  775. }
  776. // Trigger an event
  777. this.$form.trigger($.Event('status.field.bv'), {
  778. field: field,
  779. element: $field,
  780. status: status
  781. });
  782. this._onFieldValidated($field, validatorName);
  783. }
  784. return this;
  785. },
  786. /**
  787. * Check the form validity
  788. *
  789. * @returns {Boolean}
  790. */
  791. isValid: function() {
  792. for (var field in this.options.fields) {
  793. if (!this.isValidField(field)) {
  794. return false;
  795. }
  796. }
  797. return true;
  798. },
  799. /**
  800. * Check if the field is valid or not
  801. *
  802. * @param {String|jQuery} field The field name or field element
  803. * @returns {Boolean}
  804. */
  805. isValidField: function(field) {
  806. var fields = $([]);
  807. switch (typeof field) {
  808. case 'object':
  809. fields = field;
  810. field = field.attr('data-bv-field');
  811. break;
  812. case 'string':
  813. fields = this.getFieldElements(field);
  814. break;
  815. default:
  816. break;
  817. }
  818. if (fields.length === 0 || this.options.fields[field] === null || this.options.fields[field].enabled === false) {
  819. return true;
  820. }
  821. var type = fields.attr('type'),
  822. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length,
  823. $field, validatorName, status;
  824. for (var i = 0; i < total; i++) {
  825. $field = fields.eq(i);
  826. if (this._isExcluded($field)) {
  827. continue;
  828. }
  829. for (validatorName in this.options.fields[field].validators) {
  830. status = $field.data('bv.result.' + validatorName);
  831. if (status !== this.STATUS_VALID) {
  832. return false;
  833. }
  834. }
  835. }
  836. return true;
  837. },
  838. /**
  839. * Check if all fields inside a given container are valid.
  840. * It's useful when working with a wizard-like such as tab, collapse
  841. *
  842. * @param {jQuery} $container The container element
  843. * @returns {Boolean}
  844. */
  845. isValidContainer: function($container) {
  846. var that = this, map = {};
  847. $container.find('[data-bv-field]').each(function() {
  848. var field = $(this).attr('data-bv-field');
  849. if (!map[field]) {
  850. map[field] = $(this);
  851. }
  852. });
  853. for (var field in map) {
  854. var $f = map[field];
  855. if ($f.data('bv.messages')
  856. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
  857. .filter(function() {
  858. var v = $(this).attr('data-bv-validator');
  859. return ($f.data('bv.result.' + v) && $f.data('bv.result.' + v) !== that.STATUS_VALID);
  860. })
  861. .length !== 0)
  862. {
  863. // The field is not valid
  864. return false;
  865. }
  866. }
  867. return true;
  868. },
  869. /**
  870. * Submit the form using default submission.
  871. * It also does not perform any validations when submitting the form
  872. *
  873. * It might be used when you want to submit the form right inside the submitHandler()
  874. */
  875. defaultSubmit: function() {
  876. if (this.$submitButton) {
  877. // Create hidden input to send the submit buttons
  878. $('<input/>')
  879. .attr('type', 'hidden')
  880. .attr('data-bv-submit-hidden', '')
  881. .attr('name', this.$submitButton.attr('name'))
  882. .val(this.$submitButton.val())
  883. .appendTo(this.$form);
  884. }
  885. // Submit form
  886. this.$form.off('submit.bv').submit();
  887. },
  888. // Useful APIs which aren't used internally
  889. /**
  890. * Get the list of invalid fields
  891. *
  892. * @returns {jQuery[]}
  893. */
  894. getInvalidFields: function() {
  895. return this.$invalidFields;
  896. },
  897. /**
  898. * Returns the clicked submit button
  899. *
  900. * @returns {jQuery}
  901. */
  902. getSubmitButton: function() {
  903. return this.$submitButton;
  904. },
  905. /**
  906. * Get the error messages
  907. *
  908. * @param {String|jQuery} [field] The field name or field element
  909. * If the field is not defined, the method returns all error messages of all fields
  910. * @returns {String[]}
  911. */
  912. getErrors: function(field) {
  913. var that = this,
  914. messages = [],
  915. $fields = $([]);
  916. switch (true) {
  917. case (field && 'object' === typeof field):
  918. $fields = field;
  919. break;
  920. case (field && 'string' === typeof field):
  921. var f = this.getFieldElements(field);
  922. if (f.length > 0) {
  923. var type = f.attr('type');
  924. $fields = ('radio' === type || 'checkbox' === type) ? f.eq(0) : f;
  925. }
  926. break;
  927. default:
  928. $fields = this.$invalidFields;
  929. break;
  930. }
  931. $fields.each(function() {
  932. messages = messages.concat(
  933. $(this)
  934. .data('bv.messages')
  935. .find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]')
  936. .map(function() {
  937. return $(this).html();
  938. })
  939. .get()
  940. );
  941. });
  942. return messages;
  943. },
  944. /**
  945. * Add a new field
  946. *
  947. * @param {String|jQuery} field The field name or field element
  948. * @param {Object} [options] The validator rules
  949. * @returns {BootstrapValidator}
  950. */
  951. addField: function(field, options) {
  952. var fields = $([]);
  953. switch (typeof field) {
  954. case 'object':
  955. fields = field;
  956. field = field.attr('data-bv-field') || field.attr('name');
  957. break;
  958. case 'string':
  959. delete this._cacheFields[field];
  960. fields = this.getFieldElements(field);
  961. break;
  962. default:
  963. break;
  964. }
  965. fields.attr('data-bv-field', field);
  966. var type = fields.attr('type'),
  967. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  968. for (var i = 0; i < total; i++) {
  969. var $field = fields.eq(i);
  970. // Try to parse the options from HTML attributes
  971. var opts = this._parseOptions($field);
  972. opts = (opts === null) ? options : $.extend(true, options, opts);
  973. this.options.fields[field] = $.extend(true, this.options.fields[field], opts);
  974. // Update the cache
  975. this._cacheFields[field] = this._cacheFields[field] ? this._cacheFields[field].add($field) : $field;
  976. // Init the element
  977. this._initField(('checkbox' === type || 'radio' === type) ? field : $field);
  978. }
  979. this.disableSubmitButtons(false);
  980. // Trigger an event
  981. this.$form.trigger($.Event('added.field.bv'), {
  982. field: field,
  983. element: fields,
  984. options: this.options.fields[field]
  985. });
  986. return this;
  987. },
  988. /**
  989. * Remove a given field
  990. *
  991. * @param {String|jQuery} field The field name or field element
  992. * @returns {BootstrapValidator}
  993. */
  994. removeField: function(field) {
  995. var fields = $([]);
  996. switch (typeof field) {
  997. case 'object':
  998. fields = field;
  999. field = field.attr('data-bv-field') || field.attr('name');
  1000. fields.attr('data-bv-field', field);
  1001. break;
  1002. case 'string':
  1003. fields = this.getFieldElements(field);
  1004. break;
  1005. default:
  1006. break;
  1007. }
  1008. if (fields.length === 0) {
  1009. return this;
  1010. }
  1011. var type = fields.attr('type'),
  1012. total = ('radio' === type || 'checkbox' === type) ? 1 : fields.length;
  1013. for (var i = 0; i < total; i++) {
  1014. var $field = fields.eq(i);
  1015. // Remove from the list of invalid fields
  1016. this.$invalidFields = this.$invalidFields.not($field);
  1017. // Update the cache
  1018. this._cacheFields[field] = this._cacheFields[field].not($field);
  1019. }
  1020. if (!this._cacheFields[field] || this._cacheFields[field].length === 0) {
  1021. delete this.options.fields[field];
  1022. }
  1023. if ('checkbox' === type || 'radio' === type) {
  1024. this._initField(field);
  1025. }
  1026. this.disableSubmitButtons(false);
  1027. // Trigger an event
  1028. this.$form.trigger($.Event('removed.field.bv'), {
  1029. field: field,
  1030. element: fields
  1031. });
  1032. return this;
  1033. },
  1034. /**
  1035. * Reset the form
  1036. *
  1037. * @param {Boolean} [resetFormData] Reset current form data
  1038. * @returns {BootstrapValidator}
  1039. */
  1040. resetForm: function(resetFormData) {
  1041. var field, fields, total, type, validator;
  1042. for (field in this.options.fields) {
  1043. fields = this.getFieldElements(field);
  1044. total = fields.length;
  1045. for (var i = 0; i < total; i++) {
  1046. for (validator in this.options.fields[field].validators) {
  1047. fields.eq(i).removeData('bv.dfs.' + validator);
  1048. }
  1049. }
  1050. // Mark field as not validated yet
  1051. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1052. if (resetFormData) {
  1053. type = fields.attr('type');
  1054. ('radio' === type || 'checkbox' === type) ? fields.removeAttr('checked').removeAttr('selected') : fields.val('');
  1055. }
  1056. }
  1057. this.$invalidFields = $([]);
  1058. this.$submitButton = null;
  1059. // Enable submit buttons
  1060. this.disableSubmitButtons(false);
  1061. return this;
  1062. },
  1063. /**
  1064. * Revalidate given field
  1065. * It's used when you need to revalidate the field which its value is updated by other plugin
  1066. *
  1067. * @param {String|jQuery} field The field name of field element
  1068. * @returns {BootstrapValidator}
  1069. */
  1070. revalidateField: function(field) {
  1071. this.updateStatus(field, this.STATUS_NOT_VALIDATED)
  1072. .validateField(field);
  1073. return this;
  1074. },
  1075. /**
  1076. * Enable/Disable all validators to given field
  1077. *
  1078. * @param {String} field The field name
  1079. * @param {Boolean} enabled Enable/Disable field validators
  1080. * @returns {BootstrapValidator}
  1081. */
  1082. enableFieldValidators: function(field, enabled) {
  1083. if (this.options.fields[field].enabled !== enabled) {
  1084. this.options.fields[field].enabled = enabled;
  1085. this.updateStatus(field, this.STATUS_NOT_VALIDATED);
  1086. }
  1087. return this;
  1088. },
  1089. /**
  1090. * Destroy the plugin
  1091. * It will remove all error messages, feedback icons and turn off the events
  1092. */
  1093. destroy: function() {
  1094. var field, fields, $field, validator, $icon, container, group;
  1095. for (field in this.options.fields) {
  1096. fields = this.getFieldElements(field);
  1097. container = this.options.fields[field].container || this.options.container,
  1098. group = this.options.fields[field].group || this.options.group;
  1099. for (var i = 0; i < fields.length; i++) {
  1100. $field = fields.eq(i);
  1101. $field
  1102. // Remove all error messages
  1103. .data('bv.messages')
  1104. .find('.help-block[data-bv-validator][data-bv-for="' + field + '"]').remove().end()
  1105. .end()
  1106. .removeData('bv.messages')
  1107. // Remove feedback classes
  1108. .parents(group)
  1109. .removeClass('has-feedback has-error has-success')
  1110. .end()
  1111. // Turn off events
  1112. .off('.bv')
  1113. .removeAttr('data-bv-field');
  1114. // Remove feedback icons, tooltip/popover container
  1115. $icon = $field.parents(group).find('i[data-bv-icon-for="' + field + '"]');
  1116. if ($icon) {
  1117. switch (container) {
  1118. case 'tooltip':
  1119. $icon.tooltip('destroy').remove();
  1120. break;
  1121. case 'popover':
  1122. $icon.popover('destroy').remove();
  1123. break;
  1124. default:
  1125. $icon.remove();
  1126. break;
  1127. }
  1128. }
  1129. for (validator in this.options.fields[field].validators) {
  1130. $field.removeData('bv.result.' + validator).removeData('bv.dfs.' + validator);
  1131. }
  1132. }
  1133. }
  1134. // Enable submit buttons
  1135. this.disableSubmitButtons(false);
  1136. this.$form
  1137. .removeClass(this.options.elementClass)
  1138. .off('.bv')
  1139. .removeData('bootstrapValidator')
  1140. // Remove generated hidden elements
  1141. .find('[data-bv-submit-hidden]').remove();
  1142. }
  1143. };
  1144. // Plugin definition
  1145. $.fn.bootstrapValidator = function(option) {
  1146. var params = arguments;
  1147. return this.each(function() {
  1148. var $this = $(this),
  1149. data = $this.data('bootstrapValidator'),
  1150. options = 'object' === typeof option && option;
  1151. if (!data) {
  1152. data = new BootstrapValidator(this, options);
  1153. $this.data('bootstrapValidator', data);
  1154. }
  1155. // Allow to call plugin method
  1156. if ('string' === typeof option) {
  1157. data[option].apply(data, Array.prototype.slice.call(params, 1));
  1158. }
  1159. });
  1160. };
  1161. // The default options
  1162. $.fn.bootstrapValidator.DEFAULT_OPTIONS = {
  1163. // The form CSS class
  1164. elementClass: 'bv-form',
  1165. // Default invalid message
  1166. message: 'This value is not valid',
  1167. // The CSS selector for indicating the element consists the field
  1168. // By default, each field is placed inside the <div class="form-group"></div>
  1169. // You should adjust this option if your form group consists of many fields which not all of them need to be validated
  1170. group: '.form-group',
  1171. //The error messages container. It can be:
  1172. // - 'tooltip' if you want to use Bootstrap tooltip to show error messages
  1173. // - 'popover' if you want to use Bootstrap popover to show error messages
  1174. // - a CSS selector indicating the container
  1175. // In the first two cases, since the tooltip/popover should be small enough, the plugin only shows only one error message
  1176. // You also can define the message container for particular field
  1177. container: null,
  1178. // The field will not be live validated if its length is less than this number of characters
  1179. threshold: null,
  1180. // Indicate fields which won't be validated
  1181. // By default, the plugin will not validate the following kind of fields:
  1182. // - disabled
  1183. // - hidden
  1184. // - invisible
  1185. //
  1186. // The setting consists of jQuery filters. Accept 3 formats:
  1187. // - A string. Use a comma to separate filter
  1188. // - An array. Each element is a filter
  1189. // - An array. Each element can be a callback function
  1190. // function($field, validator) {
  1191. // $field is jQuery object representing the field element
  1192. // validator is the BootstrapValidator instance
  1193. // return true or false;
  1194. // }
  1195. //
  1196. // The 3 following settings are equivalent:
  1197. //
  1198. // 1) ':disabled, :hidden, :not(:visible)'
  1199. // 2) [':disabled', ':hidden', ':not(:visible)']
  1200. // 3) [':disabled', ':hidden', function($field) {
  1201. // return !$field.is(':visible');
  1202. // }]
  1203. excluded: [':disabled', ':hidden', ':not(:visible)'],
  1204. // Shows ok/error/loading icons based on the field validity.
  1205. // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
  1206. // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
  1207. // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
  1208. //
  1209. // Examples:
  1210. // - Use Glyphicons icons:
  1211. // feedbackIcons: {
  1212. // valid: 'glyphicon glyphicon-ok',
  1213. // invalid: 'glyphicon glyphicon-remove',
  1214. // validating: 'glyphicon glyphicon-refresh'
  1215. // }
  1216. // - Use FontAwesome icons:
  1217. // feedbackIcons: {
  1218. // valid: 'fa fa-check',
  1219. // invalid: 'fa fa-times',
  1220. // validating: 'fa fa-refresh'
  1221. // }
  1222. feedbackIcons: {
  1223. valid: null,
  1224. invalid: null,
  1225. validating: null
  1226. },
  1227. // The submit buttons selector
  1228. // These buttons will be disabled to prevent the valid form from multiple submissions
  1229. submitButtons: '[type="submit"]',
  1230. // The custom submit handler
  1231. // It will prevent the form from the default submission
  1232. //
  1233. // submitHandler: function(validator, form) {
  1234. // - validator is the BootstrapValidator instance
  1235. // - form is the jQuery object presenting the current form
  1236. // }
  1237. submitHandler: null,
  1238. // Live validating option
  1239. // Can be one of 3 values:
  1240. // - enabled: The plugin validates fields as soon as they are changed
  1241. // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
  1242. // - submitted: The live validating is enabled after the form is submitted
  1243. live: 'enabled',
  1244. // Map the field name with validator rules
  1245. fields: null
  1246. };
  1247. // Available validators
  1248. $.fn.bootstrapValidator.validators = {};
  1249. // i18n
  1250. $.fn.bootstrapValidator.i18n = {};
  1251. $.fn.bootstrapValidator.Constructor = BootstrapValidator;
  1252. // Helper methods, which can be used in validator class
  1253. $.fn.bootstrapValidator.helpers = {
  1254. /**
  1255. * Format a string
  1256. * It's used to format the error message
  1257. * format('The field must between %s and %s', [10, 20]) = 'The field must between 10 and 20'
  1258. *
  1259. * @param {String} message
  1260. * @param {Array} parameters
  1261. * @returns {String}
  1262. */
  1263. format: function(message, parameters) {
  1264. if (!$.isArray(parameters)) {
  1265. parameters = [parameters];
  1266. }
  1267. for (var i in parameters) {
  1268. message = message.replace('%s', parameters[i]);
  1269. }
  1270. return message;
  1271. },
  1272. /**
  1273. * Validate a date
  1274. *
  1275. * @param {Number} year The full year in 4 digits
  1276. * @param {Number} month The month number
  1277. * @param {Number} day The day number
  1278. * @param {Boolean} [notInFuture] If true, the date must not be in the future
  1279. * @returns {Boolean}
  1280. */
  1281. date: function(year, month, day, notInFuture) {
  1282. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  1283. return false;
  1284. }
  1285. if (year < 1000 || year > 9999 || month === 0 || month > 12) {
  1286. return false;
  1287. }
  1288. var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1289. // Update the number of days in Feb of leap year
  1290. if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
  1291. numDays[1] = 29;
  1292. }
  1293. // Check the day
  1294. if (day < 0 || day > numDays[month - 1]) {
  1295. return false;
  1296. }
  1297. if (notInFuture === true) {
  1298. var currentDate = new Date(),
  1299. currentYear = currentDate.getFullYear(),
  1300. currentMonth = currentDate.getMonth(),
  1301. currentDay = currentDate.getDate();
  1302. return (year < currentYear
  1303. || (year === currentYear && month - 1 < currentMonth)
  1304. || (year === currentYear && month - 1 === currentMonth && day < currentDay));
  1305. }
  1306. return true;
  1307. },
  1308. /**
  1309. * Implement Luhn validation algorithm
  1310. * Credit to https://gist.github.com/ShirtlessKirk/2134376
  1311. *
  1312. * @see http://en.wikipedia.org/wiki/Luhn
  1313. * @param {String} value
  1314. * @returns {Boolean}
  1315. */
  1316. luhn: function(value) {
  1317. var length = value.length,
  1318. mul = 0,
  1319. prodArr = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]],
  1320. sum = 0;
  1321. while (length--) {
  1322. sum += prodArr[mul][parseInt(value.charAt(length), 10)];
  1323. mul ^= 1;
  1324. }
  1325. return (sum % 10 === 0 && sum > 0);
  1326. },
  1327. /**
  1328. * Implement modulus 11, 10 (ISO 7064) algorithm
  1329. *
  1330. * @param {String} value
  1331. * @returns {Boolean}
  1332. */
  1333. mod11And10: function(value) {
  1334. var check = 5,
  1335. length = value.length;
  1336. for (var i = 0; i < length; i++) {
  1337. check = (((check || 10) * 2) % 11 + parseInt(value.charAt(i), 10)) % 10;
  1338. }
  1339. return (check === 1);
  1340. },
  1341. /**
  1342. * Implements Mod 37, 36 (ISO 7064) algorithm
  1343. * Usages:
  1344. * mod37And36('A12425GABC1234002M')
  1345. * mod37And36('002006673085', '0123456789')
  1346. *
  1347. * @param {String} value
  1348. * @param {String} [alphabet]
  1349. * @returns {Boolean}
  1350. */
  1351. mod37And36: function(value, alphabet) {
  1352. alphabet = alphabet || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1353. var modulus = alphabet.length,
  1354. length = value.length,
  1355. check = Math.floor(modulus / 2);
  1356. for (var i = 0; i < length; i++) {
  1357. check = (((check || modulus) * 2) % (modulus + 1) + alphabet.indexOf(value.charAt(i))) % modulus;
  1358. }
  1359. return (check === 1);
  1360. }
  1361. };
  1362. }(window.jQuery));
  1363. ;(function($) {
  1364. $.fn.bootstrapValidator.i18n.base64 = $.extend($.fn.bootstrapValidator.i18n.base64 || {}, {
  1365. 'default': 'Please enter a valid base 64 encoded'
  1366. });
  1367. $.fn.bootstrapValidator.validators.base64 = {
  1368. /**
  1369. * Return true if the input value is a base 64 encoded string.
  1370. *
  1371. * @param {BootstrapValidator} validator The validator plugin instance
  1372. * @param {jQuery} $field Field element
  1373. * @param {Object} options Can consist of the following keys:
  1374. * - message: The invalid message
  1375. * @returns {Boolean}
  1376. */
  1377. validate: function(validator, $field, options) {
  1378. var value = $field.val();
  1379. if (value === '') {
  1380. return true;
  1381. }
  1382. return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
  1383. }
  1384. };
  1385. }(window.jQuery));
  1386. ;(function($) {
  1387. $.fn.bootstrapValidator.i18n.between = $.extend($.fn.bootstrapValidator.i18n.between || {}, {
  1388. 'default': 'Please enter a value between %s and %s',
  1389. notInclusive: 'Please enter a value between %s and %s strictly',
  1390. getMessage: function(options) {
  1391. return (options.inclusive === true || options.inclusive === undefined)
  1392. ? $.fn.bootstrapValidator.helpers.format(this['default'], [options.min, options.max])
  1393. : $.fn.bootstrapValidator.helpers.format(this.notInclusive, [options.min, options.max]);
  1394. }
  1395. });
  1396. $.fn.bootstrapValidator.validators.between = {
  1397. html5Attributes: {
  1398. message: 'message',
  1399. min: 'min',
  1400. max: 'max',
  1401. inclusive: 'inclusive'
  1402. },
  1403. enableByHtml5: function($field) {
  1404. if ('range' === $field.attr('type')) {
  1405. return {
  1406. min: $field.attr('min'),
  1407. max: $field.attr('max')
  1408. };
  1409. }
  1410. return false;
  1411. },
  1412. /**
  1413. * Return true if the input value is between (strictly or not) two given numbers
  1414. *
  1415. * @param {BootstrapValidator} validator The validator plugin instance
  1416. * @param {jQuery} $field Field element
  1417. * @param {Object} options Can consist of the following keys:
  1418. * - min
  1419. * - max
  1420. * - inclusive [optional]: Can be true or false. Default is true
  1421. * - message: The invalid message
  1422. * @returns {Boolean}
  1423. */
  1424. validate: function(validator, $field, options) {
  1425. var value = $field.val();
  1426. if (value === '') {
  1427. return true;
  1428. }
  1429. value = parseFloat(value);
  1430. return (options.inclusive === true || options.inclusive === undefined)
  1431. ? (value >= options.min && value <= options.max)
  1432. : (value > options.min && value < options.max);
  1433. }
  1434. };
  1435. }(window.jQuery));
  1436. ;(function($) {
  1437. $.fn.bootstrapValidator.i18n.callback = $.extend($.fn.bootstrapValidator.i18n.callback || {}, {
  1438. 'default': 'Please enter a valid value'
  1439. });
  1440. $.fn.bootstrapValidator.validators.callback = {
  1441. /**
  1442. * Return result from the callback method
  1443. *
  1444. * @param {BootstrapValidator} validator The validator plugin instance
  1445. * @param {jQuery} $field Field element
  1446. * @param {Object} options Can consist of the following keys:
  1447. * - callback: The callback method that passes 2 parameters:
  1448. * callback: function(fieldValue, validator, $field) {
  1449. * // fieldValue is the value of field
  1450. * // validator is instance of BootstrapValidator
  1451. * // $field is the field element
  1452. * }
  1453. * - message: The invalid message
  1454. * @returns {Boolean|Deferred}
  1455. */
  1456. validate: function(validator, $field, options) {
  1457. var value = $field.val();
  1458. if (options.callback && 'function' === typeof options.callback) {
  1459. var dfd = new $.Deferred(),
  1460. response = options.callback.call(this, value, validator, $field);
  1461. dfd.resolve($field, 'callback', 'boolean' === typeof response ? response : response.valid, 'object' === typeof response && response.message ? response.message : null);
  1462. return dfd;
  1463. }
  1464. return true;
  1465. }
  1466. };
  1467. }(window.jQuery));
  1468. ;(function($) {
  1469. $.fn.bootstrapValidator.i18n.choice = $.extend($.fn.bootstrapValidator.i18n.choice || {}, {
  1470. 'default': 'Please enter a valid value',
  1471. less: 'Please choose %s options at minimum',
  1472. more: 'Please choose %s options at maximum',
  1473. between: 'Please choose %s - %s options',
  1474. getMessage: function(options) {
  1475. switch (true) {
  1476. case (!!options.min && !!options.max):
  1477. return $.fn.bootstrapValidator.helpers.format(this.between, [options.min, options.max]);
  1478. case (!!options.min):
  1479. return $.fn.bootstrapValidator.helpers.format(this.less, [options.min]);
  1480. case (!!options.max):
  1481. return $.fn.bootstrapValidator.helpers.format(this.more, [options.max]);
  1482. default:
  1483. return this['default'];
  1484. }
  1485. }
  1486. });
  1487. $.fn.bootstrapValidator.validators.choice = {
  1488. html5Attributes: {
  1489. message: 'message',
  1490. min: 'min',
  1491. max: 'max'
  1492. },
  1493. /**
  1494. * Check if the number of checked boxes are less or more than a given number
  1495. *
  1496. * @param {BootstrapValidator} validator The validator plugin instance
  1497. * @param {jQuery} $field Field element
  1498. * @param {Object} options Consists of following keys:
  1499. * - min
  1500. * - max
  1501. * At least one of two keys is required
  1502. * - message: The invalid message
  1503. * @returns {Boolean}
  1504. */
  1505. validate: function(validator, $field, options) {
  1506. var numChoices = $field.is('select')
  1507. ? validator.getFieldElements($field.attr('data-bv-field')).find('option').filter(':selected').length
  1508. : validator.getFieldElements($field.attr('data-bv-field')).filter(':checked').length;
  1509. if ((options.min && numChoices < options.min) || (options.max && numChoices > options.max)) {
  1510. return false;
  1511. }
  1512. return true;
  1513. }
  1514. };
  1515. }(window.jQuery));
  1516. ;(function($) {
  1517. $.fn.bootstrapValidator.i18n.creditCard = $.extend($.fn.bootstrapValidator.i18n.creditCard || {}, {
  1518. 'default': 'Please enter a valid credit card number'
  1519. });
  1520. $.fn.bootstrapValidator.validators.creditCard = {
  1521. /**
  1522. * Return true if the input value is valid credit card number
  1523. * Based on https://gist.github.com/DiegoSalazar/4075533
  1524. *
  1525. * @param {BootstrapValidator} validator The validator plugin instance
  1526. * @param {jQuery} $field Field element
  1527. * @param {Object} [options] Can consist of the following key:
  1528. * - message: The invalid message
  1529. * @returns {Boolean}
  1530. */
  1531. validate: function(validator, $field, options) {
  1532. var value = $field.val();
  1533. if (value === '') {
  1534. return true;
  1535. }
  1536. // Accept only digits, dashes or spaces
  1537. if (/[^0-9-\s]+/.test(value)) {
  1538. return false;
  1539. }
  1540. value = value.replace(/\D/g, '');
  1541. if (!$.fn.bootstrapValidator.helpers.luhn(value)) {
  1542. return false;
  1543. }
  1544. // Validate the card number based on prefix (IIN ranges) and length
  1545. var cards = {
  1546. AMERICAN_EXPRESS: {
  1547. length: [15],
  1548. prefix: ['34', '37']
  1549. },
  1550. DINERS_CLUB: {
  1551. length: [14],
  1552. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1553. },
  1554. DINERS_CLUB_US: {
  1555. length: [16],
  1556. prefix: ['54', '55']
  1557. },
  1558. DISCOVER: {
  1559. length: [16],
  1560. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1561. '62214', '62215', '62216', '62217', '62218', '62219',
  1562. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1563. '62290', '62291', '622920', '622921', '622922', '622923',
  1564. '622924', '622925', '644', '645', '646', '647', '648',
  1565. '649', '65']
  1566. },
  1567. JCB: {
  1568. length: [16],
  1569. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1570. },
  1571. LASER: {
  1572. length: [16, 17, 18, 19],
  1573. prefix: ['6304', '6706', '6771', '6709']
  1574. },
  1575. MAESTRO: {
  1576. length: [12, 13, 14, 15, 16, 17, 18, 19],
  1577. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  1578. },
  1579. MASTERCARD: {
  1580. length: [16],
  1581. prefix: ['51', '52', '53', '54', '55']
  1582. },
  1583. SOLO: {
  1584. length: [16, 18, 19],
  1585. prefix: ['6334', '6767']
  1586. },
  1587. UNIONPAY: {
  1588. length: [16, 17, 18, 19],
  1589. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  1590. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  1591. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  1592. '622920', '622921', '622922', '622923', '622924', '622925']
  1593. },
  1594. VISA: {
  1595. length: [16],
  1596. prefix: ['4']
  1597. }
  1598. };
  1599. var type, i;
  1600. for (type in cards) {
  1601. for (i in cards[type].prefix) {
  1602. if (value.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  1603. && $.inArray(value.length, cards[type].length) !== -1) // and length
  1604. {
  1605. return true;
  1606. }
  1607. }
  1608. }
  1609. return false;
  1610. }
  1611. };
  1612. }(window.jQuery));
  1613. ;(function($) {
  1614. $.fn.bootstrapValidator.i18n.cusip = $.extend($.fn.bootstrapValidator.i18n.cusip || {}, {
  1615. 'default': 'Please enter a valid CUSIP number'
  1616. });
  1617. $.fn.bootstrapValidator.validators.cusip = {
  1618. /**
  1619. * Validate a CUSIP
  1620. * Examples:
  1621. * - Valid: 037833100, 931142103, 14149YAR8, 126650BG6
  1622. * - Invalid: 31430F200, 022615AC2
  1623. *
  1624. * @see http://en.wikipedia.org/wiki/CUSIP
  1625. * @param {BootstrapValidator} validator The validator plugin instance
  1626. * @param {jQuery} $field Field element
  1627. * @param {Object} [options] Can consist of the following keys:
  1628. * - message: The invalid message
  1629. * @returns {Boolean}
  1630. */
  1631. validate: function(validator, $field, options) {
  1632. var value = $field.val();
  1633. if (value === '') {
  1634. return true;
  1635. }
  1636. value = value.toUpperCase();
  1637. if (!/^[0-9A-Z]{9}$/.test(value)) {
  1638. return false;
  1639. }
  1640. var converted = $.map(value.split(''), function(item) {
  1641. var code = item.charCodeAt(0);
  1642. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  1643. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  1644. ? (code - 'A'.charCodeAt(0) + 10)
  1645. : item;
  1646. }),
  1647. length = converted.length,
  1648. sum = 0;
  1649. for (var i = 0; i < length - 1; i++) {
  1650. var num = parseInt(converted[i], 10);
  1651. if (i % 2 !== 0) {
  1652. num *= 2;
  1653. }
  1654. if (num > 9) {
  1655. num -= 9;
  1656. }
  1657. sum += num;
  1658. }
  1659. sum = (10 - (sum % 10)) % 10;
  1660. return sum === converted[length - 1];
  1661. }
  1662. };
  1663. }(window.jQuery));
  1664. ;(function($) {
  1665. $.fn.bootstrapValidator.i18n.cvv = $.extend($.fn.bootstrapValidator.i18n.cvv || {}, {
  1666. 'default': 'Please enter a valid CVV number'
  1667. });
  1668. $.fn.bootstrapValidator.validators.cvv = {
  1669. html5Attributes: {
  1670. message: 'message',
  1671. ccfield: 'creditCardField'
  1672. },
  1673. /**
  1674. * Return true if the input value is a valid CVV number.
  1675. *
  1676. * @param {BootstrapValidator} validator The validator plugin instance
  1677. * @param {jQuery} $field Field element
  1678. * @param {Object} options Can consist of the following keys:
  1679. * - creditCardField: The credit card number field. It can be null
  1680. * - message: The invalid message
  1681. * @returns {Boolean}
  1682. */
  1683. validate: function(validator, $field, options) {
  1684. var value = $field.val();
  1685. if (value === '') {
  1686. return true;
  1687. }
  1688. if (!/^[0-9]{3,4}$/.test(value)) {
  1689. return false;
  1690. }
  1691. if (!options.creditCardField) {
  1692. return true;
  1693. }
  1694. // Get the credit card number
  1695. var creditCard = validator.getFieldElements(options.creditCardField).val();
  1696. if (creditCard === '') {
  1697. return true;
  1698. }
  1699. creditCard = creditCard.replace(/\D/g, '');
  1700. // Supported credit card types
  1701. var cards = {
  1702. AMERICAN_EXPRESS: {
  1703. length: [15],
  1704. prefix: ['34', '37']
  1705. },
  1706. DINERS_CLUB: {
  1707. length: [14],
  1708. prefix: ['300', '301', '302', '303', '304', '305', '36']
  1709. },
  1710. DINERS_CLUB_US: {
  1711. length: [16],
  1712. prefix: ['54', '55']
  1713. },
  1714. DISCOVER: {
  1715. length: [16],
  1716. prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
  1717. '62214', '62215', '62216', '62217', '62218', '62219',
  1718. '6222', '6223', '6224', '6225', '6226', '6227', '6228',
  1719. '62290', '62291', '622920', '622921', '622922', '622923',
  1720. '622924', '622925', '644', '645', '646', '647', '648',
  1721. '649', '65']
  1722. },
  1723. JCB: {
  1724. length: [16],
  1725. prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
  1726. },
  1727. LASER: {
  1728. length: [16, 17, 18, 19],
  1729. prefix: ['6304', '6706', '6771', '6709']
  1730. },
  1731. MAESTRO: {
  1732. length: [12, 13, 14, 15, 16, 17, 18, 19],
  1733. prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
  1734. },
  1735. MASTERCARD: {
  1736. length: [16],
  1737. prefix: ['51', '52', '53', '54', '55']
  1738. },
  1739. SOLO: {
  1740. length: [16, 18, 19],
  1741. prefix: ['6334', '6767']
  1742. },
  1743. UNIONPAY: {
  1744. length: [16, 17, 18, 19],
  1745. prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
  1746. '62215', '62216', '62217', '62218', '62219', '6222', '6223',
  1747. '6224', '6225', '6226', '6227', '6228', '62290', '62291',
  1748. '622920', '622921', '622922', '622923', '622924', '622925']
  1749. },
  1750. VISA: {
  1751. length: [16],
  1752. prefix: ['4']
  1753. }
  1754. };
  1755. var type, i, creditCardType = null;
  1756. for (type in cards) {
  1757. for (i in cards[type].prefix) {
  1758. if (creditCard.substr(0, cards[type].prefix[i].length) === cards[type].prefix[i] // Check the prefix
  1759. && $.inArray(creditCard.length, cards[type].length) !== -1) // and length
  1760. {
  1761. creditCardType = type;
  1762. break;
  1763. }
  1764. }
  1765. }
  1766. return (creditCardType === null)
  1767. ? false
  1768. : (('AMERICAN_EXPRESS' === creditCardType) ? (value.length === 4) : (value.length === 3));
  1769. }
  1770. };
  1771. }(window.jQuery));
  1772. ;(function($) {
  1773. $.fn.bootstrapValidator.i18n.date = $.extend($.fn.bootstrapValidator.i18n.date || {}, {
  1774. 'default': 'Please enter a valid date'
  1775. });
  1776. $.fn.bootstrapValidator.validators.date = {
  1777. html5Attributes: {
  1778. message: 'message',
  1779. format: 'format',
  1780. separator: 'separator'
  1781. },
  1782. /**
  1783. * Return true if the input value is valid date
  1784. *
  1785. * @param {BootstrapValidator} validator The validator plugin instance
  1786. * @param {jQuery} $field Field element
  1787. * @param {Object} options Can consist of the following keys:
  1788. * - message: The invalid message
  1789. * - separator: Use to separate the date, month, and year.
  1790. * By default, it is /
  1791. * - format: The date format. Default is MM/DD/YYYY
  1792. * The format can be:
  1793. *
  1794. * i) date: Consist of DD, MM, YYYY parts which are separated by the separator option
  1795. * ii) date and time:
  1796. * The time can consist of h, m, s parts which are separated by :
  1797. * ii) date, time and A (indicating AM or PM)
  1798. * @returns {Boolean}
  1799. */
  1800. validate: function(validator, $field, options) {
  1801. var value = $field.val();
  1802. if (value === '') {
  1803. return true;
  1804. }
  1805. options.format = options.format || 'MM/DD/YYYY';
  1806. var formats = options.format.split(' '),
  1807. dateFormat = formats[0],
  1808. timeFormat = (formats.length > 1) ? formats[1] : null,
  1809. amOrPm = (formats.length > 2) ? formats[2] : null,
  1810. sections = value.split(' '),
  1811. date = sections[0],
  1812. time = (sections.length > 1) ? sections[1] : null;
  1813. if (formats.length !== sections.length) {
  1814. return false;
  1815. }
  1816. // Determine the separator
  1817. var separator = options.separator;
  1818. if (!separator) {
  1819. separator = (date.indexOf('/') !== -1) ? '/' : ((date.indexOf('-') !== -1) ? '-' : null);
  1820. }
  1821. if (separator === null || date.indexOf(separator) === -1) {
  1822. return false;
  1823. }
  1824. // Determine the date
  1825. date = date.split(separator);
  1826. dateFormat = dateFormat.split(separator);
  1827. var year = date[$.inArray('YYYY', dateFormat)],
  1828. month = date[$.inArray('MM', dateFormat)],
  1829. day = date[$.inArray('DD', dateFormat)];
  1830. // Determine the time
  1831. var minutes = null, hours = null, seconds = null;
  1832. if (timeFormat) {
  1833. timeFormat = timeFormat.split(':');
  1834. time = time.split(':');
  1835. if (timeFormat.length !== time.length) {
  1836. return false;
  1837. }
  1838. hours = time.length > 0 ? time[0] : null;
  1839. minutes = time.length > 1 ? time[1] : null;
  1840. seconds = time.length > 2 ? time[2] : null;
  1841. // Validate seconds
  1842. if (seconds) {
  1843. seconds = parseInt(seconds, 10);
  1844. if (isNaN(seconds) || seconds < 0 || seconds > 60) {
  1845. return false;
  1846. }
  1847. }
  1848. // Validate hours
  1849. if (hours) {
  1850. hours = parseInt(hours, 10);
  1851. if (isNaN(hours) || hours < 0 || hours >= 24 || (amOrPm && hours > 12)) {
  1852. return false;
  1853. }
  1854. }
  1855. // Validate minutes
  1856. if (minutes) {
  1857. minutes = parseInt(minutes, 10);
  1858. if (isNaN(minutes) || minutes < 0 || minutes > 59) {
  1859. return false;
  1860. }
  1861. }
  1862. }
  1863. // Validate day, month, and year
  1864. day = parseInt(day, 10);
  1865. month = parseInt(month, 10);
  1866. year = parseInt(year, 10);
  1867. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  1868. }
  1869. };
  1870. }(window.jQuery));
  1871. ;(function($) {
  1872. $.fn.bootstrapValidator.i18n.different = $.extend($.fn.bootstrapValidator.i18n.different || {}, {
  1873. 'default': 'Please enter a different value'
  1874. });
  1875. $.fn.bootstrapValidator.validators.different = {
  1876. html5Attributes: {
  1877. message: 'message',
  1878. field: 'field'
  1879. },
  1880. /**
  1881. * Return true if the input value is different with given field's value
  1882. *
  1883. * @param {BootstrapValidator} validator The validator plugin instance
  1884. * @param {jQuery} $field Field element
  1885. * @param {Object} options Consists of the following key:
  1886. * - field: The name of field that will be used to compare with current one
  1887. * - message: The invalid message
  1888. * @returns {Boolean}
  1889. */
  1890. validate: function(validator, $field, options) {
  1891. var value = $field.val();
  1892. if (value === '') {
  1893. return true;
  1894. }
  1895. var compareWith = validator.getFieldElements(options.field);
  1896. if (compareWith === null) {
  1897. return true;
  1898. }
  1899. if (value !== compareWith.val()) {
  1900. validator.updateStatus(options.field, validator.STATUS_VALID, 'different');
  1901. return true;
  1902. } else {
  1903. return false;
  1904. }
  1905. }
  1906. };
  1907. }(window.jQuery));
  1908. ;(function($) {
  1909. $.fn.bootstrapValidator.i18n.digits = $.extend($.fn.bootstrapValidator.i18n.digits || {}, {
  1910. 'default': 'Please enter only digits'
  1911. });
  1912. $.fn.bootstrapValidator.validators.digits = {
  1913. /**
  1914. * Return true if the input value contains digits only
  1915. *
  1916. * @param {BootstrapValidator} validator Validate plugin instance
  1917. * @param {jQuery} $field Field element
  1918. * @param {Object} [options]
  1919. * @returns {Boolean}
  1920. */
  1921. validate: function(validator, $field, options) {
  1922. var value = $field.val();
  1923. if (value === '') {
  1924. return true;
  1925. }
  1926. return /^\d+$/.test(value);
  1927. }
  1928. };
  1929. }(window.jQuery));
  1930. ;(function($) {
  1931. $.fn.bootstrapValidator.i18n.ean = $.extend($.fn.bootstrapValidator.i18n.ean || {}, {
  1932. 'default': 'Please enter a valid EAN number'
  1933. });
  1934. $.fn.bootstrapValidator.validators.ean = {
  1935. /**
  1936. * Validate EAN (International Article Number)
  1937. * Examples:
  1938. * - Valid: 73513537, 9780471117094, 4006381333931
  1939. * - Invalid: 73513536
  1940. *
  1941. * @see http://en.wikipedia.org/wiki/European_Article_Number
  1942. * @param {BootstrapValidator} validator The validator plugin instance
  1943. * @param {jQuery} $field Field element
  1944. * @param {Object} options Can consist of the following keys:
  1945. * - message: The invalid message
  1946. * @returns {Boolean}
  1947. */
  1948. validate: function(validator, $field, options) {
  1949. var value = $field.val();
  1950. if (value === '') {
  1951. return true;
  1952. }
  1953. if (!/^(\d{8}|\d{12}|\d{13})$/.test(value)) {
  1954. return false;
  1955. }
  1956. var length = value.length,
  1957. sum = 0,
  1958. weight = (length === 8) ? [3, 1] : [1, 3];
  1959. for (var i = 0; i < length - 1; i++) {
  1960. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  1961. }
  1962. sum = (10 - sum % 10) % 10;
  1963. return (sum + '' === value.charAt(length - 1));
  1964. }
  1965. };
  1966. }(window.jQuery));
  1967. ;(function($) {
  1968. $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
  1969. 'default': 'Please enter a valid email address'
  1970. });
  1971. $.fn.bootstrapValidator.validators.emailAddress = {
  1972. enableByHtml5: function($field) {
  1973. return ('email' === $field.attr('type'));
  1974. },
  1975. /**
  1976. * Return true if and only if the input value is a valid email address
  1977. *
  1978. * @param {BootstrapValidator} validator Validate plugin instance
  1979. * @param {jQuery} $field Field element
  1980. * @param {Object} [options]
  1981. * @returns {Boolean}
  1982. */
  1983. validate: function(validator, $field, options) {
  1984. var value = $field.val();
  1985. if (value === '') {
  1986. return true;
  1987. }
  1988. // Email address regular expression
  1989. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  1990. var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  1991. return emailRegExp.test(value);
  1992. }
  1993. };
  1994. }(window.jQuery));
  1995. ;(function($) {
  1996. $.fn.bootstrapValidator.i18n.file = $.extend($.fn.bootstrapValidator.i18n.file || {}, {
  1997. 'default': 'Please choose a valid file'
  1998. });
  1999. $.fn.bootstrapValidator.validators.file = {
  2000. html5Attributes: {
  2001. extension: 'extension',
  2002. maxsize: 'maxSize',
  2003. message: 'message',
  2004. type: 'type'
  2005. },
  2006. /**
  2007. * Validate upload file. Use HTML 5 API if the browser supports
  2008. *
  2009. * @param {BootstrapValidator} validator The validator plugin instance
  2010. * @param {jQuery} $field Field element
  2011. * @param {Object} options Can consist of the following keys:
  2012. * - extension: The allowed extensions, separated by a comma
  2013. * - maxSize: The maximum size in bytes
  2014. * - message: The invalid message
  2015. * - type: The allowed MIME type, separated by a comma
  2016. * @returns {Boolean}
  2017. */
  2018. validate: function(validator, $field, options) {
  2019. var value = $field.val();
  2020. if (value === '') {
  2021. return true;
  2022. }
  2023. var ext,
  2024. extensions = options.extension ? options.extension.toLowerCase().split(',') : null,
  2025. types = options.type ? options.type.toLowerCase().split(',') : null,
  2026. html5 = (window.File && window.FileList && window.FileReader);
  2027. if (html5) {
  2028. // Get FileList instance
  2029. var files = $field.get(0).files,
  2030. total = files.length;
  2031. for (var i = 0; i < total; i++) {
  2032. // Check file size
  2033. if (options.maxSize && files[i].size > parseInt(options.maxSize, 10)) {
  2034. return false;
  2035. }
  2036. // Check file extension
  2037. ext = files[i].name.substr(files[i].name.lastIndexOf('.') + 1);
  2038. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2039. return false;
  2040. }
  2041. // Check file type
  2042. if (types && $.inArray(files[i].type.toLowerCase(), types) === -1) {
  2043. return false;
  2044. }
  2045. }
  2046. } else {
  2047. // Check file extension
  2048. ext = value.substr(value.lastIndexOf('.') + 1);
  2049. if (extensions && $.inArray(ext.toLowerCase(), extensions) === -1) {
  2050. return false;
  2051. }
  2052. }
  2053. return true;
  2054. }
  2055. };
  2056. }(window.jQuery));
  2057. ;(function($) {
  2058. $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
  2059. 'default': 'Please enter a value greater than or equal to %s',
  2060. notInclusive: 'Please enter a value greater than %s',
  2061. getMessage: function(options) {
  2062. return (options.inclusive === true || options.inclusive === undefined)
  2063. ? $.fn.bootstrapValidator.helpers.format(this['default'], options.value)
  2064. : $.fn.bootstrapValidator.helpers.format(this.notInclusive, options.value);
  2065. }
  2066. });
  2067. $.fn.bootstrapValidator.validators.greaterThan = {
  2068. html5Attributes: {
  2069. message: 'message',
  2070. value: 'value',
  2071. inclusive: 'inclusive'
  2072. },
  2073. enableByHtml5: function($field) {
  2074. var min = $field.attr('min');
  2075. if (min) {
  2076. return {
  2077. value: min
  2078. };
  2079. }
  2080. return false;
  2081. },
  2082. /**
  2083. * Return true if the input value is greater than or equals to given number
  2084. *
  2085. * @param {BootstrapValidator} validator Validate plugin instance
  2086. * @param {jQuery} $field Field element
  2087. * @param {Object} options Can consist of the following keys:
  2088. * - value: The number used to compare to
  2089. * - inclusive [optional]: Can be true or false. Default is true
  2090. * - message: The invalid message
  2091. * @returns {Boolean}
  2092. */
  2093. validate: function(validator, $field, options) {
  2094. var value = $field.val();
  2095. if (value === '') {
  2096. return true;
  2097. }
  2098. value = parseFloat(value);
  2099. return (options.inclusive === true || options.inclusive === undefined) ? (value >= options.value) : (value > options.value);
  2100. }
  2101. };
  2102. }(window.jQuery));
  2103. ;(function($) {
  2104. $.fn.bootstrapValidator.i18n.grid = $.extend($.fn.bootstrapValidator.i18n.grid || {}, {
  2105. 'default': 'Please enter a valid GRId number'
  2106. });
  2107. $.fn.bootstrapValidator.validators.grid = {
  2108. /**
  2109. * Validate GRId (Global Release Identifier)
  2110. * Examples:
  2111. * - Valid: A12425GABC1234002M, A1-2425G-ABC1234002-M, A1 2425G ABC1234002 M, Grid:A1-2425G-ABC1234002-M
  2112. * - Invalid: A1-2425G-ABC1234002-Q
  2113. *
  2114. * @see http://en.wikipedia.org/wiki/Global_Release_Identifier
  2115. * @param {BootstrapValidator} validator The validator plugin instance
  2116. * @param {jQuery} $field Field element
  2117. * @param {Object} options Can consist of the following keys:
  2118. * - message: The invalid message
  2119. * @returns {Boolean}
  2120. */
  2121. validate: function(validator, $field, options) {
  2122. var value = $field.val();
  2123. if (value === '') {
  2124. return true;
  2125. }
  2126. value = value.toUpperCase();
  2127. if (!/^[GRID:]*([0-9A-Z]{2})[-\s]*([0-9A-Z]{5})[-\s]*([0-9A-Z]{10})[-\s]*([0-9A-Z]{1})$/g.test(value)) {
  2128. return false;
  2129. }
  2130. value = value.replace(/\s/g, '').replace(/-/g, '');
  2131. if ('GRID:' === value.substr(0, 5)) {
  2132. value = value.substr(5);
  2133. }
  2134. return $.fn.bootstrapValidator.helpers.mod37And36(value);
  2135. }
  2136. };
  2137. }(window.jQuery));
  2138. ;(function($) {
  2139. $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
  2140. 'default': 'Please enter a valid hexadecimal number'
  2141. });
  2142. $.fn.bootstrapValidator.validators.hex = {
  2143. /**
  2144. * Return true if and only if the input value is a valid hexadecimal number
  2145. *
  2146. * @param {BootstrapValidator} validator The validator plugin instance
  2147. * @param {jQuery} $field Field element
  2148. * @param {Object} options Consist of key:
  2149. * - message: The invalid message
  2150. * @returns {Boolean}
  2151. */
  2152. validate: function(validator, $field, options) {
  2153. var value = $field.val();
  2154. if (value === '') {
  2155. return true;
  2156. }
  2157. return /^[0-9a-fA-F]+$/.test(value);
  2158. }
  2159. };
  2160. }(window.jQuery));
  2161. ;(function($) {
  2162. $.fn.bootstrapValidator.i18n.hexColor = $.extend($.fn.bootstrapValidator.i18n.hexColor || {}, {
  2163. 'default': 'Please enter a valid hex color'
  2164. });
  2165. $.fn.bootstrapValidator.validators.hexColor = {
  2166. enableByHtml5: function($field) {
  2167. return ('color' === $field.attr('type'));
  2168. },
  2169. /**
  2170. * Return true if the input value is a valid hex color
  2171. *
  2172. * @param {BootstrapValidator} validator The validator plugin instance
  2173. * @param {jQuery} $field Field element
  2174. * @param {Object} options Can consist of the following keys:
  2175. * - message: The invalid message
  2176. * @returns {Boolean}
  2177. */
  2178. validate: function(validator, $field, options) {
  2179. var value = $field.val();
  2180. if (value === '') {
  2181. return true;
  2182. }
  2183. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  2184. }
  2185. };
  2186. }(window.jQuery));
  2187. ;(function($) {
  2188. $.fn.bootstrapValidator.i18n.iban = $.extend($.fn.bootstrapValidator.i18n.iban || {}, {
  2189. 'default': 'Please enter a valid IBAN number',
  2190. countryNotSupported: 'The country code %s is not supported',
  2191. country: 'Please enter a valid IBAN number in %s',
  2192. countries: {
  2193. AD: 'Andorra',
  2194. AE: 'United Arab Emirates',
  2195. AL: 'Albania',
  2196. AO: 'Angola',
  2197. AT: 'Austria',
  2198. AZ: 'Azerbaijan',
  2199. BA: 'Bosnia and Herzegovina',
  2200. BE: 'Belgium',
  2201. BF: 'Burkina Faso',
  2202. BG: 'Bulgaria',
  2203. BH: 'Bahrain',
  2204. BI: 'Burundi',
  2205. BJ: 'Benin',
  2206. BR: 'Brazil',
  2207. CH: 'Switzerland',
  2208. CI: 'Ivory Coast',
  2209. CM: 'Cameroon',
  2210. CR: 'Costa Rica',
  2211. CV: 'Cape Verde',
  2212. CY: 'Cyprus',
  2213. CZ: 'Czech Republic',
  2214. DE: 'Germany',
  2215. DK: 'Denmark',
  2216. DO: 'Dominican Republic',
  2217. DZ: 'Algeria',
  2218. EE: 'Estonia',
  2219. ES: 'Spain',
  2220. FI: 'Finland',
  2221. FO: 'Faroe Islands',
  2222. FR: 'France',
  2223. GB: 'United Kingdom',
  2224. GE: 'Georgia',
  2225. GI: 'Gibraltar',
  2226. GL: 'Greenland',
  2227. GR: 'Greece',
  2228. GT: 'Guatemala',
  2229. HR: 'Croatia',
  2230. HU: 'Hungary',
  2231. IE: 'Ireland',
  2232. IL: 'Israel',
  2233. IR: 'Iran',
  2234. IS: 'Iceland',
  2235. IT: 'Italy',
  2236. JO: 'Jordan',
  2237. KW: 'Kuwait',
  2238. KZ: 'Kazakhstan',
  2239. LB: 'Lebanon',
  2240. LI: 'Liechtenstein',
  2241. LT: 'Lithuania',
  2242. LU: 'Luxembourg',
  2243. LV: 'Latvia',
  2244. MC: 'Monaco',
  2245. MD: 'Moldova',
  2246. ME: 'Montenegro',
  2247. MG: 'Madagascar',
  2248. MK: 'Macedonia',
  2249. ML: 'Mali',
  2250. MR: 'Mauritania',
  2251. MT: 'Malta',
  2252. MU: 'Mauritius',
  2253. MZ: 'Mozambique',
  2254. NL: 'Netherlands',
  2255. NO: 'Norway',
  2256. PK: 'Pakistan',
  2257. PL: 'Poland',
  2258. PS: 'Palestinian',
  2259. PT: 'Portugal',
  2260. QA: 'Qatar',
  2261. RO: 'Romania',
  2262. RS: 'Serbia',
  2263. SA: 'Saudi Arabia',
  2264. SE: 'Sweden',
  2265. SI: 'Slovenia',
  2266. SK: 'Slovakia',
  2267. SM: 'San Marino',
  2268. SN: 'Senegal',
  2269. TN: 'Tunisia',
  2270. TR: 'Turkey',
  2271. VG: 'Virgin Islands, British'
  2272. },
  2273. getMessage: function(options) {
  2274. if (options.country) {
  2275. var country = options.country.toUpperCase();
  2276. if (!$.fn.bootstrapValidator.validators.iban.REGEX[country]) {
  2277. return $.fn.bootstrapValidator.helpers.format(this.countryNotSupported, options.country);
  2278. }
  2279. if (this.countries[country]) {
  2280. return $.fn.bootstrapValidator.helpers.format(this.country, this.countries[country]);
  2281. }
  2282. }
  2283. return this['default'];
  2284. }
  2285. });
  2286. $.fn.bootstrapValidator.validators.iban = {
  2287. html5Attributes: {
  2288. message: 'message',
  2289. country: 'country'
  2290. },
  2291. // http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
  2292. // http://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country
  2293. REGEX: {
  2294. 'AD': 'AD[0-9]{2}[0-9]{4}[0-9]{4}[A-Z0-9]{12}', // Andorra
  2295. 'AE': 'AE[0-9]{2}[0-9]{3}[0-9]{16}', // United Arab Emirates
  2296. 'AL': 'AL[0-9]{2}[0-9]{8}[A-Z0-9]{16}', // Albania
  2297. 'AO': 'AO[0-9]{2}[0-9]{21}', // Angola
  2298. 'AT': 'AT[0-9]{2}[0-9]{5}[0-9]{11}', // Austria
  2299. 'AZ': 'AZ[0-9]{2}[A-Z]{4}[A-Z0-9]{20}', // Azerbaijan
  2300. 'BA': 'BA[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{8}[0-9]{2}', // Bosnia and Herzegovina
  2301. 'BE': 'BE[0-9]{2}[0-9]{3}[0-9]{7}[0-9]{2}', // Belgium
  2302. 'BF': 'BF[0-9]{2}[0-9]{23}', // Burkina Faso
  2303. 'BG': 'BG[0-9]{2}[A-Z]{4}[0-9]{4}[0-9]{2}[A-Z0-9]{8}', // Bulgaria
  2304. 'BH': 'BH[0-9]{2}[A-Z]{4}[A-Z0-9]{14}', // Bahrain
  2305. 'BI': 'BI[0-9]{2}[0-9]{12}', // Burundi
  2306. 'BJ': 'BJ[0-9]{2}[A-Z]{1}[0-9]{23}', // Benin
  2307. 'BR': 'BR[0-9]{2}[0-9]{8}[0-9]{5}[0-9]{10}[A-Z][A-Z0-9]', // Brazil
  2308. 'CH': 'CH[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Switzerland
  2309. 'CI': 'CI[0-9]{2}[A-Z]{1}[0-9]{23}', // Ivory Coast
  2310. 'CM': 'CM[0-9]{2}[0-9]{23}', // Cameroon
  2311. 'CR': 'CR[0-9]{2}[0-9]{3}[0-9]{14}', // Costa Rica
  2312. 'CV': 'CV[0-9]{2}[0-9]{21}', // Cape Verde
  2313. 'CY': 'CY[0-9]{2}[0-9]{3}[0-9]{5}[A-Z0-9]{16}', // Cyprus
  2314. 'CZ': 'CZ[0-9]{2}[0-9]{20}', // Czech Republic
  2315. 'DE': 'DE[0-9]{2}[0-9]{8}[0-9]{10}', // Germany
  2316. 'DK': 'DK[0-9]{2}[0-9]{14}', // Denmark
  2317. 'DO': 'DO[0-9]{2}[A-Z0-9]{4}[0-9]{20}', // Dominican Republic
  2318. 'DZ': 'DZ[0-9]{2}[0-9]{20}', // Algeria
  2319. 'EE': 'EE[0-9]{2}[0-9]{2}[0-9]{2}[0-9]{11}[0-9]{1}', // Estonia
  2320. 'ES': 'ES[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{1}[0-9]{1}[0-9]{10}', // Spain
  2321. 'FI': 'FI[0-9]{2}[0-9]{6}[0-9]{7}[0-9]{1}', // Finland
  2322. 'FO': 'FO[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Faroe Islands
  2323. 'FR': 'FR[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // France
  2324. 'GB': 'GB[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // United Kingdom
  2325. 'GE': 'GE[0-9]{2}[A-Z]{2}[0-9]{16}', // Georgia
  2326. 'GI': 'GI[0-9]{2}[A-Z]{4}[A-Z0-9]{15}', // Gibraltar
  2327. 'GL': 'GL[0-9]{2}[0-9]{4}[0-9]{9}[0-9]{1}', // Greenland[
  2328. 'GR': 'GR[0-9]{2}[0-9]{3}[0-9]{4}[A-Z0-9]{16}', // Greece
  2329. 'GT': 'GT[0-9]{2}[A-Z0-9]{4}[A-Z0-9]{20}', // Guatemala
  2330. 'HR': 'HR[0-9]{2}[0-9]{7}[0-9]{10}', // Croatia
  2331. 'HU': 'HU[0-9]{2}[0-9]{3}[0-9]{4}[0-9]{1}[0-9]{15}[0-9]{1}', // Hungary
  2332. 'IE': 'IE[0-9]{2}[A-Z]{4}[0-9]{6}[0-9]{8}', // Ireland
  2333. 'IL': 'IL[0-9]{2}[0-9]{3}[0-9]{3}[0-9]{13}', // Israel
  2334. 'IR': 'IR[0-9]{2}[0-9]{22}', // Iran
  2335. 'IS': 'IS[0-9]{2}[0-9]{4}[0-9]{2}[0-9]{6}[0-9]{10}', // Iceland
  2336. 'IT': 'IT[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // Italy
  2337. 'JO': 'JO[0-9]{2}[A-Z]{4}[0-9]{4}[0]{8}[A-Z0-9]{10}', // Jordan
  2338. 'KW': 'KW[0-9]{2}[A-Z]{4}[0-9]{22}', // Kuwait
  2339. 'KZ': 'KZ[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Kazakhstan
  2340. 'LB': 'LB[0-9]{2}[0-9]{4}[A-Z0-9]{20}', // Lebanon
  2341. 'LI': 'LI[0-9]{2}[0-9]{5}[A-Z0-9]{12}', // Liechtenstein
  2342. 'LT': 'LT[0-9]{2}[0-9]{5}[0-9]{11}', // Lithuania
  2343. 'LU': 'LU[0-9]{2}[0-9]{3}[A-Z0-9]{13}', // Luxembourg
  2344. 'LV': 'LV[0-9]{2}[A-Z]{4}[A-Z0-9]{13}', // Latvia
  2345. 'MC': 'MC[0-9]{2}[0-9]{5}[0-9]{5}[A-Z0-9]{11}[0-9]{2}', // Monaco
  2346. 'MD': 'MD[0-9]{2}[A-Z0-9]{20}', // Moldova
  2347. 'ME': 'ME[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Montenegro
  2348. 'MG': 'MG[0-9]{2}[0-9]{23}', // Madagascar
  2349. 'MK': 'MK[0-9]{2}[0-9]{3}[A-Z0-9]{10}[0-9]{2}', // Macedonia
  2350. 'ML': 'ML[0-9]{2}[A-Z]{1}[0-9]{23}', // Mali
  2351. 'MR': 'MR13[0-9]{5}[0-9]{5}[0-9]{11}[0-9]{2}', // Mauritania
  2352. 'MT': 'MT[0-9]{2}[A-Z]{4}[0-9]{5}[A-Z0-9]{18}', // Malta
  2353. 'MU': 'MU[0-9]{2}[A-Z]{4}[0-9]{2}[0-9]{2}[0-9]{12}[0-9]{3}[A-Z]{3}',// Mauritius
  2354. 'MZ': 'MZ[0-9]{2}[0-9]{21}', // Mozambique
  2355. 'NL': 'NL[0-9]{2}[A-Z]{4}[0-9]{10}', // Netherlands
  2356. 'NO': 'NO[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{1}', // Norway
  2357. 'PK': 'PK[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Pakistan
  2358. 'PL': 'PL[0-9]{2}[0-9]{8}[0-9]{16}', // Poland
  2359. 'PS': 'PS[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Palestinian
  2360. 'PT': 'PT[0-9]{2}[0-9]{4}[0-9]{4}[0-9]{11}[0-9]{2}', // Portugal
  2361. 'QA': 'QA[0-9]{2}[A-Z]{4}[A-Z0-9]{21}', // Qatar
  2362. 'RO': 'RO[0-9]{2}[A-Z]{4}[A-Z0-9]{16}', // Romania
  2363. 'RS': 'RS[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Serbia
  2364. 'SA': 'SA[0-9]{2}[0-9]{2}[A-Z0-9]{18}', // Saudi Arabia
  2365. 'SE': 'SE[0-9]{2}[0-9]{3}[0-9]{16}[0-9]{1}', // Sweden
  2366. 'SI': 'SI[0-9]{2}[0-9]{5}[0-9]{8}[0-9]{2}', // Slovenia
  2367. 'SK': 'SK[0-9]{2}[0-9]{4}[0-9]{6}[0-9]{10}', // Slovakia
  2368. 'SM': 'SM[0-9]{2}[A-Z]{1}[0-9]{5}[0-9]{5}[A-Z0-9]{12}', // San Marino
  2369. 'SN': 'SN[0-9]{2}[A-Z]{1}[0-9]{23}', // Senegal
  2370. 'TN': 'TN59[0-9]{2}[0-9]{3}[0-9]{13}[0-9]{2}', // Tunisia
  2371. 'TR': 'TR[0-9]{2}[0-9]{5}[A-Z0-9]{1}[A-Z0-9]{16}', // Turkey
  2372. 'VG': 'VG[0-9]{2}[A-Z]{4}[0-9]{16}' // Virgin Islands, British
  2373. },
  2374. /**
  2375. * Validate an International Bank Account Number (IBAN)
  2376. * To test it, take the sample IBAN from
  2377. * http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
  2378. *
  2379. * @param {BootstrapValidator} validator The validator plugin instance
  2380. * @param {jQuery} $field Field element
  2381. * @param {Object} options Can consist of the following keys:
  2382. * - message: The invalid message
  2383. * - country: The ISO 3166-1 country code
  2384. * @returns {Boolean}
  2385. */
  2386. validate: function(validator, $field, options) {
  2387. var value = $field.val();
  2388. if (value === '') {
  2389. return true;
  2390. }
  2391. value = value.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
  2392. var country = options.country || value.substr(0, 2);
  2393. if (!this.REGEX[country]) {
  2394. return false;
  2395. }
  2396. if (!(new RegExp('^' + this.REGEX[country] + '$')).test(value)) {
  2397. return false;
  2398. }
  2399. value = value.substr(4) + value.substr(0, 4);
  2400. value = $.map(value.split(''), function(n) {
  2401. var code = n.charCodeAt(0);
  2402. return (code >= 'A'.charCodeAt(0) && code <= 'Z'.charCodeAt(0))
  2403. // Replace A, B, C, ..., Z with 10, 11, ..., 35
  2404. ? (code - 'A'.charCodeAt(0) + 10)
  2405. : n;
  2406. });
  2407. value = value.join('');
  2408. var temp = parseInt(value.substr(0, 1), 10),
  2409. length = value.length;
  2410. for (var i = 1; i < length; ++i) {
  2411. temp = (temp * 10 + parseInt(value.substr(i, 1), 10)) % 97;
  2412. }
  2413. return (temp === 1);
  2414. }
  2415. };
  2416. }(window.jQuery));
  2417. ;(function($) {
  2418. $.fn.bootstrapValidator.i18n.id = $.extend($.fn.bootstrapValidator.i18n.id || {}, {
  2419. 'default': 'Please enter a valid identification number',
  2420. countryNotSupported: 'The country code %s is not supported',
  2421. country: 'Please enter a valid %s identification number',
  2422. countries: {
  2423. BA: 'Bosnia and Herzegovina',
  2424. BG: 'Bulgarian',
  2425. BR: 'Brazilian',
  2426. CH: 'Swiss',
  2427. CL: 'Chilean',
  2428. CZ: 'Czech',
  2429. DK: 'Danish',
  2430. EE: 'Estonian',
  2431. ES: 'Spanish',
  2432. FI: 'Finnish',
  2433. HR: 'Croatian',
  2434. IE: 'Irish',
  2435. IS: 'Iceland',
  2436. LT: 'Lithuanian',
  2437. LV: 'Latvian',
  2438. ME: 'Montenegro',
  2439. MK: 'Macedonian',
  2440. NL: 'Dutch',
  2441. RO: 'Romanian',
  2442. RS: 'Serbian',
  2443. SE: 'Swedish',
  2444. SI: 'Slovenian',
  2445. SK: 'Slovak',
  2446. SM: 'San Marino',
  2447. ZA: 'South African'
  2448. },
  2449. getMessage: function(options) {
  2450. if (options.country) {
  2451. var country = options.country.toLowerCase(),
  2452. method = ['_', country].join('');
  2453. if ($.fn.bootstrapValidator.validators.id[method] === undefined) {
  2454. return $.fn.bootstrapValidator.helpers.format(this.countryNotSupported, country);
  2455. }
  2456. country = country.toUpperCase();
  2457. if (this.countries[country]) {
  2458. return $.fn.bootstrapValidator.helpers.format(this.country, this.countries[country]);
  2459. }
  2460. }
  2461. return this['default'];
  2462. }
  2463. });
  2464. $.fn.bootstrapValidator.validators.id = {
  2465. html5Attributes: {
  2466. message: 'message',
  2467. country: 'country'
  2468. },
  2469. /**
  2470. * Validate identification number in different countries
  2471. *
  2472. * @see http://en.wikipedia.org/wiki/National_identification_number
  2473. * @param {BootstrapValidator} validator The validator plugin instance
  2474. * @param {jQuery} $field Field element
  2475. * @param {Object} options Consist of key:
  2476. * - message: The invalid message
  2477. * - country: The ISO 3166-1 country code
  2478. * @returns {Boolean}
  2479. */
  2480. validate: function(validator, $field, options) {
  2481. var value = $field.val();
  2482. if (value === '') {
  2483. return true;
  2484. }
  2485. var country = options.country || value.substr(0, 2),
  2486. method = ['_', country.toLowerCase()].join('');
  2487. if (this[method] && 'function' === typeof this[method]) {
  2488. return this[method](value);
  2489. }
  2490. return false;
  2491. },
  2492. /**
  2493. * Validate Unique Master Citizen Number which uses in
  2494. * - Bosnia and Herzegovina (country code: BA)
  2495. * - Macedonia (MK)
  2496. * - Montenegro (ME)
  2497. * - Serbia (RS)
  2498. * - Slovenia (SI)
  2499. *
  2500. * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
  2501. * @param {String} value The ID
  2502. * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
  2503. * @returns {Boolean}
  2504. */
  2505. _validateJMBG: function(value, countryCode) {
  2506. if (!/^\d{13}$/.test(value)) {
  2507. return false;
  2508. }
  2509. var day = parseInt(value.substr(0, 2), 10),
  2510. month = parseInt(value.substr(2, 2), 10),
  2511. year = parseInt(value.substr(4, 3), 10),
  2512. rr = parseInt(value.substr(7, 2), 10),
  2513. k = parseInt(value.substr(12, 1), 10);
  2514. // Validate date of birth
  2515. // FIXME: Validate the year of birth
  2516. if (day > 31 || month > 12) {
  2517. return false;
  2518. }
  2519. // Validate checksum
  2520. var sum = 0;
  2521. for (var i = 0; i < 6; i++) {
  2522. sum += (7 - i) * (parseInt(value.charAt(i), 10) + parseInt(value.charAt(i + 6), 10));
  2523. }
  2524. sum = 11 - sum % 11;
  2525. if (sum === 10 || sum === 11) {
  2526. sum = 0;
  2527. }
  2528. if (sum !== k) {
  2529. return false;
  2530. }
  2531. // Validate political region
  2532. // rr is the political region of birth, which can be in ranges:
  2533. // 10-19: Bosnia and Herzegovina
  2534. // 20-29: Montenegro
  2535. // 30-39: Croatia (not used anymore)
  2536. // 41-49: Macedonia
  2537. // 50-59: Slovenia (only 50 is used)
  2538. // 70-79: Central Serbia
  2539. // 80-89: Serbian province of Vojvodina
  2540. // 90-99: Kosovo
  2541. switch (countryCode.toUpperCase()) {
  2542. case 'BA':
  2543. return (10 <= rr && rr <= 19);
  2544. case 'MK':
  2545. return (41 <= rr && rr <= 49);
  2546. case 'ME':
  2547. return (20 <= rr && rr <= 29);
  2548. case 'RS':
  2549. return (70 <= rr && rr <= 99);
  2550. case 'SI':
  2551. return (50 <= rr && rr <= 59);
  2552. default:
  2553. return true;
  2554. }
  2555. },
  2556. _ba: function(value) {
  2557. return this._validateJMBG(value, 'BA');
  2558. },
  2559. _mk: function(value) {
  2560. return this._validateJMBG(value, 'MK');
  2561. },
  2562. _me: function(value) {
  2563. return this._validateJMBG(value, 'ME');
  2564. },
  2565. _rs: function(value) {
  2566. return this._validateJMBG(value, 'RS');
  2567. },
  2568. /**
  2569. * Examples: 0101006500006
  2570. */
  2571. _si: function(value) {
  2572. return this._validateJMBG(value, 'SI');
  2573. },
  2574. /**
  2575. * Validate Bulgarian national identification number (EGN)
  2576. * Examples:
  2577. * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
  2578. * - Invalid: 8019010008
  2579. *
  2580. * @see http://en.wikipedia.org/wiki/Uniform_civil_number
  2581. * @param {String} value The ID
  2582. * @returns {Boolean}
  2583. */
  2584. _bg: function(value) {
  2585. if (!/^\d{10}$/.test(value) && !/^\d{6}\s\d{3}\s\d{1}$/.test(value)) {
  2586. return false;
  2587. }
  2588. value = value.replace(/\s/g, '');
  2589. // Check the birth date
  2590. var year = parseInt(value.substr(0, 2), 10) + 1900,
  2591. month = parseInt(value.substr(2, 2), 10),
  2592. day = parseInt(value.substr(4, 2), 10);
  2593. if (month > 40) {
  2594. year += 100;
  2595. month -= 40;
  2596. } else if (month > 20) {
  2597. year -= 100;
  2598. month -= 20;
  2599. }
  2600. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2601. return false;
  2602. }
  2603. var sum = 0,
  2604. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  2605. for (var i = 0; i < 9; i++) {
  2606. sum += parseInt(value.charAt(i), 10) * weight[i];
  2607. }
  2608. sum = (sum % 11) % 10;
  2609. return (sum + '' === value.substr(9, 1));
  2610. },
  2611. /**
  2612. * Validate Brazilian national identification number (CPF)
  2613. * Examples:
  2614. * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
  2615. * - Invalid: 231.002.999-00
  2616. *
  2617. * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
  2618. * @param {String} value The ID
  2619. * @returns {Boolean}
  2620. */
  2621. _br: function(value) {
  2622. if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
  2623. return false;
  2624. }
  2625. if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
  2626. return false;
  2627. }
  2628. value = value.replace(/\./g, '').replace(/-/g, '');
  2629. var d1 = 0;
  2630. for (var i = 0; i < 9; i++) {
  2631. d1 += (10 - i) * parseInt(value.charAt(i), 10);
  2632. }
  2633. d1 = 11 - d1 % 11;
  2634. if (d1 === 10 || d1 === 11) {
  2635. d1 = 0;
  2636. }
  2637. if (d1 + '' !== value.charAt(9)) {
  2638. return false;
  2639. }
  2640. var d2 = 0;
  2641. for (i = 0; i < 10; i++) {
  2642. d2 += (11 - i) * parseInt(value.charAt(i), 10);
  2643. }
  2644. d2 = 11 - d2 % 11;
  2645. if (d2 === 10 || d2 === 11) {
  2646. d2 = 0;
  2647. }
  2648. return (d2 + '' === value.charAt(10));
  2649. },
  2650. /**
  2651. * Validate Swiss Social Security Number (AHV-Nr/No AVS)
  2652. * Examples:
  2653. * - Valid: 756.1234.5678.95, 7561234567895
  2654. *
  2655. * @see http://en.wikipedia.org/wiki/National_identification_number#Switzerland
  2656. * @see http://www.bsv.admin.ch/themen/ahv/00011/02185/index.html?lang=de
  2657. * @param {String} value The ID
  2658. * @returns {Boolean}
  2659. */
  2660. _ch: function(value) {
  2661. if (!/^756[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{4}[\.]{0,1}[0-9]{2}$/.test(value)) {
  2662. return false;
  2663. }
  2664. value = value.replace(/\D/g, '').substr(3);
  2665. var length = value.length,
  2666. sum = 0,
  2667. weight = (length === 8) ? [3, 1] : [1, 3];
  2668. for (var i = 0; i < length - 1; i++) {
  2669. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  2670. }
  2671. sum = 10 - sum % 10;
  2672. return (sum + '' === value.charAt(length - 1));
  2673. },
  2674. /**
  2675. * Validate Chilean national identification number (RUN/RUT)
  2676. * Examples:
  2677. * - Valid: 76086428-5, 22060449-7, 12531909-2
  2678. *
  2679. * @see http://en.wikipedia.org/wiki/National_identification_number#Chile
  2680. * @see https://palena.sii.cl/cvc/dte/ee_empresas_emisoras.html for samples
  2681. * @param {String} value The ID
  2682. * @returns {Boolean}
  2683. */
  2684. _cl: function(value) {
  2685. if (!/^\d{7,8}[-]{0,1}[0-9K]$/.test(value)) {
  2686. return false;
  2687. }
  2688. value = value.replace(/\D/g, '');
  2689. while (value.length < 9) {
  2690. value = '0' + value;
  2691. }
  2692. var sum = 0,
  2693. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  2694. for (var i = 0; i < 8; i++) {
  2695. sum += parseInt(value.charAt(i), 10) * weight[i];
  2696. }
  2697. sum = 11 - sum % 11;
  2698. if (sum === 11) {
  2699. sum = 0;
  2700. } else if (sum === 10) {
  2701. sum = 'K';
  2702. }
  2703. return sum + '' === value.charAt(8);
  2704. },
  2705. /**
  2706. * Validate Czech national identification number (RC)
  2707. * Examples:
  2708. * - Valid: 7103192745, 991231123
  2709. * - Invalid: 1103492745, 590312123
  2710. *
  2711. * @param {String} value The ID
  2712. * @returns {Boolean}
  2713. */
  2714. _cz: function(value) {
  2715. if (!/^\d{9,10}$/.test(value)) {
  2716. return false;
  2717. }
  2718. var year = 1900 + parseInt(value.substr(0, 2), 10),
  2719. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  2720. day = parseInt(value.substr(4, 2), 10);
  2721. if (value.length === 9) {
  2722. if (year >= 1980) {
  2723. year -= 100;
  2724. }
  2725. if (year > 1953) {
  2726. return false;
  2727. }
  2728. } else if (year < 1954) {
  2729. year += 100;
  2730. }
  2731. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2732. return false;
  2733. }
  2734. // Check that the birth date is not in the future
  2735. if (value.length === 10) {
  2736. var check = parseInt(value.substr(0, 9), 10) % 11;
  2737. if (year < 1985) {
  2738. check = check % 10;
  2739. }
  2740. return (check + '' === value.substr(9, 1));
  2741. }
  2742. return true;
  2743. },
  2744. /**
  2745. * Validate Danish Personal Identification number (CPR)
  2746. * Examples:
  2747. * - Valid: 2110625629, 211062-5629
  2748. * - Invalid: 511062-5629
  2749. *
  2750. * @see https://en.wikipedia.org/wiki/Personal_identification_number_(Denmark)
  2751. * @param {String} value The ID
  2752. * @returns {Boolean}
  2753. */
  2754. _dk: function(value) {
  2755. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  2756. return false;
  2757. }
  2758. value = value.replace(/-/g, '');
  2759. var day = parseInt(value.substr(0, 2), 10),
  2760. month = parseInt(value.substr(2, 2), 10),
  2761. year = parseInt(value.substr(4, 2), 10);
  2762. switch (true) {
  2763. case ('5678'.indexOf(value.charAt(6)) !== -1 && year >= 58):
  2764. year += 1800;
  2765. break;
  2766. case ('0123'.indexOf(value.charAt(6)) !== -1):
  2767. case ('49'.indexOf(value.charAt(6)) !== -1 && year >= 37):
  2768. year += 1900;
  2769. break;
  2770. default:
  2771. year += 2000;
  2772. break;
  2773. }
  2774. return $.fn.bootstrapValidator.helpers.date(year, month, day);
  2775. },
  2776. /**
  2777. * Validate Estonian Personal Identification Code (isikukood)
  2778. * Examples:
  2779. * - Valid: 37605030299
  2780. *
  2781. * @see http://et.wikipedia.org/wiki/Isikukood
  2782. * @param {String} value The ID
  2783. * @returns {Boolean}
  2784. */
  2785. _ee: function(value) {
  2786. // Use the same format as Lithuanian Personal Code
  2787. return this._lt(value);
  2788. },
  2789. /**
  2790. * Validate Spanish personal identity code (DNI)
  2791. * Support i) DNI (for Spanish citizens) and ii) NIE (for foreign people)
  2792. *
  2793. * Examples:
  2794. * - Valid: i) 54362315K, 54362315-K; ii) X2482300W, X-2482300W, X-2482300-W
  2795. * - Invalid: i) 54362315Z; ii) X-2482300A
  2796. *
  2797. * @see https://en.wikipedia.org/wiki/National_identification_number#Spain
  2798. * @param {String} value The ID
  2799. * @returns {Boolean}
  2800. */
  2801. _es: function(value) {
  2802. if (!/^[0-9A-Z]{8}[-]{0,1}[0-9A-Z]$/.test(value) // DNI
  2803. && !/^[XYZ][-]{0,1}[0-9]{7}[-]{0,1}[0-9A-Z]$/.test(value)) { // NIE
  2804. return false;
  2805. }
  2806. value = value.replace(/-/g, '');
  2807. var index = 'XYZ'.indexOf(value.charAt(0));
  2808. if (index !== -1) {
  2809. // It is NIE number
  2810. value = index + value.substr(1) + '';
  2811. }
  2812. var check = parseInt(value.substr(0, 8), 10);
  2813. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  2814. return (check === value.substr(8, 1));
  2815. },
  2816. /**
  2817. * Validate Finnish Personal Identity Code (HETU)
  2818. * Examples:
  2819. * - Valid: 311280-888Y, 131052-308T
  2820. * - Invalid: 131052-308U, 310252-308Y
  2821. *
  2822. * @param {String} value The ID
  2823. * @returns {Boolean}
  2824. */
  2825. _fi: function(value) {
  2826. if (!/^[0-9]{6}[-+A][0-9]{3}[0-9ABCDEFHJKLMNPRSTUVWXY]$/.test(value)) {
  2827. return false;
  2828. }
  2829. var day = parseInt(value.substr(0, 2), 10),
  2830. month = parseInt(value.substr(2, 2), 10),
  2831. year = parseInt(value.substr(4, 2), 10),
  2832. centuries = {
  2833. '+': 1800,
  2834. '-': 1900,
  2835. 'A': 2000
  2836. };
  2837. year = centuries[value.charAt(6)] + year;
  2838. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  2839. return false;
  2840. }
  2841. var individual = parseInt(value.substr(7, 3), 10);
  2842. if (individual < 2) {
  2843. return false;
  2844. }
  2845. var n = value.substr(0, 6) + value.substr(7, 3) + '';
  2846. n = parseInt(n, 10);
  2847. return '0123456789ABCDEFHJKLMNPRSTUVWXY'.charAt(n % 31) === value.charAt(10);
  2848. },
  2849. /**
  2850. * Validate Croatian personal identification number (OIB)
  2851. * Examples:
  2852. * - Valid: 33392005961
  2853. * - Invalid: 33392005962
  2854. *
  2855. * @param {String} value The ID
  2856. * @returns {Boolean}
  2857. */
  2858. _hr: function(value) {
  2859. if (!/^[0-9]{11}$/.test(value)) {
  2860. return false;
  2861. }
  2862. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  2863. },
  2864. /**
  2865. * Validate Irish Personal Public Service Number (PPS)
  2866. * Examples:
  2867. * - Valid: 6433435F, 6433435FT, 6433435FW, 6433435OA, 6433435IH, 1234567TW, 1234567FA
  2868. * - Invalid: 6433435E, 6433435VH
  2869. *
  2870. * @see https://en.wikipedia.org/wiki/Personal_Public_Service_Number
  2871. * @param {String} value The ID
  2872. * @returns {Boolean}
  2873. */
  2874. _ie: function(value) {
  2875. if (!/^\d{7}[A-W][AHWTX]?$/.test(value)) {
  2876. return false;
  2877. }
  2878. var getCheckDigit = function(value) {
  2879. while (value.length < 7) {
  2880. value = '0' + value;
  2881. }
  2882. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  2883. sum = 0;
  2884. for (var i = 0; i < 7; i++) {
  2885. sum += parseInt(value.charAt(i), 10) * (8 - i);
  2886. }
  2887. sum += 9 * alphabet.indexOf(value.substr(7));
  2888. return alphabet[sum % 23];
  2889. };
  2890. // 2013 format
  2891. if (value.length === 9 && ('A' === value.charAt(8) || 'H' === value.charAt(8))) {
  2892. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  2893. }
  2894. // The old format
  2895. else {
  2896. return value.charAt(7) === getCheckDigit(value.substr(0, 7));
  2897. }
  2898. },
  2899. /**
  2900. * Validate Iceland national identification number (Kennitala)
  2901. * Examples:
  2902. * - Valid: 120174-3399, 1201743399, 0902862349
  2903. *
  2904. * @see http://en.wikipedia.org/wiki/Kennitala
  2905. * @param {String} value The ID
  2906. * @returns {Boolean}
  2907. */
  2908. _is: function(value) {
  2909. if (!/^[0-9]{6}[-]{0,1}[0-9]{4}$/.test(value)) {
  2910. return false;
  2911. }
  2912. value = value.replace(/-/g, '');
  2913. var day = parseInt(value.substr(0, 2), 10),
  2914. month = parseInt(value.substr(2, 2), 10),
  2915. year = parseInt(value.substr(4, 2), 10),
  2916. century = parseInt(value.charAt(9), 10);
  2917. year = (century === 9) ? (1900 + year) : ((20 + century) * 100 + year);
  2918. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  2919. return false;
  2920. }
  2921. // Validate the check digit
  2922. var sum = 0,
  2923. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  2924. for (var i = 0; i < 8; i++) {
  2925. sum += parseInt(value.charAt(i), 10) * weight[i];
  2926. }
  2927. sum = 11 - sum % 11;
  2928. return (sum + '' === value.charAt(8));
  2929. },
  2930. /**
  2931. * Validate Lithuanian Personal Code (Asmens kodas)
  2932. * Examples:
  2933. * - Valid: 38703181745
  2934. * - Invalid: 38703181746, 78703181745, 38703421745
  2935. *
  2936. * @see http://en.wikipedia.org/wiki/National_identification_number#Lithuania
  2937. * @see http://www.adomas.org/midi2007/pcode.html
  2938. * @param {String} value The ID
  2939. * @returns {Boolean}
  2940. */
  2941. _lt: function(value) {
  2942. if (!/^[0-9]{11}$/.test(value)) {
  2943. return false;
  2944. }
  2945. var gender = parseInt(value.charAt(0), 10),
  2946. year = parseInt(value.substr(1, 2), 10),
  2947. month = parseInt(value.substr(3, 2), 10),
  2948. day = parseInt(value.substr(5, 2), 10),
  2949. century = (gender % 2 === 0) ? (17 + gender / 2) : (17 + (gender + 1) / 2);
  2950. year = century * 100 + year;
  2951. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  2952. return false;
  2953. }
  2954. // Validate the check digit
  2955. var sum = 0,
  2956. weight = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
  2957. for (var i = 0; i < 10; i++) {
  2958. sum += parseInt(value.charAt(i), 10) * weight[i];
  2959. }
  2960. sum = sum % 11;
  2961. if (sum !== 10) {
  2962. return sum + '' === value.charAt(10);
  2963. }
  2964. // Re-calculate the check digit
  2965. sum = 0;
  2966. weight = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
  2967. for (i = 0; i < 10; i++) {
  2968. sum += parseInt(value.charAt(i), 10) * weight[i];
  2969. }
  2970. sum = sum % 11;
  2971. if (sum === 10) {
  2972. sum = 0;
  2973. }
  2974. return (sum + '' === value.charAt(10));
  2975. },
  2976. /**
  2977. * Validate Latvian Personal Code (Personas kods)
  2978. * Examples:
  2979. * - Valid: 161175-19997, 16117519997
  2980. * - Invalid: 161375-19997
  2981. *
  2982. * @see http://laacz.lv/2006/11/25/pk-parbaudes-algoritms/
  2983. * @param {String} value The ID
  2984. * @returns {Boolean}
  2985. */
  2986. _lv: function(value) {
  2987. if (!/^[0-9]{6}[-]{0,1}[0-9]{5}$/.test(value)) {
  2988. return false;
  2989. }
  2990. value = value.replace(/\D/g, '');
  2991. // Check birth date
  2992. var day = parseInt(value.substr(0, 2), 10),
  2993. month = parseInt(value.substr(2, 2), 10),
  2994. year = parseInt(value.substr(4, 2), 10);
  2995. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  2996. if (!$.fn.bootstrapValidator.helpers.date(year, month, day, true)) {
  2997. return false;
  2998. }
  2999. // Check personal code
  3000. var sum = 0,
  3001. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  3002. for (var i = 0; i < 10; i++) {
  3003. sum += parseInt(value.charAt(i), 10) * weight[i];
  3004. }
  3005. sum = (sum + 1) % 11 % 10;
  3006. return (sum + '' === value.charAt(10));
  3007. },
  3008. /**
  3009. * Validate Dutch national identification number (BSN)
  3010. * Examples:
  3011. * - Valid: 111222333, 941331490, 9413.31.490
  3012. * - Invalid: 111252333
  3013. *
  3014. * @see https://nl.wikipedia.org/wiki/Burgerservicenummer
  3015. * @param {String} value The ID
  3016. * @returns {Boolean}
  3017. */
  3018. _nl: function(value) {
  3019. while (value.length < 9) {
  3020. value = '0' + value;
  3021. }
  3022. if (!/^[0-9]{4}[.]{0,1}[0-9]{2}[.]{0,1}[0-9]{3}$/.test(value)) {
  3023. return false;
  3024. }
  3025. value = value.replace(/\./g, '');
  3026. if (parseInt(value, 10) === 0) {
  3027. return false;
  3028. }
  3029. var sum = 0,
  3030. length = value.length;
  3031. for (var i = 0; i < length - 1; i++) {
  3032. sum += (9 - i) * parseInt(value.charAt(i), 10);
  3033. }
  3034. sum = sum % 11;
  3035. if (sum === 10) {
  3036. sum = 0;
  3037. }
  3038. return (sum + '' === value.charAt(length - 1));
  3039. },
  3040. /**
  3041. * Validate Romanian numerical personal code (CNP)
  3042. * Examples:
  3043. * - Valid: 1630615123457, 1800101221144
  3044. * - Invalid: 8800101221144, 1632215123457, 1630615123458
  3045. *
  3046. * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
  3047. * @param {String} value The ID
  3048. * @returns {Boolean}
  3049. */
  3050. _ro: function(value) {
  3051. if (!/^[0-9]{13}$/.test(value)) {
  3052. return false;
  3053. }
  3054. var gender = parseInt(value.charAt(0), 10);
  3055. if (gender === 0 || gender === 7 || gender === 8) {
  3056. return false;
  3057. }
  3058. // Determine the date of birth
  3059. var year = parseInt(value.substr(1, 2), 10),
  3060. month = parseInt(value.substr(3, 2), 10),
  3061. day = parseInt(value.substr(5, 2), 10),
  3062. // The year of date is determined base on the gender
  3063. centuries = {
  3064. '1': 1900, // Male born between 1900 and 1999
  3065. '2': 1900, // Female born between 1900 and 1999
  3066. '3': 1800, // Male born between 1800 and 1899
  3067. '4': 1800, // Female born between 1800 and 1899
  3068. '5': 2000, // Male born after 2000
  3069. '6': 2000 // Female born after 2000
  3070. };
  3071. if (day > 31 && month > 12) {
  3072. return false;
  3073. }
  3074. if (gender !== 9) {
  3075. year = centuries[gender + ''] + year;
  3076. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3077. return false;
  3078. }
  3079. }
  3080. // Validate the check digit
  3081. var sum = 0,
  3082. weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
  3083. length = value.length;
  3084. for (var i = 0; i < length - 1; i++) {
  3085. sum += parseInt(value.charAt(i), 10) * weight[i];
  3086. }
  3087. sum = sum % 11;
  3088. if (sum === 10) {
  3089. sum = 1;
  3090. }
  3091. return (sum + '' === value.charAt(length - 1));
  3092. },
  3093. /**
  3094. * Validate Swedish personal identity number (personnummer)
  3095. * Examples:
  3096. * - Valid: 8112289874, 811228-9874, 811228+9874
  3097. * - Invalid: 811228-9873
  3098. *
  3099. * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
  3100. * @param {String} value The ID
  3101. * @returns {Boolean}
  3102. */
  3103. _se: function(value) {
  3104. if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
  3105. return false;
  3106. }
  3107. value = value.replace(/[^0-9]/g, '');
  3108. var year = parseInt(value.substr(0, 2), 10) + 1900,
  3109. month = parseInt(value.substr(2, 2), 10),
  3110. day = parseInt(value.substr(4, 2), 10);
  3111. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3112. return false;
  3113. }
  3114. // Validate the last check digit
  3115. return $.fn.bootstrapValidator.helpers.luhn(value);
  3116. },
  3117. /**
  3118. * Validate Slovak national identifier number (RC)
  3119. * Examples:
  3120. * - Valid: 7103192745, 991231123
  3121. * - Invalid: 7103192746, 1103492745
  3122. *
  3123. * @param {String} value The ID
  3124. * @returns {Boolean}
  3125. */
  3126. _sk: function(value) {
  3127. // Slovakia uses the same format as Czech Republic
  3128. return this._cz(value);
  3129. },
  3130. /**
  3131. * Validate San Marino citizen number
  3132. *
  3133. * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
  3134. * @param {String} value The ID
  3135. * @returns {Boolean}
  3136. */
  3137. _sm: function(value) {
  3138. return /^\d{5}$/.test(value);
  3139. },
  3140. /**
  3141. * Validate South African ID
  3142. * Example:
  3143. * - Valid: 8001015009087
  3144. * - Invalid: 8001015009287, 8001015009086
  3145. *
  3146. * @see http://en.wikipedia.org/wiki/National_identification_number#South_Africa
  3147. * @param {String} value The ID
  3148. * @returns {Boolean}
  3149. */
  3150. _za: function(value) {
  3151. if (!/^[0-9]{10}[0|1][8|9][0-9]$/.test(value)) {
  3152. return false;
  3153. }
  3154. var year = parseInt(value.substr(0, 2), 10),
  3155. currentYear = new Date().getFullYear() % 100,
  3156. month = parseInt(value.substr(2, 2), 10),
  3157. day = parseInt(value.substr(4, 2), 10);
  3158. year = (year >= currentYear) ? (year + 1900) : (year + 2000);
  3159. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  3160. return false;
  3161. }
  3162. // Validate the last check digit
  3163. return $.fn.bootstrapValidator.helpers.luhn(value);
  3164. }
  3165. };
  3166. }(window.jQuery));
  3167. ;(function($) {
  3168. $.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
  3169. 'default': 'Please enter the same value'
  3170. });
  3171. $.fn.bootstrapValidator.validators.identical = {
  3172. html5Attributes: {
  3173. message: 'message',
  3174. field: 'field'
  3175. },
  3176. /**
  3177. * Check if input value equals to value of particular one
  3178. *
  3179. * @param {BootstrapValidator} validator The validator plugin instance
  3180. * @param {jQuery} $field Field element
  3181. * @param {Object} options Consists of the following key:
  3182. * - field: The name of field that will be used to compare with current one
  3183. * @returns {Boolean}
  3184. */
  3185. validate: function(validator, $field, options) {
  3186. var value = $field.val();
  3187. if (value === '') {
  3188. return true;
  3189. }
  3190. var compareWith = validator.getFieldElements(options.field);
  3191. if (compareWith === null) {
  3192. return true;
  3193. }
  3194. if (value === compareWith.val()) {
  3195. validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
  3196. return true;
  3197. } else {
  3198. return false;
  3199. }
  3200. }
  3201. };
  3202. }(window.jQuery));
  3203. ;(function($) {
  3204. $.fn.bootstrapValidator.i18n.imei = $.extend($.fn.bootstrapValidator.i18n.imei || {}, {
  3205. 'default': 'Please enter a valid IMEI number'
  3206. });
  3207. $.fn.bootstrapValidator.validators.imei = {
  3208. /**
  3209. * Validate IMEI (International Mobile Station Equipment Identity)
  3210. * Examples:
  3211. * - Valid: 35-209900-176148-1, 35-209900-176148-23, 3568680000414120, 490154203237518
  3212. * - Invalid: 490154203237517
  3213. *
  3214. * @see http://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity
  3215. * @param {BootstrapValidator} validator The validator plugin instance
  3216. * @param {jQuery} $field Field element
  3217. * @param {Object} options Can consist of the following keys:
  3218. * - message: The invalid message
  3219. * @returns {Boolean}
  3220. */
  3221. validate: function(validator, $field, options) {
  3222. var value = $field.val();
  3223. if (value === '') {
  3224. return true;
  3225. }
  3226. switch (true) {
  3227. case /^\d{15}$/.test(value):
  3228. case /^\d{2}-\d{6}-\d{6}-\d{1}$/.test(value):
  3229. case /^\d{2}\s\d{6}\s\d{6}\s\d{1}$/.test(value):
  3230. value = value.replace(/[^0-9]/g, '');
  3231. return $.fn.bootstrapValidator.helpers.luhn(value);
  3232. case /^\d{14}$/.test(value):
  3233. case /^\d{16}$/.test(value):
  3234. case /^\d{2}-\d{6}-\d{6}(|-\d{2})$/.test(value):
  3235. case /^\d{2}\s\d{6}\s\d{6}(|\s\d{2})$/.test(value):
  3236. return true;
  3237. default:
  3238. return false;
  3239. }
  3240. }
  3241. };
  3242. }(window.jQuery));
  3243. ;(function($) {
  3244. $.fn.bootstrapValidator.i18n.integer = $.extend($.fn.bootstrapValidator.i18n.integer || {}, {
  3245. 'default': 'Please enter a valid number'
  3246. });
  3247. $.fn.bootstrapValidator.validators.integer = {
  3248. enableByHtml5: function($field) {
  3249. return ('number' === $field.attr('type'));
  3250. },
  3251. /**
  3252. * Return true if the input value is an integer
  3253. *
  3254. * @param {BootstrapValidator} validator The validator plugin instance
  3255. * @param {jQuery} $field Field element
  3256. * @param {Object} options Can consist of the following key:
  3257. * - message: The invalid message
  3258. * @returns {Boolean}
  3259. */
  3260. validate: function(validator, $field, options) {
  3261. var value = $field.val();
  3262. if (value === '') {
  3263. return true;
  3264. }
  3265. return /^(?:-?(?:0|[1-9][0-9]*))$/.test(value);
  3266. }
  3267. };
  3268. }(window.jQuery));
  3269. ;(function($) {
  3270. $.fn.bootstrapValidator.i18n.ip = $.extend($.fn.bootstrapValidator.i18n.ip || {}, {
  3271. 'default': 'Please enter a valid IP address'
  3272. });
  3273. $.fn.bootstrapValidator.validators.ip = {
  3274. html5Attributes: {
  3275. message: 'message',
  3276. ipv4: 'ipv4',
  3277. ipv6: 'ipv6'
  3278. },
  3279. /**
  3280. * Return true if the input value is a IP address.
  3281. *
  3282. * @param {BootstrapValidator} validator The validator plugin instance
  3283. * @param {jQuery} $field Field element
  3284. * @param {Object} options Can consist of the following keys:
  3285. * - ipv4: Enable IPv4 validator, default to true
  3286. * - ipv6: Enable IPv6 validator, default to true
  3287. * - message: The invalid message
  3288. * @returns {Boolean}
  3289. */
  3290. validate: function(validator, $field, options) {
  3291. var value = $field.val();
  3292. if (value === '') {
  3293. return true;
  3294. }
  3295. options = $.extend({}, { ipv4: true, ipv6: true }, options);
  3296. if (options.ipv4) {
  3297. return /^(?:(?: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]?)$/.test(value);
  3298. } else if (options.ipv6) {
  3299. return /^\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*$/.test(value);
  3300. }
  3301. return false;
  3302. }
  3303. };
  3304. }(window.jQuery));
  3305. ;(function($) {
  3306. $.fn.bootstrapValidator.i18n.isbn = $.extend($.fn.bootstrapValidator.i18n.isbn || {}, {
  3307. 'default': 'Please enter a valid ISBN number'
  3308. });
  3309. $.fn.bootstrapValidator.validators.isbn = {
  3310. /**
  3311. * Return true if the input value is a valid ISBN 10 or ISBN 13 number
  3312. * Examples:
  3313. * - Valid:
  3314. * 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
  3315. * ISBN 13: 978-0-306-40615-7
  3316. * - Invalid:
  3317. * ISBN 10: 99921-58-10-6
  3318. * ISBN 13: 978-0-306-40615-6
  3319. *
  3320. * @see http://en.wikipedia.org/wiki/International_Standard_Book_Number
  3321. * @param {BootstrapValidator} validator The validator plugin instance
  3322. * @param {jQuery} $field Field element
  3323. * @param {Object} [options] Can consist of the following keys:
  3324. * - message: The invalid message
  3325. * @returns {Boolean}
  3326. */
  3327. validate: function(validator, $field, options) {
  3328. var value = $field.val();
  3329. if (value === '') {
  3330. return true;
  3331. }
  3332. // http://en.wikipedia.org/wiki/International_Standard_Book_Number#Overview
  3333. // Groups are separated by a hyphen or a space
  3334. var type;
  3335. switch (true) {
  3336. case /^\d{9}[\dX]$/.test(value):
  3337. case (value.length === 13 && /^(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  3338. case (value.length === 13 && /^(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  3339. type = 'ISBN10';
  3340. break;
  3341. case /^(978|979)\d{9}[\dX]$/.test(value):
  3342. case (value.length === 17 && /^(978|979)-(\d+)-(\d+)-(\d+)-([\dX])$/.test(value)):
  3343. case (value.length === 17 && /^(978|979)\s(\d+)\s(\d+)\s(\d+)\s([\dX])$/.test(value)):
  3344. type = 'ISBN13';
  3345. break;
  3346. default:
  3347. return false;
  3348. }
  3349. // Replace all special characters except digits and X
  3350. value = value.replace(/[^0-9X]/gi, '');
  3351. var chars = value.split(''),
  3352. length = chars.length,
  3353. sum = 0,
  3354. i,
  3355. checksum;
  3356. switch (type) {
  3357. case 'ISBN10':
  3358. sum = 0;
  3359. for (i = 0; i < length - 1; i++) {
  3360. sum += parseInt(chars[i], 10) * (10 - i);
  3361. }
  3362. checksum = 11 - (sum % 11);
  3363. if (checksum === 11) {
  3364. checksum = 0;
  3365. } else if (checksum === 10) {
  3366. checksum = 'X';
  3367. }
  3368. return (checksum + '' === chars[length - 1]);
  3369. case 'ISBN13':
  3370. sum = 0;
  3371. for (i = 0; i < length - 1; i++) {
  3372. sum += ((i % 2 === 0) ? parseInt(chars[i], 10) : (parseInt(chars[i], 10) * 3));
  3373. }
  3374. checksum = 10 - (sum % 10);
  3375. if (checksum === 10) {
  3376. checksum = '0';
  3377. }
  3378. return (checksum + '' === chars[length - 1]);
  3379. default:
  3380. return false;
  3381. }
  3382. }
  3383. };
  3384. }(window.jQuery));
  3385. ;(function($) {
  3386. $.fn.bootstrapValidator.i18n.isin = $.extend($.fn.bootstrapValidator.i18n.isin || {}, {
  3387. 'default': 'Please enter a valid ISIN number'
  3388. });
  3389. $.fn.bootstrapValidator.validators.isin = {
  3390. // Available country codes
  3391. // See http://isin.net/country-codes/
  3392. 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',
  3393. /**
  3394. * Validate an ISIN (International Securities Identification Number)
  3395. * Examples:
  3396. * - Valid: US0378331005, AU0000XVGZA3, GB0002634946
  3397. * - Invalid: US0378331004, AA0000XVGZA3
  3398. *
  3399. * @see http://en.wikipedia.org/wiki/International_Securities_Identifying_Number
  3400. * @param {BootstrapValidator} validator The validator plugin instance
  3401. * @param {jQuery} $field Field element
  3402. * @param {Object} options Can consist of the following keys:
  3403. * - message: The invalid message
  3404. * @returns {Boolean}
  3405. */
  3406. validate: function(validator, $field, options) {
  3407. var value = $field.val();
  3408. if (value === '') {
  3409. return true;
  3410. }
  3411. value = value.toUpperCase();
  3412. var regex = new RegExp('^(' + this.COUNTRY_CODES + ')[0-9A-Z]{10}$');
  3413. if (!regex.test(value)) {
  3414. return false;
  3415. }
  3416. var converted = '',
  3417. length = value.length;
  3418. // Convert letters to number
  3419. for (var i = 0; i < length - 1; i++) {
  3420. var c = value.charCodeAt(i);
  3421. converted += ((c > 57) ? (c - 55).toString() : value.charAt(i));
  3422. }
  3423. var digits = '',
  3424. n = converted.length,
  3425. group = (n % 2 !== 0) ? 0 : 1;
  3426. for (i = 0; i < n; i++) {
  3427. digits += (parseInt(converted[i], 10) * ((i % 2) === group ? 2 : 1) + '');
  3428. }
  3429. var sum = 0;
  3430. for (i = 0; i < digits.length; i++) {
  3431. sum += parseInt(digits.charAt(i), 10);
  3432. }
  3433. sum = (10 - (sum % 10)) % 10;
  3434. return sum + '' === value.charAt(length - 1);
  3435. }
  3436. };
  3437. }(window.jQuery));
  3438. ;(function($) {
  3439. $.fn.bootstrapValidator.i18n.ismn = $.extend($.fn.bootstrapValidator.i18n.ismn || {}, {
  3440. 'default': 'Please enter a valid ISMN number'
  3441. });
  3442. $.fn.bootstrapValidator.validators.ismn = {
  3443. /**
  3444. * Validate ISMN (International Standard Music Number)
  3445. * Examples:
  3446. * - Valid: M230671187, 979-0-0601-1561-5, 979 0 3452 4680 5, 9790060115615
  3447. * - Invalid: 9790060115614
  3448. *
  3449. * @see http://en.wikipedia.org/wiki/International_Standard_Music_Number
  3450. * @param {BootstrapValidator} validator The validator plugin instance
  3451. * @param {jQuery} $field Field element
  3452. * @param {Object} options Can consist of the following keys:
  3453. * - message: The invalid message
  3454. * @returns {Boolean}
  3455. */
  3456. validate: function(validator, $field, options) {
  3457. var value = $field.val();
  3458. if (value === '') {
  3459. return true;
  3460. }
  3461. // Groups are separated by a hyphen or a space
  3462. var type;
  3463. switch (true) {
  3464. case /^M\d{9}$/.test(value):
  3465. case /^M-\d{4}-\d{4}-\d{1}$/.test(value):
  3466. case /^M\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3467. type = 'ISMN10';
  3468. break;
  3469. case /^9790\d{9}$/.test(value):
  3470. case /^979-0-\d{4}-\d{4}-\d{1}$/.test(value):
  3471. case /^979\s0\s\d{4}\s\d{4}\s\d{1}$/.test(value):
  3472. type = 'ISMN13';
  3473. break;
  3474. default:
  3475. return false;
  3476. }
  3477. if ('ISMN10' === type) {
  3478. value = '9790' + value.substr(1);
  3479. }
  3480. // Replace all special characters except digits
  3481. value = value.replace(/[^0-9]/gi, '');
  3482. var length = value.length,
  3483. sum = 0,
  3484. weight = [1, 3];
  3485. for (var i = 0; i < length - 1; i++) {
  3486. sum += parseInt(value.charAt(i), 10) * weight[i % 2];
  3487. }
  3488. sum = 10 - sum % 10;
  3489. return (sum + '' === value.charAt(length - 1));
  3490. }
  3491. };
  3492. }(window.jQuery));
  3493. ;(function($) {
  3494. $.fn.bootstrapValidator.i18n.issn = $.extend($.fn.bootstrapValidator.i18n.issn || {}, {
  3495. 'default': 'Please enter a valid ISSN number'
  3496. });
  3497. $.fn.bootstrapValidator.validators.issn = {
  3498. /**
  3499. * Validate ISSN (International Standard Serial Number)
  3500. * Examples:
  3501. * - Valid: 0378-5955, 0024-9319, 0032-1478
  3502. * - Invalid: 0032-147X
  3503. *
  3504. * @see http://en.wikipedia.org/wiki/International_Standard_Serial_Number
  3505. * @param {BootstrapValidator} validator The validator plugin instance
  3506. * @param {jQuery} $field Field element
  3507. * @param {Object} options Can consist of the following keys:
  3508. * - message: The invalid message
  3509. * @returns {Boolean}
  3510. */
  3511. validate: function(validator, $field, options) {
  3512. var value = $field.val();
  3513. if (value === '') {
  3514. return true;
  3515. }
  3516. // Groups are separated by a hyphen or a space
  3517. if (!/^\d{4}\-\d{3}[\dX]$/.test(value)) {
  3518. return false;
  3519. }
  3520. // Replace all special characters except digits and X
  3521. value = value.replace(/[^0-9X]/gi, '');
  3522. var chars = value.split(''),
  3523. length = chars.length,
  3524. sum = 0;
  3525. if (chars[7] === 'X') {
  3526. chars[7] = 10;
  3527. }
  3528. for (var i = 0; i < length; i++) {
  3529. sum += parseInt(chars[i], 10) * (8 - i);
  3530. }
  3531. return (sum % 11 === 0);
  3532. }
  3533. };
  3534. }(window.jQuery));
  3535. ;(function($) {
  3536. $.fn.bootstrapValidator.i18n.lessThan = $.extend($.fn.bootstrapValidator.i18n.lessThan || {}, {
  3537. 'default': 'Please enter a value less than or equal to %s',
  3538. notInclusive: 'Please enter a value less than %s',
  3539. getMessage: function(options) {
  3540. return (options.inclusive === true || options.inclusive === undefined)
  3541. ? $.fn.bootstrapValidator.helpers.format(this['default'], options.value)
  3542. : $.fn.bootstrapValidator.helpers.format(this.notInclusive, options.value);
  3543. }
  3544. });
  3545. $.fn.bootstrapValidator.validators.lessThan = {
  3546. html5Attributes: {
  3547. message: 'message',
  3548. value: 'value',
  3549. inclusive: 'inclusive'
  3550. },
  3551. enableByHtml5: function($field) {
  3552. var max = $field.attr('max');
  3553. if (max) {
  3554. return {
  3555. value: max
  3556. };
  3557. }
  3558. return false;
  3559. },
  3560. /**
  3561. * Return true if the input value is less than or equal to given number
  3562. *
  3563. * @param {BootstrapValidator} validator The validator plugin instance
  3564. * @param {jQuery} $field Field element
  3565. * @param {Object} options Can consist of the following keys:
  3566. * - value: The number used to compare to
  3567. * - inclusive [optional]: Can be true or false. Default is true
  3568. * - message: The invalid message
  3569. * @returns {Boolean}
  3570. */
  3571. validate: function(validator, $field, options) {
  3572. var value = $field.val();
  3573. if (value === '') {
  3574. return true;
  3575. }
  3576. value = parseFloat(value);
  3577. return (options.inclusive === true || options.inclusive === undefined) ? (value <= options.value) : (value < options.value);
  3578. }
  3579. };
  3580. }(window.jQuery));
  3581. ;(function($) {
  3582. $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
  3583. 'default': 'Please enter a valid MAC address'
  3584. });
  3585. $.fn.bootstrapValidator.validators.mac = {
  3586. /**
  3587. * Return true if the input value is a MAC address.
  3588. *
  3589. * @param {BootstrapValidator} validator The validator plugin instance
  3590. * @param {jQuery} $field Field element
  3591. * @param {Object} options Can consist of the following keys:
  3592. * - message: The invalid message
  3593. * @returns {Boolean}
  3594. */
  3595. validate: function(validator, $field, options) {
  3596. var value = $field.val();
  3597. if (value === '') {
  3598. return true;
  3599. }
  3600. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  3601. }
  3602. };
  3603. }(window.jQuery));
  3604. ;(function($) {
  3605. $.fn.bootstrapValidator.i18n.notEmpty = $.extend($.fn.bootstrapValidator.i18n.notEmpty || {}, {
  3606. 'default': 'Please enter a value'
  3607. });
  3608. $.fn.bootstrapValidator.validators.notEmpty = {
  3609. enableByHtml5: function($field) {
  3610. var required = $field.attr('required') + '';
  3611. return ('required' === required || 'true' === required);
  3612. },
  3613. /**
  3614. * Check if input value is empty or not
  3615. *
  3616. * @param {BootstrapValidator} validator The validator plugin instance
  3617. * @param {jQuery} $field Field element
  3618. * @param {Object} options
  3619. * @returns {Boolean}
  3620. */
  3621. validate: function(validator, $field, options) {
  3622. var type = $field.attr('type');
  3623. if ('radio' === type || 'checkbox' === type) {
  3624. return validator
  3625. .getFieldElements($field.attr('data-bv-field'))
  3626. .filter(':checked')
  3627. .length > 0;
  3628. }
  3629. return $.trim($field.val()) !== '';
  3630. }
  3631. };
  3632. }(window.jQuery));
  3633. ;(function($) {
  3634. $.fn.bootstrapValidator.i18n.numeric = $.extend($.fn.bootstrapValidator.i18n.numeric || {}, {
  3635. 'default': 'Please enter a valid float number'
  3636. });
  3637. $.fn.bootstrapValidator.validators.numeric = {
  3638. html5Attributes: {
  3639. message: 'message',
  3640. separator: 'separator'
  3641. },
  3642. /**
  3643. * Validate decimal number
  3644. *
  3645. * @param {BootstrapValidator} validator The validator plugin instance
  3646. * @param {jQuery} $field Field element
  3647. * @param {Object} options Consist of key:
  3648. * - message: The invalid message
  3649. * - separator: The decimal separator. Can be "." (default), ","
  3650. * @returns {Boolean}
  3651. */
  3652. validate: function(validator, $field, options) {
  3653. var value = $field.val();
  3654. if (value === '') {
  3655. return true;
  3656. }
  3657. var separator = options.separator || '.';
  3658. if (separator !== '.') {
  3659. value = value.replace(separator, '.');
  3660. }
  3661. return !isNaN(parseFloat(value)) && isFinite(value);
  3662. }
  3663. };
  3664. }(window.jQuery));
  3665. ;(function($) {
  3666. $.fn.bootstrapValidator.i18n.phone = $.extend($.fn.bootstrapValidator.i18n.phone || {}, {
  3667. 'default': 'Please enter a valid phone number',
  3668. countryNotSupported: 'The country code %s is not supported',
  3669. country: 'Please enter a valid phone number in %s',
  3670. countries: {
  3671. GB: 'United Kingdom',
  3672. US: 'USA'
  3673. },
  3674. getMessage: function(options) {
  3675. var country = (options.country || 'US').toUpperCase();
  3676. if ($.inArray(country, $.fn.bootstrapValidator.validators.phone.COUNTRIES) === -1) {
  3677. return $.fn.bootstrapValidator.helpers.format(this.countryNotSupported, country);
  3678. }
  3679. if (this.countries[country]) {
  3680. return $.fn.bootstrapValidator.helpers.format(this.country, this.countries[country]);
  3681. }
  3682. return this['default'];
  3683. }
  3684. });
  3685. $.fn.bootstrapValidator.validators.phone = {
  3686. html5Attributes: {
  3687. message: 'message',
  3688. country: 'country'
  3689. },
  3690. // The supported countries
  3691. COUNTRIES: ['GB', 'US'],
  3692. /**
  3693. * Return true if the input value contains a valid phone number for the country
  3694. * selected in the options
  3695. *
  3696. * @param {BootstrapValidator} validator Validate plugin instance
  3697. * @param {jQuery} $field Field element
  3698. * @param {Object} options Consist of key:
  3699. * - message: The invalid message
  3700. * - country: The ISO 3166 country code
  3701. * Currently it only supports United State (US) or United Kingdom (GB) countries
  3702. * @returns {Boolean}
  3703. */
  3704. validate: function(validator, $field, options) {
  3705. var value = $field.val();
  3706. if (value === '') {
  3707. return true;
  3708. }
  3709. var country = (options.country || 'US').toUpperCase();
  3710. if ($.inArray(country, this.COUNTRIES) === -1) {
  3711. return false;
  3712. }
  3713. switch (country) {
  3714. case 'GB':
  3715. // http://aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers#Match_GB_telephone_number_in_any_format
  3716. // Test: http://regexr.com/38uhv
  3717. value = $.trim(value);
  3718. return (/^\(?(?:(?: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);
  3719. case 'US':
  3720. /* falls through */
  3721. default:
  3722. // Make sure US phone numbers have 10 digits
  3723. // May start with 1, +1, or 1-; should discard
  3724. // Area code may be delimited with (), & sections may be delimited with . or -
  3725. // Test: http://regexr.com/38mqi
  3726. value = value.replace(/\D/g, '');
  3727. return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length === 10);
  3728. }
  3729. }
  3730. };
  3731. }(window.jQuery));
  3732. ;(function($) {
  3733. $.fn.bootstrapValidator.i18n.regexp = $.extend($.fn.bootstrapValidator.i18n.regexp || {}, {
  3734. 'default': 'Please enter a value matching the pattern'
  3735. });
  3736. $.fn.bootstrapValidator.validators.regexp = {
  3737. html5Attributes: {
  3738. message: 'message',
  3739. regexp: 'regexp'
  3740. },
  3741. enableByHtml5: function($field) {
  3742. var pattern = $field.attr('pattern');
  3743. if (pattern) {
  3744. return {
  3745. regexp: pattern
  3746. };
  3747. }
  3748. return false;
  3749. },
  3750. /**
  3751. * Check if the element value matches given regular expression
  3752. *
  3753. * @param {BootstrapValidator} validator The validator plugin instance
  3754. * @param {jQuery} $field Field element
  3755. * @param {Object} options Consists of the following key:
  3756. * - regexp: The regular expression you need to check
  3757. * @returns {Boolean}
  3758. */
  3759. validate: function(validator, $field, options) {
  3760. var value = $field.val();
  3761. if (value === '') {
  3762. return true;
  3763. }
  3764. var regexp = ('string' === typeof options.regexp) ? new RegExp(options.regexp) : options.regexp;
  3765. return regexp.test(value);
  3766. }
  3767. };
  3768. }(window.jQuery));
  3769. ;(function($) {
  3770. $.fn.bootstrapValidator.i18n.remote = $.extend($.fn.bootstrapValidator.i18n.remote || {}, {
  3771. 'default': 'Please enter a valid value'
  3772. });
  3773. $.fn.bootstrapValidator.validators.remote = {
  3774. html5Attributes: {
  3775. message: 'message',
  3776. url: 'url',
  3777. name: 'name'
  3778. },
  3779. /**
  3780. * Request a remote server to check the input value
  3781. *
  3782. * @param {BootstrapValidator} validator Plugin instance
  3783. * @param {jQuery} $field Field element
  3784. * @param {Object} options Can consist of the following keys:
  3785. * - url {String|Function}
  3786. * - type {String} [optional] Can be GET or POST (default)
  3787. * - data {Object|Function} [optional]: By default, it will take the value
  3788. * {
  3789. * <fieldName>: <fieldValue>
  3790. * }
  3791. * - name {String} [optional]: Override the field name for the request.
  3792. * - message: The invalid message
  3793. * @returns {Boolean|Deferred}
  3794. */
  3795. validate: function(validator, $field, options) {
  3796. var value = $field.val();
  3797. if (value === '') {
  3798. return true;
  3799. }
  3800. var name = $field.attr('data-bv-field'),
  3801. data = options.data || {},
  3802. url = options.url,
  3803. type = options.type || 'POST';
  3804. // Support dynamic data
  3805. if ('function' === typeof data) {
  3806. data = data.call(this, validator);
  3807. }
  3808. // Support dynamic url
  3809. if ('function' === typeof url) {
  3810. url = url.call(this, validator);
  3811. }
  3812. data[options.name || name] = value;
  3813. var dfd = new $.Deferred();
  3814. var xhr = $.ajax({
  3815. type: type,
  3816. url: url,
  3817. dataType: 'json',
  3818. data: data
  3819. });
  3820. xhr.then(function(response) {
  3821. dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true', response.message ? response.message : null);
  3822. });
  3823. dfd.fail(function() {
  3824. xhr.abort();
  3825. });
  3826. return dfd;
  3827. }
  3828. };
  3829. }(window.jQuery));
  3830. ;(function($) {
  3831. $.fn.bootstrapValidator.i18n.rtn = $.extend($.fn.bootstrapValidator.i18n.rtn || {}, {
  3832. 'default': 'Please enter a valid RTN number'
  3833. });
  3834. $.fn.bootstrapValidator.validators.rtn = {
  3835. /**
  3836. * Validate a RTN (Routing transit number)
  3837. * Examples:
  3838. * - Valid: 021200025, 789456124
  3839. *
  3840. * @see http://en.wikipedia.org/wiki/Routing_transit_number
  3841. * @param {BootstrapValidator} validator The validator plugin instance
  3842. * @param {jQuery} $field Field element
  3843. * @param {Object} options Can consist of the following keys:
  3844. * - message: The invalid message
  3845. * @returns {Boolean}
  3846. */
  3847. validate: function(validator, $field, options) {
  3848. var value = $field.val();
  3849. if (value === '') {
  3850. return true;
  3851. }
  3852. if (!/^\d{9}$/.test(value)) {
  3853. return false;
  3854. }
  3855. var sum = 0;
  3856. for (var i = 0; i < value.length; i += 3) {
  3857. sum += parseInt(value.charAt(i), 10) * 3
  3858. + parseInt(value.charAt(i + 1), 10) * 7
  3859. + parseInt(value.charAt(i + 2), 10);
  3860. }
  3861. return (sum !== 0 && sum % 10 === 0);
  3862. }
  3863. };
  3864. }(window.jQuery));
  3865. ;(function($) {
  3866. $.fn.bootstrapValidator.i18n.sedol = $.extend($.fn.bootstrapValidator.i18n.sedol || {}, {
  3867. 'default': 'Please enter a valid SEDOL number'
  3868. });
  3869. $.fn.bootstrapValidator.validators.sedol = {
  3870. /**
  3871. * Validate a SEDOL (Stock Exchange Daily Official List)
  3872. * Examples:
  3873. * - Valid: 0263494, B0WNLY7
  3874. *
  3875. * @see http://en.wikipedia.org/wiki/SEDOL
  3876. * @param {BootstrapValidator} validator The validator plugin instance
  3877. * @param {jQuery} $field Field element
  3878. * @param {Object} options Can consist of the following keys:
  3879. * - message: The invalid message
  3880. * @returns {Boolean}
  3881. */
  3882. validate: function(validator, $field, options) {
  3883. var value = $field.val();
  3884. if (value === '') {
  3885. return true;
  3886. }
  3887. value = value.toUpperCase();
  3888. if (!/^[0-9A-Z]{7}$/.test(value)) {
  3889. return false;
  3890. }
  3891. var sum = 0,
  3892. weight = [1, 3, 1, 7, 3, 9, 1],
  3893. length = value.length;
  3894. for (var i = 0; i < length - 1; i++) {
  3895. sum += weight[i] * parseInt(value.charAt(i), 36);
  3896. }
  3897. sum = (10 - sum % 10) % 10;
  3898. return sum + '' === value.charAt(length - 1);
  3899. }
  3900. };
  3901. }(window.jQuery));
  3902. ;(function($) {
  3903. $.fn.bootstrapValidator.i18n.siren = $.extend($.fn.bootstrapValidator.i18n.siren || {}, {
  3904. 'default': 'Please enter a valid SIREN number'
  3905. });
  3906. $.fn.bootstrapValidator.validators.siren = {
  3907. /**
  3908. * Check if a string is a siren number
  3909. *
  3910. * @param {BootstrapValidator} validator The validator plugin instance
  3911. * @param {jQuery} $field Field element
  3912. * @param {Object} options Consist of key:
  3913. * - message: The invalid message
  3914. * @returns {Boolean}
  3915. */
  3916. validate: function(validator, $field, options) {
  3917. var value = $field.val();
  3918. if (value === '') {
  3919. return true;
  3920. }
  3921. if (!/^\d{9}$/.test(value)) {
  3922. return false;
  3923. }
  3924. return $.fn.bootstrapValidator.helpers.luhn(value);
  3925. }
  3926. };
  3927. }(window.jQuery));
  3928. ;(function($) {
  3929. $.fn.bootstrapValidator.i18n.siret = $.extend($.fn.bootstrapValidator.i18n.siret || {}, {
  3930. 'default': 'Please enter a valid SIRET number'
  3931. });
  3932. $.fn.bootstrapValidator.validators.siret = {
  3933. /**
  3934. * Check if a string is a siret number
  3935. *
  3936. * @param {BootstrapValidator} validator The validator plugin instance
  3937. * @param {jQuery} $field Field element
  3938. * @param {Object} options Consist of key:
  3939. * - message: The invalid message
  3940. * @returns {Boolean}
  3941. */
  3942. validate: function(validator, $field, options) {
  3943. var value = $field.val();
  3944. if (value === '') {
  3945. return true;
  3946. }
  3947. var sum = 0,
  3948. length = value.length,
  3949. tmp;
  3950. for (var i = 0; i < length; i++) {
  3951. tmp = parseInt(value.charAt(i), 10);
  3952. if ((i % 2) === 0) {
  3953. tmp = tmp * 2;
  3954. if (tmp > 9) {
  3955. tmp -= 9;
  3956. }
  3957. }
  3958. sum += tmp;
  3959. }
  3960. return (sum % 10 === 0);
  3961. }
  3962. };
  3963. }(window.jQuery));
  3964. ;(function($) {
  3965. $.fn.bootstrapValidator.i18n.step = $.extend($.fn.bootstrapValidator.i18n.step || {}, {
  3966. 'default': 'Please enter a valid step of %s',
  3967. getMessage: function(options) {
  3968. return $.fn.bootstrapValidator.helpers.format(this['default'], [options.step]);
  3969. }
  3970. });
  3971. $.fn.bootstrapValidator.validators.step = {
  3972. html5Attributes: {
  3973. message: 'message',
  3974. base: 'baseValue',
  3975. step: 'step'
  3976. },
  3977. /**
  3978. * Return true if the input value is valid step one
  3979. *
  3980. * @param {BootstrapValidator} validator The validator plugin instance
  3981. * @param {jQuery} $field Field element
  3982. * @param {Object} options Can consist of the following keys:
  3983. * - baseValue: The base value
  3984. * - step: The step
  3985. * - message: The invalid message
  3986. * @returns {Boolean}
  3987. */
  3988. validate: function(validator, $field, options) {
  3989. var value = $field.val();
  3990. if (value === '') {
  3991. return true;
  3992. }
  3993. options = $.extend({}, { baseValue: 0, step: 1 }, options);
  3994. value = parseFloat(value);
  3995. if (isNaN(value) || !isFinite(value)) {
  3996. return false;
  3997. }
  3998. var round = function(x, precision) {
  3999. var m = Math.pow(10, precision);
  4000. x = x * m;
  4001. var sign = (x > 0) | -(x < 0),
  4002. isHalf = (x % 1 === 0.5 * sign);
  4003. if (isHalf) {
  4004. return (Math.floor(x) + (sign > 0)) / m;
  4005. } else {
  4006. return Math.round(x) / m;
  4007. }
  4008. },
  4009. floatMod = function(x, y) {
  4010. if (y === 0.0) {
  4011. return 1.0;
  4012. }
  4013. var dotX = (x + '').split('.'),
  4014. dotY = (y + '').split('.'),
  4015. precision = ((dotX.length === 1) ? 0 : dotX[1].length) + ((dotY.length === 1) ? 0 : dotY[1].length);
  4016. return round(x - y * Math.floor(x / y), precision);
  4017. };
  4018. var mod = floatMod(value - options.baseValue, options.step);
  4019. return (mod === 0.0 || mod === options.step);
  4020. }
  4021. };
  4022. }(window.jQuery));
  4023. ;(function($) {
  4024. $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
  4025. 'default': 'Please enter only lowercase characters',
  4026. upper: 'Please enter only uppercase characters',
  4027. getMessage: function(options) {
  4028. var stringCase = (options['case'] || 'lower').toLowerCase();
  4029. return ('upper' === stringCase) ? this.upper : this['default'];
  4030. }
  4031. });
  4032. $.fn.bootstrapValidator.validators.stringCase = {
  4033. html5Attributes: {
  4034. message: 'message',
  4035. 'case': 'case'
  4036. },
  4037. /**
  4038. * Check if a string is a lower or upper case one
  4039. *
  4040. * @param {BootstrapValidator} validator The validator plugin instance
  4041. * @param {jQuery} $field Field element
  4042. * @param {Object} options Consist of key:
  4043. * - message: The invalid message
  4044. * - case: Can be 'lower' (default) or 'upper'
  4045. * @returns {Boolean}
  4046. */
  4047. validate: function(validator, $field, options) {
  4048. var value = $field.val();
  4049. if (value === '') {
  4050. return true;
  4051. }
  4052. var stringCase = (options['case'] || 'lower').toLowerCase();
  4053. return ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase();
  4054. }
  4055. };
  4056. }(window.jQuery));
  4057. ;(function($) {
  4058. $.fn.bootstrapValidator.i18n.stringLength = $.extend($.fn.bootstrapValidator.i18n.stringLength || {}, {
  4059. 'default': 'Please enter a value with valid length',
  4060. less: 'Please enter less than %s characters',
  4061. more: 'Please enter more than %s characters',
  4062. between: 'Please enter value between %s and %s characters long',
  4063. getMessage: function(options) {
  4064. switch (true) {
  4065. case (!!options.min && !!options.max):
  4066. return $.fn.bootstrapValidator.helpers.format(this.between, [options.min, options.max]);
  4067. case (!!options.min):
  4068. return $.fn.bootstrapValidator.helpers.format(this.more, options.min);
  4069. case (!!options.max):
  4070. return $.fn.bootstrapValidator.helpers.format(this.less, options.max);
  4071. default:
  4072. return this['default'];
  4073. }
  4074. }
  4075. });
  4076. $.fn.bootstrapValidator.validators.stringLength = {
  4077. html5Attributes: {
  4078. message: 'message',
  4079. min: 'min',
  4080. max: 'max'
  4081. },
  4082. enableByHtml5: function($field) {
  4083. var maxLength = $field.attr('maxlength');
  4084. if (maxLength) {
  4085. return {
  4086. max: parseInt(maxLength, 10)
  4087. };
  4088. }
  4089. return false;
  4090. },
  4091. /**
  4092. * Check if the length of element value is less or more than given number
  4093. *
  4094. * @param {BootstrapValidator} validator The validator plugin instance
  4095. * @param {jQuery} $field Field element
  4096. * @param {Object} options Consists of following keys:
  4097. * - min
  4098. * - max
  4099. * At least one of two keys is required
  4100. * - message: The invalid message
  4101. * @returns {Boolean}
  4102. */
  4103. validate: function(validator, $field, options) {
  4104. var value = $field.val();
  4105. if (value === '') {
  4106. return true;
  4107. }
  4108. var length = value.length;
  4109. if ((options.min && length < options.min) || (options.max && length > options.max)) {
  4110. return false;
  4111. }
  4112. return true;
  4113. }
  4114. };
  4115. }(window.jQuery));
  4116. ;(function($) {
  4117. $.fn.bootstrapValidator.i18n.uri = $.extend($.fn.bootstrapValidator.i18n.uri || {}, {
  4118. 'default': 'Please enter a valid URI'
  4119. });
  4120. $.fn.bootstrapValidator.validators.uri = {
  4121. html5Attributes: {
  4122. message: 'message',
  4123. allowlocal: 'allowLocal'
  4124. },
  4125. enableByHtml5: function($field) {
  4126. return ('url' === $field.attr('type'));
  4127. },
  4128. /**
  4129. * Return true if the input value is a valid URL
  4130. *
  4131. * @param {BootstrapValidator} validator The validator plugin instance
  4132. * @param {jQuery} $field Field element
  4133. * @param {Object} options
  4134. * - message: The error message
  4135. * - allowLocal: Allow the private and local network IP. Default to false
  4136. * @returns {Boolean}
  4137. */
  4138. validate: function(validator, $field, options) {
  4139. var value = $field.val();
  4140. if (value === '') {
  4141. return true;
  4142. }
  4143. // Credit to https://gist.github.com/dperini/729294
  4144. //
  4145. // Regular Expression for URL validation
  4146. //
  4147. // Author: Diego Perini
  4148. // Updated: 2010/12/05
  4149. //
  4150. // the regular expression composed & commented
  4151. // could be easily tweaked for RFC compliance,
  4152. // it was expressly modified to fit & satisfy
  4153. // these test for an URL shortener:
  4154. //
  4155. // http://mathiasbynens.be/demo/url-regex
  4156. //
  4157. // Notes on possible differences from a standard/generic validation:
  4158. //
  4159. // - utf-8 char class take in consideration the full Unicode range
  4160. // - TLDs have been made mandatory so single names like "localhost" fails
  4161. // - protocols have been restricted to ftp, http and https only as requested
  4162. //
  4163. // Changes:
  4164. //
  4165. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  4166. // first and last IP address of each class is considered invalid
  4167. // (since they are broadcast/network addresses)
  4168. //
  4169. // - Added exclusion of private, reserved and/or local networks ranges
  4170. //
  4171. var allowLocal = options.allowLocal === true || options.allowLocal === 'true',
  4172. urlExp = new RegExp(
  4173. "^" +
  4174. // protocol identifier
  4175. "(?:(?:https?|ftp)://)" +
  4176. // user:pass authentication
  4177. "(?:\\S+(?::\\S*)?@)?" +
  4178. "(?:" +
  4179. // IP address exclusion
  4180. // private & local networks
  4181. (allowLocal
  4182. ? ''
  4183. : ("(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
  4184. "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
  4185. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})")) +
  4186. // IP address dotted notation octets
  4187. // excludes loopback network 0.0.0.0
  4188. // excludes reserved space >= 224.0.0.0
  4189. // excludes network & broadcast addresses
  4190. // (first & last IP address of each class)
  4191. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  4192. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  4193. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  4194. "|" +
  4195. // host name
  4196. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  4197. // domain name
  4198. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  4199. // TLD identifier
  4200. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  4201. ")" +
  4202. // port number
  4203. "(?::\\d{2,5})?" +
  4204. // resource path
  4205. "(?:/[^\\s]*)?" +
  4206. "$", "i"
  4207. );
  4208. return urlExp.test(value);
  4209. }
  4210. };
  4211. }(window.jQuery));
  4212. ;(function($) {
  4213. $.fn.bootstrapValidator.i18n.uuid = $.extend($.fn.bootstrapValidator.i18n.uuid || {}, {
  4214. 'default': 'Please enter a valid UUID number',
  4215. version: 'Please enter a valid UUID version %s number',
  4216. getMessage: function(options) {
  4217. return (options.version)
  4218. ? $.fn.bootstrapValidator.helpers.format(this.version, [options.version])
  4219. : this['default'];
  4220. }
  4221. });
  4222. $.fn.bootstrapValidator.validators.uuid = {
  4223. html5Attributes: {
  4224. message: 'message',
  4225. version: 'version'
  4226. },
  4227. /**
  4228. * Return true if and only if the input value is a valid UUID string
  4229. *
  4230. * @see http://en.wikipedia.org/wiki/Universally_unique_identifier
  4231. * @param {BootstrapValidator} validator The validator plugin instance
  4232. * @param {jQuery} $field Field element
  4233. * @param {Object} options Consist of key:
  4234. * - message: The invalid message
  4235. * - version: Can be 3, 4, 5, null
  4236. * @returns {Boolean}
  4237. */
  4238. validate: function(validator, $field, options) {
  4239. var value = $field.val();
  4240. if (value === '') {
  4241. return true;
  4242. }
  4243. // See the format at http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions
  4244. var patterns = {
  4245. '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
  4246. '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  4247. '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
  4248. all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
  4249. },
  4250. version = options.version ? (options.version + '') : 'all';
  4251. return (null === patterns[version]) ? true : patterns[version].test(value);
  4252. }
  4253. };
  4254. }(window.jQuery));
  4255. ;(function($) {
  4256. $.fn.bootstrapValidator.i18n.vat = $.extend($.fn.bootstrapValidator.i18n.vat || {}, {
  4257. 'default': 'Please enter a valid VAT number',
  4258. countryNotSupported: 'The country code %s is not supported',
  4259. country: 'Please enter a valid %s VAT number',
  4260. countries: {
  4261. AT: 'Austrian',
  4262. BE: 'Belgian',
  4263. BG: 'Bulgarian',
  4264. CH: 'Swiss',
  4265. CY: 'Cypriot',
  4266. CZ: 'Czech',
  4267. DE: 'German',
  4268. DK: 'Danish',
  4269. EE: 'Estonian',
  4270. ES: 'Spanish',
  4271. FI: 'Finnish',
  4272. FR: 'French',
  4273. GB: 'United Kingdom',
  4274. GR: 'Greek',
  4275. EL: 'Greek',
  4276. HU: 'Hungarian',
  4277. HR: 'Croatian',
  4278. IE: 'Irish',
  4279. IT: 'Italian',
  4280. LT: 'Lithuanian',
  4281. LU: 'Luxembourg',
  4282. LV: 'Latvian',
  4283. MT: 'Maltese',
  4284. NL: 'Dutch',
  4285. NO: 'Norwegian',
  4286. PL: 'Polish',
  4287. PT: 'Portuguese',
  4288. RO: 'Romanian',
  4289. RU: 'Russian',
  4290. RS: 'Serbian',
  4291. SE: 'Swedish',
  4292. SI: 'Slovenian',
  4293. SK: 'Slovak'
  4294. },
  4295. getMessage: function(options) {
  4296. if (options.country) {
  4297. var country = options.country,
  4298. method = ['_', country.toLowerCase()].join('');
  4299. if ($.fn.bootstrapValidator.validators.vat[method] === undefined) {
  4300. return $.fn.bootstrapValidator.helpers.format(this.countryNotSupported, options.country);
  4301. }
  4302. country = country.toUpperCase();
  4303. if (this.countries[country]) {
  4304. return $.fn.bootstrapValidator.helpers.format(this.country, this.countries[country]);
  4305. }
  4306. }
  4307. return this['default'];
  4308. }
  4309. });
  4310. $.fn.bootstrapValidator.validators.vat = {
  4311. html5Attributes: {
  4312. message: 'message',
  4313. country: 'country'
  4314. },
  4315. /**
  4316. * Validate an European VAT number
  4317. *
  4318. * @param {BootstrapValidator} validator The validator plugin instance
  4319. * @param {jQuery} $field Field element
  4320. * @param {Object} options Consist of key:
  4321. * - message: The invalid message
  4322. * - country: The ISO 3166-1 country code
  4323. * @returns {Boolean}
  4324. */
  4325. validate: function(validator, $field, options) {
  4326. var value = $field.val();
  4327. if (value === '') {
  4328. return true;
  4329. }
  4330. var country = options.country || value.substr(0, 2),
  4331. method = ['_', country.toLowerCase()].join('');
  4332. if (this[method] && 'function' === typeof this[method]) {
  4333. return this[method](value);
  4334. }
  4335. return false;
  4336. },
  4337. // VAT validators
  4338. /**
  4339. * Validate Austrian VAT number
  4340. * Example:
  4341. * - Valid: ATU13585627
  4342. * - Invalid: ATU13585626
  4343. *
  4344. * @param {String} value VAT number
  4345. * @returns {Boolean}
  4346. */
  4347. _at: function(value) {
  4348. if (!/^ATU[0-9]{8}$/.test(value)) {
  4349. return false;
  4350. }
  4351. value = value.substr(3);
  4352. var sum = 0,
  4353. weight = [1, 2, 1, 2, 1, 2, 1],
  4354. temp = 0;
  4355. for (var i = 0; i < 7; i++) {
  4356. temp = parseInt(value.charAt(i), 10) * weight[i];
  4357. if (temp > 9) {
  4358. temp = Math.floor(temp / 10) + temp % 10;
  4359. }
  4360. sum += temp;
  4361. }
  4362. sum = 10 - (sum + 4) % 10;
  4363. if (sum === 10) {
  4364. sum = 0;
  4365. }
  4366. return (sum + '' === value.substr(7, 1));
  4367. },
  4368. /**
  4369. * Validate Belgian VAT number
  4370. * Example:
  4371. * - Valid: BE0428759497
  4372. * - Invalid: BE431150351
  4373. *
  4374. * @param {String} value VAT number
  4375. * @returns {Boolean}
  4376. */
  4377. _be: function(value) {
  4378. if (!/^BE[0]{0,1}[0-9]{9}$/.test(value)) {
  4379. return false;
  4380. }
  4381. value = value.substr(2);
  4382. if (value.length === 9) {
  4383. value = '0' + value;
  4384. }
  4385. if (value.substr(1, 1) === '0') {
  4386. return false;
  4387. }
  4388. var sum = parseInt(value.substr(0, 8), 10) + parseInt(value.substr(8, 2), 10);
  4389. return (sum % 97 === 0);
  4390. },
  4391. /**
  4392. * Validate Bulgarian VAT number
  4393. * Example:
  4394. * - Valid: BG175074752,
  4395. * BG7523169263, BG8032056031,
  4396. * BG7542011030,
  4397. * BG7111042925
  4398. * - Invalid: BG175074753, BG7552A10004, BG7111042922
  4399. *
  4400. * @param {String} value VAT number
  4401. * @returns {Boolean}
  4402. */
  4403. _bg: function(value) {
  4404. if (!/^BG[0-9]{9,10}$/.test(value)) {
  4405. return false;
  4406. }
  4407. value = value.substr(2);
  4408. var sum = 0, i = 0;
  4409. // Legal entities
  4410. if (value.length === 9) {
  4411. for (i = 0; i < 8; i++) {
  4412. sum += parseInt(value.charAt(i), 10) * (i + 1);
  4413. }
  4414. sum = sum % 11;
  4415. if (sum === 10) {
  4416. sum = 0;
  4417. for (i = 0; i < 8; i++) {
  4418. sum += parseInt(value.charAt(i), 10) * (i + 3);
  4419. }
  4420. }
  4421. sum = sum % 10;
  4422. return (sum + '' === value.substr(8));
  4423. }
  4424. // Physical persons, foreigners and others
  4425. else if (value.length === 10) {
  4426. // Validate Bulgarian national identification numbers
  4427. var egn = function(value) {
  4428. // Check the birth date
  4429. var year = parseInt(value.substr(0, 2), 10) + 1900,
  4430. month = parseInt(value.substr(2, 2), 10),
  4431. day = parseInt(value.substr(4, 2), 10);
  4432. if (month > 40) {
  4433. year += 100;
  4434. month -= 40;
  4435. } else if (month > 20) {
  4436. year -= 100;
  4437. month -= 20;
  4438. }
  4439. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4440. return false;
  4441. }
  4442. var sum = 0,
  4443. weight = [2, 4, 8, 5, 10, 9, 7, 3, 6];
  4444. for (var i = 0; i < 9; i++) {
  4445. sum += parseInt(value.charAt(i), 10) * weight[i];
  4446. }
  4447. sum = (sum % 11) % 10;
  4448. return (sum + '' === value.substr(9, 1));
  4449. },
  4450. // Validate Bulgarian personal number of a foreigner
  4451. pnf = function(value) {
  4452. var sum = 0,
  4453. weight = [21, 19, 17, 13, 11, 9, 7, 3, 1];
  4454. for (var i = 0; i < 9; i++) {
  4455. sum += parseInt(value.charAt(i), 10) * weight[i];
  4456. }
  4457. sum = sum % 10;
  4458. return (sum + '' === value.substr(9, 1));
  4459. },
  4460. // Finally, consider it as a VAT number
  4461. vat = function(value) {
  4462. var sum = 0,
  4463. weight = [4, 3, 2, 7, 6, 5, 4, 3, 2];
  4464. for (var i = 0; i < 9; i++) {
  4465. sum += parseInt(value.charAt(i), 10) * weight[i];
  4466. }
  4467. sum = 11 - sum % 11;
  4468. if (sum === 10) {
  4469. return false;
  4470. }
  4471. if (sum === 11) {
  4472. sum = 0;
  4473. }
  4474. return (sum + '' === value.substr(9, 1));
  4475. };
  4476. return (egn(value) || pnf(value) || vat(value));
  4477. }
  4478. return false;
  4479. },
  4480. /**
  4481. * Validate Swiss VAT number
  4482. *
  4483. * @param {String} value VAT number
  4484. * @returns {Boolean}
  4485. */
  4486. _ch: function(value) {
  4487. if (!/^CHE[0-9]{9}(MWST)?$/.test(value)) {
  4488. return false;
  4489. }
  4490. value = value.substr(3);
  4491. var sum = 0,
  4492. weight = [5, 4, 3, 2, 7, 6, 5, 4];
  4493. for (var i = 0; i < 8; i++) {
  4494. sum += parseInt(value.charAt(i), 10) * weight[i];
  4495. }
  4496. sum = 11 - sum % 11;
  4497. if (sum === 10) {
  4498. return false;
  4499. }
  4500. if (sum === 11) {
  4501. sum = 0;
  4502. }
  4503. return (sum + '' === value.substr(8, 1));
  4504. },
  4505. /**
  4506. * Validate Cypriot VAT number
  4507. * Examples:
  4508. * - Valid: CY10259033P
  4509. * - Invalid: CY10259033Z
  4510. *
  4511. * @param {String} value VAT number
  4512. * @returns {Boolean}
  4513. */
  4514. _cy: function(value) {
  4515. if (!/^CY[0-5|9]{1}[0-9]{7}[A-Z]{1}$/.test(value)) {
  4516. return false;
  4517. }
  4518. value = value.substr(2);
  4519. // Do not allow to start with "12"
  4520. if (value.substr(0, 2) === '12') {
  4521. return false;
  4522. }
  4523. // Extract the next digit and multiply by the counter.
  4524. var sum = 0,
  4525. translation = {
  4526. '0': 1, '1': 0, '2': 5, '3': 7, '4': 9,
  4527. '5': 13, '6': 15, '7': 17, '8': 19, '9': 21
  4528. };
  4529. for (var i = 0; i < 8; i++) {
  4530. var temp = parseInt(value.charAt(i), 10);
  4531. if (i % 2 === 0) {
  4532. temp = translation[temp + ''];
  4533. }
  4534. sum += temp;
  4535. }
  4536. sum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[sum % 26];
  4537. return (sum + '' === value.substr(8, 1));
  4538. },
  4539. /**
  4540. * Validate Czech Republic VAT number
  4541. * Can be:
  4542. * i) Legal entities (8 digit numbers)
  4543. * ii) Individuals with a RC (the 9 or 10 digit Czech birth number)
  4544. * iii) Individuals without a RC (9 digit numbers beginning with 6)
  4545. *
  4546. * Examples:
  4547. * - Valid: i) CZ25123891; ii) CZ7103192745, CZ991231123; iii) CZ640903926
  4548. * - Invalid: i) CZ25123890; ii) CZ1103492745, CZ590312123
  4549. *
  4550. * @param {String} value VAT number
  4551. * @returns {Boolean}
  4552. */
  4553. _cz: function(value) {
  4554. if (!/^CZ[0-9]{8,10}$/.test(value)) {
  4555. return false;
  4556. }
  4557. value = value.substr(2);
  4558. var sum = 0,
  4559. i = 0;
  4560. if (value.length === 8) {
  4561. // Do not allow to start with '9'
  4562. if (value.charAt(0) + '' === '9') {
  4563. return false;
  4564. }
  4565. sum = 0;
  4566. for (i = 0; i < 7; i++) {
  4567. sum += parseInt(value.charAt(i), 10) * (8 - i);
  4568. }
  4569. sum = 11 - sum % 11;
  4570. if (sum === 10) {
  4571. sum = 0;
  4572. }
  4573. if (sum === 11) {
  4574. sum = 1;
  4575. }
  4576. return (sum + '' === value.substr(7, 1));
  4577. } else if (value.length === 9 && (value.charAt(0) + '' === '6')) {
  4578. sum = 0;
  4579. // Skip the first (which is 6)
  4580. for (i = 0; i < 7; i++) {
  4581. sum += parseInt(value.charAt(i + 1), 10) * (8 - i);
  4582. }
  4583. sum = 11 - sum % 11;
  4584. if (sum === 10) {
  4585. sum = 0;
  4586. }
  4587. if (sum === 11) {
  4588. sum = 1;
  4589. }
  4590. sum = [8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 10][sum - 1];
  4591. return (sum + '' === value.substr(8, 1));
  4592. } else if (value.length === 9 || value.length === 10) {
  4593. // Validate Czech birth number (Rodné číslo), which is also national identifier
  4594. var year = 1900 + parseInt(value.substr(0, 2), 10),
  4595. month = parseInt(value.substr(2, 2), 10) % 50 % 20,
  4596. day = parseInt(value.substr(4, 2), 10);
  4597. if (value.length === 9) {
  4598. if (year >= 1980) {
  4599. year -= 100;
  4600. }
  4601. if (year > 1953) {
  4602. return false;
  4603. }
  4604. } else if (year < 1954) {
  4605. year += 100;
  4606. }
  4607. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  4608. return false;
  4609. }
  4610. // Check that the birth date is not in the future
  4611. if (value.length === 10) {
  4612. var check = parseInt(value.substr(0, 9), 10) % 11;
  4613. if (year < 1985) {
  4614. check = check % 10;
  4615. }
  4616. return (check + '' === value.substr(9, 1));
  4617. }
  4618. return true;
  4619. }
  4620. return false;
  4621. },
  4622. /**
  4623. * Validate German VAT number
  4624. * Examples:
  4625. * - Valid: DE136695976
  4626. * - Invalid: DE136695978
  4627. *
  4628. * @param {String} value VAT number
  4629. * @returns {Boolean}
  4630. */
  4631. _de: function(value) {
  4632. if (!/^DE[0-9]{9}$/.test(value)) {
  4633. return false;
  4634. }
  4635. value = value.substr(2);
  4636. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  4637. },
  4638. /**
  4639. * Validate Danish VAT number
  4640. * Example:
  4641. * - Valid: DK13585628
  4642. * - Invalid: DK13585627
  4643. *
  4644. * @param {String} value VAT number
  4645. * @returns {Boolean}
  4646. */
  4647. _dk: function(value) {
  4648. if (!/^DK[0-9]{8}$/.test(value)) {
  4649. return false;
  4650. }
  4651. value = value.substr(2);
  4652. var sum = 0,
  4653. weight = [2, 7, 6, 5, 4, 3, 2, 1];
  4654. for (var i = 0; i < 8; i++) {
  4655. sum += parseInt(value.charAt(i), 10) * weight[i];
  4656. }
  4657. return (sum % 11 === 0);
  4658. },
  4659. /**
  4660. * Validate Estonian VAT number
  4661. * Examples:
  4662. * - Valid: EE100931558, EE100594102
  4663. * - Invalid: EE100594103
  4664. *
  4665. * @param {String} value VAT number
  4666. * @returns {Boolean}
  4667. */
  4668. _ee: function(value) {
  4669. if (!/^EE[0-9]{9}$/.test(value)) {
  4670. return false;
  4671. }
  4672. value = value.substr(2);
  4673. var sum = 0,
  4674. weight = [3, 7, 1, 3, 7, 1, 3, 7, 1];
  4675. for (var i = 0; i < 9; i++) {
  4676. sum += parseInt(value.charAt(i), 10) * weight[i];
  4677. }
  4678. return (sum % 10 === 0);
  4679. },
  4680. /**
  4681. * Validate Spanish VAT number (NIF - Número de Identificación Fiscal)
  4682. * Can be:
  4683. * i) DNI (Documento nacional de identidad), for Spaniards
  4684. * ii) NIE (Número de Identificación de Extranjeros), for foreigners
  4685. * iii) CIF (Certificado de Identificación Fiscal), for legal entities and others
  4686. *
  4687. * Examples:
  4688. * - Valid: i) ES54362315K; ii) ESX2482300W, ESX5253868R; iii) ESM1234567L, ESJ99216582, ESB58378431, ESB64717838
  4689. * - Invalid: i) ES54362315Z; ii) ESX2482300A; iii) ESJ99216583
  4690. *
  4691. * @param {String} value VAT number
  4692. * @returns {Boolean}
  4693. */
  4694. _es: function(value) {
  4695. if (!/^ES[0-9A-Z][0-9]{7}[0-9A-Z]$/.test(value)) {
  4696. return false;
  4697. }
  4698. value = value.substr(2);
  4699. var dni = function(value) {
  4700. var check = parseInt(value.substr(0, 8), 10);
  4701. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4702. return (check + '' === value.substr(8, 1));
  4703. },
  4704. nie = function(value) {
  4705. var check = ['XYZ'.indexOf(value.charAt(0)), value.substr(1)].join('');
  4706. check = parseInt(check, 10);
  4707. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4708. return (check + '' === value.substr(8, 1));
  4709. },
  4710. cif = function(value) {
  4711. var first = value.charAt(0), check;
  4712. if ('KLM'.indexOf(first) !== -1) {
  4713. // K: Spanish younger than 14 year old
  4714. // L: Spanish living outside Spain without DNI
  4715. // M: Granted the tax to foreigners who have no NIE
  4716. check = parseInt(value.substr(1, 8), 10);
  4717. check = 'TRWAGMYFPDXBNJZSQVHLCKE'[check % 23];
  4718. return (check + '' === value.substr(8, 1));
  4719. } else if ('ABCDEFGHJNPQRSUVW'.indexOf(first) !== -1) {
  4720. var sum = 0,
  4721. weight = [2, 1, 2, 1, 2, 1, 2],
  4722. temp = 0;
  4723. for (var i = 0; i < 7; i++) {
  4724. temp = parseInt(value.charAt(i + 1), 10) * weight[i];
  4725. if (temp > 9) {
  4726. temp = Math.floor(temp / 10) + temp % 10;
  4727. }
  4728. sum += temp;
  4729. }
  4730. sum = 10 - sum % 10;
  4731. return (sum + '' === value.substr(8, 1) || 'JABCDEFGHI'[sum] === value.substr(8, 1));
  4732. }
  4733. return false;
  4734. };
  4735. var first = value.charAt(0);
  4736. if (/^[0-9]$/.test(first)) {
  4737. return dni(value);
  4738. } else if (/^[XYZ]$/.test(first)) {
  4739. return nie(value);
  4740. } else {
  4741. return cif(value);
  4742. }
  4743. },
  4744. /**
  4745. * Validate Finnish VAT number
  4746. * Examples:
  4747. * - Valid: FI20774740
  4748. * - Invalid: FI20774741
  4749. *
  4750. * @param {String} value VAT number
  4751. * @returns {Boolean}
  4752. */
  4753. _fi: function(value) {
  4754. if (!/^FI[0-9]{8}$/.test(value)) {
  4755. return false;
  4756. }
  4757. value = value.substr(2);
  4758. var sum = 0,
  4759. weight = [7, 9, 10, 5, 8, 4, 2, 1];
  4760. for (var i = 0; i < 8; i++) {
  4761. sum += parseInt(value.charAt(i), 10) * weight[i];
  4762. }
  4763. return (sum % 11 === 0);
  4764. },
  4765. /**
  4766. * Validate French VAT number (TVA - taxe sur la valeur ajoutée)
  4767. * It's constructed by a SIREN number, prefixed by two characters.
  4768. *
  4769. * Examples:
  4770. * - Valid: FR40303265045, FR23334175221, FRK7399859412, FR4Z123456782
  4771. * - Invalid: FR84323140391
  4772. *
  4773. * @param {String} value VAT number
  4774. * @returns {Boolean}
  4775. */
  4776. _fr: function(value) {
  4777. if (!/^FR[0-9A-Z]{2}[0-9]{9}$/.test(value)) {
  4778. return false;
  4779. }
  4780. value = value.substr(2);
  4781. if (!$.fn.bootstrapValidator.helpers.luhn(value.substr(2))) {
  4782. return false;
  4783. }
  4784. if (/^[0-9]{2}$/.test(value.substr(0, 2))) {
  4785. // First two characters are digits
  4786. return value.substr(0, 2) === (parseInt(value.substr(2) + '12', 10) % 97 + '');
  4787. } else {
  4788. // The first characters cann't be O and I
  4789. var alphabet = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ',
  4790. check;
  4791. // First one is digit
  4792. if (/^[0-9]{1}$/.test(value.charAt(0))) {
  4793. check = alphabet.indexOf(value.charAt(0)) * 24 + alphabet.indexOf(value.charAt(1)) - 10;
  4794. } else {
  4795. check = alphabet.indexOf(value.charAt(0)) * 34 + alphabet.indexOf(value.charAt(1)) - 100;
  4796. }
  4797. return ((parseInt(value.substr(2), 10) + 1 + Math.floor(check / 11)) % 11) === (check % 11);
  4798. }
  4799. },
  4800. /**
  4801. * Validate United Kingdom VAT number
  4802. * Example:
  4803. * - Valid: GB980780684
  4804. * - Invalid: GB802311781
  4805. *
  4806. * @param {String} value VAT number
  4807. * @returns {Boolean}
  4808. */
  4809. _gb: function(value) {
  4810. if (!/^GB[0-9]{9}$/.test(value) /* Standard */
  4811. && !/^GB[0-9]{12}$/.test(value) /* Branches */
  4812. && !/^GBGD[0-9]{3}$/.test(value) /* Government department */
  4813. && !/^GBHA[0-9]{3}$/.test(value) /* Health authority */
  4814. && !/^GB(GD|HA)8888[0-9]{5}$/.test(value))
  4815. {
  4816. return false;
  4817. }
  4818. value = value.substr(2);
  4819. var length = value.length;
  4820. if (length === 5) {
  4821. var firstTwo = value.substr(0, 2),
  4822. lastThree = parseInt(value.substr(2), 10);
  4823. return ('GD' === firstTwo && lastThree < 500) || ('HA' === firstTwo && lastThree >= 500);
  4824. } else if (length === 11 && ('GD8888' === value.substr(0, 6) || 'HA8888' === value.substr(0, 6))) {
  4825. if (('GD' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) >= 500)
  4826. || ('HA' === value.substr(0, 2) && parseInt(value.substr(6, 3), 10) < 500))
  4827. {
  4828. return false;
  4829. }
  4830. return (parseInt(value.substr(6, 3), 10) % 97 === parseInt(value.substr(9, 2), 10));
  4831. } else if (length === 9 || length === 12) {
  4832. var sum = 0,
  4833. weight = [8, 7, 6, 5, 4, 3, 2, 10, 1];
  4834. for (var i = 0; i < 9; i++) {
  4835. sum += parseInt(value.charAt(i), 10) * weight[i];
  4836. }
  4837. sum = sum % 97;
  4838. if (parseInt(value.substr(0, 3), 10) >= 100) {
  4839. return (sum === 0 || sum === 42 || sum === 55);
  4840. } else {
  4841. return (sum === 0);
  4842. }
  4843. }
  4844. return true;
  4845. },
  4846. /**
  4847. * Validate Greek VAT number
  4848. * Examples:
  4849. * - Valid: GR023456780, EL094259216
  4850. * - Invalid: EL123456781
  4851. *
  4852. * @param {String} value VAT number
  4853. * @returns {Boolean}
  4854. */
  4855. _gr: function(value) {
  4856. if (!/^GR[0-9]{9}$/.test(value)) {
  4857. return false;
  4858. }
  4859. value = value.substr(2);
  4860. if (value.length === 8) {
  4861. value = '0' + value;
  4862. }
  4863. var sum = 0,
  4864. weight = [256, 128, 64, 32, 16, 8, 4, 2];
  4865. for (var i = 0; i < 8; i++) {
  4866. sum += parseInt(value.charAt(i), 10) * weight[i];
  4867. }
  4868. sum = (sum % 11) % 10;
  4869. return (sum + '' === value.substr(8, 1));
  4870. },
  4871. // EL is traditionally prefix of Greek VAT numbers
  4872. _el: function(value) {
  4873. if (!/^EL[0-9]{9}$/.test(value)) {
  4874. return false;
  4875. }
  4876. value = 'GR' + value.substr(2);
  4877. return this._gr(value);
  4878. },
  4879. /**
  4880. * Validate Hungarian VAT number
  4881. * Examples:
  4882. * - Valid: HU12892312
  4883. * - Invalid: HU12892313
  4884. *
  4885. * @param {String} value VAT number
  4886. * @returns {Boolean}
  4887. */
  4888. _hu: function(value) {
  4889. if (!/^HU[0-9]{8}$/.test(value)) {
  4890. return false;
  4891. }
  4892. value = value.substr(2);
  4893. var sum = 0,
  4894. weight = [9, 7, 3, 1, 9, 7, 3, 1];
  4895. for (var i = 0; i < 8; i++) {
  4896. sum += parseInt(value.charAt(i), 10) * weight[i];
  4897. }
  4898. return (sum % 10 === 0);
  4899. },
  4900. /**
  4901. * Validate Croatian VAT number
  4902. * Examples:
  4903. * - Valid: HR33392005961
  4904. * - Invalid: HR33392005962
  4905. *
  4906. * @param {String} value VAT number
  4907. * @returns {Boolean}
  4908. */
  4909. _hr: function(value) {
  4910. if (!/^HR[0-9]{11}$/.test(value)) {
  4911. return false;
  4912. }
  4913. value = value.substr(2);
  4914. return $.fn.bootstrapValidator.helpers.mod11And10(value);
  4915. },
  4916. /**
  4917. * Validate Irish VAT number
  4918. * Examples:
  4919. * - Valid: IE6433435F, IE6433435OA, IE8D79739I
  4920. * - Invalid: IE8D79738J
  4921. *
  4922. * @param {String} value VAT number
  4923. * @returns {Boolean}
  4924. */
  4925. _ie: function(value) {
  4926. if (!/^IE[0-9]{1}[0-9A-Z\*\+]{1}[0-9]{5}[A-Z]{1,2}$/.test(value)) {
  4927. return false;
  4928. }
  4929. value = value.substr(2);
  4930. var getCheckDigit = function(value) {
  4931. while (value.length < 7) {
  4932. value = '0' + value;
  4933. }
  4934. var alphabet = 'WABCDEFGHIJKLMNOPQRSTUV',
  4935. sum = 0;
  4936. for (var i = 0; i < 7; i++) {
  4937. sum += parseInt(value.charAt(i), 10) * (8 - i);
  4938. }
  4939. sum += 9 * alphabet.indexOf(value.substr(7));
  4940. return alphabet[sum % 23];
  4941. };
  4942. // The first 7 characters are digits
  4943. if (/^[0-9]+$/.test(value.substr(0, 7))) {
  4944. // New system
  4945. return value.charAt(7) === getCheckDigit(value.substr(0, 7) + value.substr(8) + '');
  4946. } else if ('ABCDEFGHIJKLMNOPQRSTUVWXYZ+*'.indexOf(value.charAt(1)) !== -1) {
  4947. // Old system
  4948. return value.charAt(7) === getCheckDigit(value.substr(2, 5) + value.substr(0, 1) + '');
  4949. }
  4950. return true;
  4951. },
  4952. /**
  4953. * Validate Italian VAT number, which consists of 11 digits.
  4954. * - First 7 digits are a company identifier
  4955. * - Next 3 are the province of residence
  4956. * - The last one is a check digit
  4957. *
  4958. * Examples:
  4959. * - Valid: IT00743110157
  4960. * - Invalid: IT00743110158
  4961. *
  4962. * @param {String} value VAT number
  4963. * @returns {Boolean}
  4964. */
  4965. _it: function(value) {
  4966. if (!/^IT[0-9]{11}$/.test(value)) {
  4967. return false;
  4968. }
  4969. value = value.substr(2);
  4970. if (parseInt(value.substr(0, 7), 10) === 0) {
  4971. return false;
  4972. }
  4973. var lastThree = parseInt(value.substr(7, 3), 10);
  4974. if ((lastThree < 1) || (lastThree > 201) && lastThree !== 999 && lastThree !== 888) {
  4975. return false;
  4976. }
  4977. return $.fn.bootstrapValidator.helpers.luhn(value);
  4978. },
  4979. /**
  4980. * Validate Lithuanian VAT number
  4981. * It can be:
  4982. * - 9 digits, for legal entities
  4983. * - 12 digits, for temporarily registered taxpayers
  4984. *
  4985. * Examples:
  4986. * - Valid: LT119511515, LT100001919017, LT100004801610
  4987. * - Invalid: LT100001919018
  4988. *
  4989. * @param {String} value VAT number
  4990. * @returns {Boolean}
  4991. */
  4992. _lt: function(value) {
  4993. if (!/^LT([0-9]{7}1[0-9]{1}|[0-9]{10}1[0-9]{1})$/.test(value)) {
  4994. return false;
  4995. }
  4996. value = value.substr(2);
  4997. var length = value.length,
  4998. sum = 0,
  4999. i;
  5000. for (i = 0; i < length - 1; i++) {
  5001. sum += parseInt(value.charAt(i), 10) * (1 + i % 9);
  5002. }
  5003. var check = sum % 11;
  5004. if (check === 10) {
  5005. sum = 0;
  5006. for (i = 0; i < length - 1; i++) {
  5007. sum += parseInt(value.charAt(i), 10) * (1 + (i + 2) % 9);
  5008. }
  5009. }
  5010. check = check % 11 % 10;
  5011. return (check + '' === value.charAt(length - 1));
  5012. },
  5013. /**
  5014. * Validate Luxembourg VAT number
  5015. * Examples:
  5016. * - Valid: LU15027442
  5017. * - Invalid: LU15027443
  5018. *
  5019. * @param {String} value VAT number
  5020. * @returns {Boolean}
  5021. */
  5022. _lu: function(value) {
  5023. if (!/^LU[0-9]{8}$/.test(value)) {
  5024. return false;
  5025. }
  5026. value = value.substr(2);
  5027. return ((parseInt(value.substr(0, 6), 10) % 89) + '' === value.substr(6, 2));
  5028. },
  5029. /**
  5030. * Validate Latvian VAT number
  5031. * Examples:
  5032. * - Valid: LV40003521600, LV16117519997
  5033. * - Invalid: LV40003521601, LV16137519997
  5034. *
  5035. * @param {String} value VAT number
  5036. * @returns {Boolean}
  5037. */
  5038. _lv: function(value) {
  5039. if (!/^LV[0-9]{11}$/.test(value)) {
  5040. return false;
  5041. }
  5042. value = value.substr(2);
  5043. var first = parseInt(value.charAt(0), 10),
  5044. sum = 0,
  5045. weight = [],
  5046. i,
  5047. length = value.length;
  5048. if (first > 3) {
  5049. // Legal entity
  5050. sum = 0;
  5051. weight = [9, 1, 4, 8, 3, 10, 2, 5, 7, 6, 1];
  5052. for (i = 0; i < length; i++) {
  5053. sum += parseInt(value.charAt(i), 10) * weight[i];
  5054. }
  5055. sum = sum % 11;
  5056. return (sum === 3);
  5057. } else {
  5058. // Check birth date
  5059. var day = parseInt(value.substr(0, 2), 10),
  5060. month = parseInt(value.substr(2, 2), 10),
  5061. year = parseInt(value.substr(4, 2), 10);
  5062. year = year + 1800 + parseInt(value.charAt(6), 10) * 100;
  5063. if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
  5064. return false;
  5065. }
  5066. // Check personal code
  5067. sum = 0;
  5068. weight = [10, 5, 8, 4, 2, 1, 6, 3, 7, 9];
  5069. for (i = 0; i < length - 1; i++) {
  5070. sum += parseInt(value.charAt(i), 10) * weight[i];
  5071. }
  5072. sum = (sum + 1) % 11 % 10;
  5073. return (sum + '' === value.charAt(length - 1));
  5074. }
  5075. },
  5076. /**
  5077. * Validate Maltese VAT number
  5078. * Examples:
  5079. * - Valid: MT11679112
  5080. * - Invalid: MT11679113
  5081. *
  5082. * @param {String} value VAT number
  5083. * @returns {Boolean}
  5084. */
  5085. _mt: function(value) {
  5086. if (!/^MT[0-9]{8}$/.test(value)) {
  5087. return false;
  5088. }
  5089. value = value.substr(2);
  5090. var sum = 0,
  5091. weight = [3, 4, 6, 7, 8, 9, 10, 1];
  5092. for (var i = 0; i < 8; i++) {
  5093. sum += parseInt(value.charAt(i), 10) * weight[i];
  5094. }
  5095. return (sum % 37 === 0);
  5096. },
  5097. /**
  5098. * Validate Dutch VAT number
  5099. * Examples:
  5100. * - Valid: NL004495445B01
  5101. * - Invalid: NL123456789B90
  5102. *
  5103. * @param {String} value VAT number
  5104. * @returns {Boolean}
  5105. */
  5106. _nl: function(value) {
  5107. if (!/^NL[0-9]{9}B[0-9]{2}$/.test(value)) {
  5108. return false;
  5109. }
  5110. value = value.substr(2);
  5111. var sum = 0,
  5112. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  5113. for (var i = 0; i < 8; i++) {
  5114. sum += parseInt(value.charAt(i), 10) * weight[i];
  5115. }
  5116. sum = sum % 11;
  5117. if (sum > 9) {
  5118. sum = 0;
  5119. }
  5120. return (sum + '' === value.substr(8, 1));
  5121. },
  5122. /**
  5123. * Validate Norwegian VAT number
  5124. *
  5125. * @see http://www.brreg.no/english/coordination/number.html
  5126. * @param {String} value VAT number
  5127. * @returns {Boolean}
  5128. */
  5129. _no: function(value) {
  5130. if (!/^NO[0-9]{9}$/.test(value)) {
  5131. return false;
  5132. }
  5133. value = value.substr(2);
  5134. var sum = 0,
  5135. weight = [3, 2, 7, 6, 5, 4, 3, 2];
  5136. for (var i = 0; i < 8; i++) {
  5137. sum += parseInt(value.charAt(i), 10) * weight[i];
  5138. }
  5139. sum = 11 - sum % 11;
  5140. if (sum === 11) {
  5141. sum = 0;
  5142. }
  5143. return (sum + '' === value.substr(8, 1));
  5144. },
  5145. /**
  5146. * Validate Polish VAT number
  5147. * Examples:
  5148. * - Valid: PL8567346215
  5149. * - Invalid: PL8567346216
  5150. *
  5151. * @param {String} value VAT number
  5152. * @returns {Boolean}
  5153. */
  5154. _pl: function(value) {
  5155. if (!/^PL[0-9]{10}$/.test(value)) {
  5156. return false;
  5157. }
  5158. value = value.substr(2);
  5159. var sum = 0,
  5160. weight = [6, 5, 7, 2, 3, 4, 5, 6, 7, -1];
  5161. for (var i = 0; i < 10; i++) {
  5162. sum += parseInt(value.charAt(i), 10) * weight[i];
  5163. }
  5164. return (sum % 11 === 0);
  5165. },
  5166. /**
  5167. * Validate Portuguese VAT number
  5168. * Examples:
  5169. * - Valid: PT501964843
  5170. * - Invalid: PT501964842
  5171. *
  5172. * @param {String} value VAT number
  5173. * @returns {Boolean}
  5174. */
  5175. _pt: function(value) {
  5176. if (!/^PT[0-9]{9}$/.test(value)) {
  5177. return false;
  5178. }
  5179. value = value.substr(2);
  5180. var sum = 0,
  5181. weight = [9, 8, 7, 6, 5, 4, 3, 2];
  5182. for (var i = 0; i < 8; i++) {
  5183. sum += parseInt(value.charAt(i), 10) * weight[i];
  5184. }
  5185. sum = 11 - sum % 11;
  5186. if (sum > 9) {
  5187. sum = 0;
  5188. }
  5189. return (sum + '' === value.substr(8, 1));
  5190. },
  5191. /**
  5192. * Validate Romanian VAT number
  5193. * Examples:
  5194. * - Valid: RO18547290
  5195. * - Invalid: RO18547291
  5196. *
  5197. * @param {String} value VAT number
  5198. * @returns {Boolean}
  5199. */
  5200. _ro: function(value) {
  5201. if (!/^RO[1-9][0-9]{1,9}$/.test(value)) {
  5202. return false;
  5203. }
  5204. value = value.substr(2);
  5205. var length = value.length,
  5206. weight = [7, 5, 3, 2, 1, 7, 5, 3, 2].slice(10 - length),
  5207. sum = 0;
  5208. for (var i = 0; i < length - 1; i++) {
  5209. sum += parseInt(value.charAt(i), 10) * weight[i];
  5210. }
  5211. sum = (10 * sum) % 11 % 10;
  5212. return (sum + '' === value.substr(length - 1, 1));
  5213. },
  5214. /**
  5215. * Validate Russian VAT number (Taxpayer Identification Number - INN)
  5216. *
  5217. * @param {String} value VAT number
  5218. * @returns {Boolean}
  5219. */
  5220. _ru: function(value) {
  5221. if (!/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
  5222. return false;
  5223. }
  5224. value = value.substr(2);
  5225. var i = 0;
  5226. if (value.length === 10) {
  5227. var sum = 0,
  5228. weight = [2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  5229. for (i = 0; i < 10; i++) {
  5230. sum += parseInt(value.charAt(i), 10) * weight[i];
  5231. }
  5232. sum = sum % 11;
  5233. if (sum > 9) {
  5234. sum = sum % 10;
  5235. }
  5236. return (sum + '' === value.substr(9, 1));
  5237. } else if (value.length === 12) {
  5238. var sum1 = 0,
  5239. weight1 = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0],
  5240. sum2 = 0,
  5241. weight2 = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8, 0];
  5242. for (i = 0; i < 11; i++) {
  5243. sum1 += parseInt(value.charAt(i), 10) * weight1[i];
  5244. sum2 += parseInt(value.charAt(i), 10) * weight2[i];
  5245. }
  5246. sum1 = sum1 % 11;
  5247. if (sum1 > 9) {
  5248. sum1 = sum1 % 10;
  5249. }
  5250. sum2 = sum2 % 11;
  5251. if (sum2 > 9) {
  5252. sum2 = sum2 % 10;
  5253. }
  5254. return (sum1 + '' === value.substr(10, 1) && sum2 + '' === value.substr(11, 1));
  5255. }
  5256. return false;
  5257. },
  5258. /**
  5259. * Validate Serbian VAT number
  5260. *
  5261. * @param {String} value VAT number
  5262. * @returns {Boolean}
  5263. */
  5264. _rs: function(value) {
  5265. if (!/^RS[0-9]{9}$/.test(value)) {
  5266. return false;
  5267. }
  5268. value = value.substr(2);
  5269. var sum = 10,
  5270. temp = 0;
  5271. for (var i = 0; i < 8; i++) {
  5272. temp = (parseInt(value.charAt(i), 10) + sum) % 10;
  5273. if (temp === 0) {
  5274. temp = 10;
  5275. }
  5276. sum = (2 * temp) % 11;
  5277. }
  5278. return ((sum + parseInt(value.substr(8, 1), 10)) % 10 === 1);
  5279. },
  5280. /**
  5281. * Validate Swedish VAT number
  5282. * Examples:
  5283. * - Valid: SE123456789701
  5284. * - Invalid: SE123456789101
  5285. *
  5286. * @param {String} value VAT number
  5287. * @returns {Boolean}
  5288. */
  5289. _se: function(value) {
  5290. if (!/^SE[0-9]{10}01$/.test(value)) {
  5291. return false;
  5292. }
  5293. value = value.substr(2, 10);
  5294. return $.fn.bootstrapValidator.helpers.luhn(value);
  5295. },
  5296. /**
  5297. * Validate Slovenian VAT number
  5298. * Examples:
  5299. * - Valid: SI50223054
  5300. * - Invalid: SI50223055
  5301. *
  5302. * @param {String} value VAT number
  5303. * @returns {Boolean}
  5304. */
  5305. _si: function(value) {
  5306. if (!/^SI[0-9]{8}$/.test(value)) {
  5307. return false;
  5308. }
  5309. value = value.substr(2);
  5310. var sum = 0,
  5311. weight = [8, 7, 6, 5, 4, 3, 2];
  5312. for (var i = 0; i < 7; i++) {
  5313. sum += parseInt(value.charAt(i), 10) * weight[i];
  5314. }
  5315. sum = 11 - sum % 11;
  5316. if (sum === 10) {
  5317. sum = 0;
  5318. }
  5319. return (sum + '' === value.substr(7, 1));
  5320. },
  5321. /**
  5322. * Validate Slovak VAT number
  5323. * Examples:
  5324. * - Valid: SK2022749619
  5325. * - Invalid: SK2022749618
  5326. *
  5327. * @param {String} value VAT number
  5328. * @returns {Boolean}
  5329. */
  5330. _sk: function(value) {
  5331. if (!/^SK[1-9][0-9][(2-4)|(6-9)][0-9]{7}$/.test(value)) {
  5332. return false;
  5333. }
  5334. return (parseInt(value.substr(2), 10) % 11 === 0);
  5335. }
  5336. };
  5337. }(window.jQuery));
  5338. ;(function($) {
  5339. $.fn.bootstrapValidator.i18n.vin = $.extend($.fn.bootstrapValidator.i18n.vin || {}, {
  5340. 'default': 'Please enter a valid VIN number'
  5341. });
  5342. $.fn.bootstrapValidator.validators.vin = {
  5343. /**
  5344. * Validate an US VIN (Vehicle Identification Number)
  5345. *
  5346. * @param {BootstrapValidator} validator The validator plugin instance
  5347. * @param {jQuery} $field Field element
  5348. * @param {Object} options Consist of key:
  5349. * - message: The invalid message
  5350. * @returns {Boolean}
  5351. */
  5352. validate: function(validator, $field, options) {
  5353. var value = $field.val();
  5354. if (value === '') {
  5355. return true;
  5356. }
  5357. // Don't accept I, O, Q characters
  5358. if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/i.test(value)) {
  5359. return false;
  5360. }
  5361. value = value.toUpperCase();
  5362. var chars = {
  5363. A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,
  5364. J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,
  5365. S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,
  5366. '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0
  5367. },
  5368. weights = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2],
  5369. sum = 0,
  5370. length = value.length;
  5371. for (var i = 0; i < length; i++) {
  5372. sum += chars[value.charAt(i) + ''] * weights[i];
  5373. }
  5374. var reminder = sum % 11;
  5375. if (reminder === 10) {
  5376. reminder = 'X';
  5377. }
  5378. return (reminder + '') === value.charAt(8);
  5379. }
  5380. };
  5381. }(window.jQuery));
  5382. ;(function($) {
  5383. $.fn.bootstrapValidator.i18n.zipCode = $.extend($.fn.bootstrapValidator.i18n.zipCode || {}, {
  5384. 'default': 'Please enter a valid zip code',
  5385. countryNotSupported: 'The country code %s is not supported',
  5386. country: 'Please enter a valid %s',
  5387. countries: {
  5388. 'CA': 'Canadian postal code',
  5389. 'DK': 'Danish postal code',
  5390. 'GB': 'United Kingdom postal code',
  5391. 'IT': 'Italian postal code',
  5392. 'NL': 'Dutch postal code',
  5393. 'SE': 'Swiss postal code',
  5394. 'SG': 'Singapore postal code',
  5395. 'US': 'US zip code'
  5396. },
  5397. getMessage: function(options) {
  5398. var country = (options.country || 'US').toUpperCase();
  5399. if ($.inArray(country, $.fn.bootstrapValidator.validators.zipCode.COUNTRIES) === -1) {
  5400. return $.fn.bootstrapValidator.helpers.format(this.countryNotSupported, country);
  5401. }
  5402. if (this.countries[country]) {
  5403. return $.fn.bootstrapValidator.helpers.format(this.country, this.countries[country]);
  5404. }
  5405. return this['default'];
  5406. }
  5407. });
  5408. $.fn.bootstrapValidator.validators.zipCode = {
  5409. html5Attributes: {
  5410. message: 'message',
  5411. country: 'country'
  5412. },
  5413. COUNTRIES: ['CA', 'DK', 'GB', 'IT', 'NL', 'SE', 'SG', 'US'],
  5414. /**
  5415. * Return true if and only if the input value is a valid country zip code
  5416. *
  5417. * @param {BootstrapValidator} validator The validator plugin instance
  5418. * @param {jQuery} $field Field element
  5419. * @param {Object} options Consist of key:
  5420. * - message: The invalid message
  5421. * - country: The ISO 3166 country code
  5422. *
  5423. * Currently it supports the following countries:
  5424. * - US (United State)
  5425. * - CA (Canada)
  5426. * - DK (Denmark)
  5427. * - GB (United Kingdom)
  5428. * - IT (Italy)
  5429. * - NL (Netherlands)
  5430. * - SE (Sweden)
  5431. * - SG (Singapore)
  5432. * @returns {Boolean}
  5433. */
  5434. validate: function(validator, $field, options) {
  5435. var value = $field.val();
  5436. if (value === '' || !options.country) {
  5437. return true;
  5438. }
  5439. var country = (options.country || 'US').toUpperCase();
  5440. if ($.inArray(country, this.COUNTRIES) === -1) {
  5441. return false;
  5442. }
  5443. switch (country) {
  5444. case 'CA': return /^(?: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|X|Y){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}$/i.test(value);
  5445. case 'DK': return /^(DK(-|\s)?)?\d{4}$/i.test(value);
  5446. case 'GB': return this._gb(value);
  5447. // http://en.wikipedia.org/wiki/List_of_postal_codes_in_Italy
  5448. case 'IT': return /^(I-|IT-)?\d{5}$/i.test(value);
  5449. // http://en.wikipedia.org/wiki/Postal_codes_in_the_Netherlands
  5450. case 'NL': return /^[1-9][0-9]{3} ?(?!sa|sd|ss)[a-z]{2}$/i.test(value);
  5451. case 'SE': return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
  5452. case 'SG': return /^([0][1-9]|[1-6][0-9]|[7]([0-3]|[5-9])|[8][0-2])(\d{4})$/i.test(value);
  5453. case 'US':
  5454. /* falls through */
  5455. default: return /^\d{4,5}([\-]\d{4})?$/.test(value);
  5456. }
  5457. },
  5458. /**
  5459. * Validate United Kingdom postcode
  5460. * Examples:
  5461. * - Standard: EC1A 1BB, W1A 1HQ, M1 1AA, B33 8TH, CR2 6XH, DN55 1PT
  5462. * - Special cases:
  5463. * AI-2640, ASCN 1ZZ, GIR 0AA
  5464. *
  5465. * @see http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom
  5466. * @param {String} value The postcode
  5467. * @returns {Boolean}
  5468. */
  5469. _gb: function(value) {
  5470. var firstChar = '[ABCDEFGHIJKLMNOPRSTUWYZ]', // Does not accept QVX
  5471. secondChar = '[ABCDEFGHKLMNOPQRSTUVWXY]', // Does not accept IJZ
  5472. thirdChar = '[ABCDEFGHJKPMNRSTUVWXY]',
  5473. fourthChar = '[ABEHMNPRVWXY]',
  5474. fifthChar = '[ABDEFGHJLNPQRSTUWXYZ]',
  5475. regexps = [
  5476. // AN NAA, ANN NAA, AAN NAA, AANN NAA format
  5477. new RegExp('^(' + firstChar + '{1}' + secondChar + '?[0-9]{1,2})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  5478. // ANA NAA
  5479. new RegExp('^(' + firstChar + '{1}[0-9]{1}' + thirdChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  5480. // AANA NAA
  5481. new RegExp('^(' + firstChar + '{1}' + secondChar + '{1}?[0-9]{1}' + fourthChar + '{1})(\\s*)([0-9]{1}' + fifthChar + '{2})$', 'i'),
  5482. new RegExp('^(BF1)(\\s*)([0-6]{1}[ABDEFGHJLNPQRST]{1}[ABDEFGHJLNPQRSTUWZYZ]{1})$', 'i'), // BFPO postcodes
  5483. /^(GIR)(\s*)(0AA)$/i, // Special postcode GIR 0AA
  5484. /^(BFPO)(\s*)([0-9]{1,4})$/i, // Standard BFPO numbers
  5485. /^(BFPO)(\s*)(c\/o\s*[0-9]{1,3})$/i, // c/o BFPO numbers
  5486. /^([A-Z]{4})(\s*)(1ZZ)$/i, // Overseas Territories
  5487. /^(AI-2640)$/i // Anguilla
  5488. ];
  5489. for (var i = 0; i < regexps.length; i++) {
  5490. if (regexps[i].test(value)) {
  5491. return true;
  5492. }
  5493. }
  5494. return false;
  5495. }
  5496. };
  5497. }(window.jQuery));