bootstrapValidator.js 197 KB

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