bootstrapValidator.js 199 KB

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