bootstrapValidator.js 198 KB

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