bootstrapValidator.js 228 KB

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