bootstrapValidator.js 200 KB

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