bootstrapValidator.js 202 KB

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