bootstrapValidator.js 229 KB

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