bootstrapValidator.js 223 KB

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