bootstrapValidator.js 202 KB

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