bootstrapValidator.js 200 KB

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