bootstrapValidator.js 199 KB

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