bootstrapValidator.js 226 KB

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