/** * @preserve * Regula: An annotation-based form-validation framework in Javascript * Version 1.3.4 * * Written By Vivin Paliath (http://vivin.net) * License: BSD License * Copyright (C) 2010-2014 * * Other licenses: * * DOMUtils#getElementsByAttribute * Author: Robert Nyman * Copyright Robert Nyman, http://www.robertnyman.com * Free to use if this text is included */ (function(e,t){typeof define=="function"&&define.amd?define("utils/MapUtils",t):(typeof e.regulaModules=="undefined"&&(e.regulaModules={}),e.regulaModules.MapUtils=t())})(this,function(){return{iterateOverMap:function(e,t){var n=0;for(var r in e)e.hasOwnProperty(r)&&r!=="__size__"&&(t.call(e,r,e[r],n),n++)},exists:function(e,t){var n=!1,r=0;while(!n&&r0&&(typeof r=="undefined"||o&&o.test(a))&&s.push(u);return s}function n(e,t){var n=e.getAttribute&&e.getAttribute(t)||null;if(!n){var r=e.attributes;for(var i=0;i0)for(var s in e)e.hasOwnProperty(s)&&s!="__size__"&&t.put(i,s,e[s]);return i}function f(e,t,n,i){var s=o[y.constraintType],a=W(t,s,i),f={group:n,constraintName:e.constraintName,custom:u[s].custom,compound:u[s].compound,async:u[s].async,constraintParameters:y.params,failingElements:e.failingElements,message:a};return r.reportAsSingleViolation||(f.composingConstraintViolations=e.composingConstraintViolations||[]),f}var l=[],c=[];for(var h=0;h0){v=[];for(var h=0;h0){v===null&&(v=[]);var T=0;for(var h=0;h0)throw new r.Exception.IllegalArgumentException("No constraints have been bound to the specified elements: "+i.explode(p)+". "+r.explodeParameters(e));return n=M(n),D(n,e)}function N(e){var t=[],n={asyncContexts:[],syncContexts:[]};for(var s in a)if(a.hasOwnProperty(s)){var o=a[s];for(var u=0;u0)throw new r.Exception.IllegalArgumentException("No constraints have been bound to the specified elements: "+i.explode(t)+". "+r.explodeParameters(e));return n=M(n),D(n,e)}function C(e){var t=!1,n={groupedContexts:{}},i=0;while(i0)throw new r.Exception.IllegalArgumentException("The following elements: "+i.explode(n)+" were not found in one or more of the following group(s): ["+i.explode(t,",").replace(/,/g,", ")+"]. "+r.explodeParameters(e));var m=_(o);return e.groups=m.groups,o=m.uniqueConstraintsToValidate,P(e,o,s)}function A(e){var t=!1,n={groupedContexts:{}},r=0;while(r0&&(n=B(e));if(e.asyncContexts.length>0){if(!t.callback)throw new r.Exception.IllegalArgumentException("One or more constraints to be validated are asynchronous, but a callback has not been provided.");j(e,function(e){n.length>0?n=n.concat(e):n=e,t.callback(n)})}else t.callback&&t.callback(n);return n}function P(e,t,n){var i=F(e.groups,e.independent,t);if(n){if(!e.callback)throw new r.Exception.IllegalArgumentException("One or more constraints to be validated are asynchronous, but a callback has not been provided.");if(!e.independent&&i.length>0){var s=i[0].group,o=t.groupedContexts[s];t.groupedContexts={},t.groupedContexts[s]=o}I(e.groups,e.independent,t,function(t){i.length>0?i=i.concat(t):i=t,e.callback(i)})}else e.callback&&e.callback(i);return i}function H(e,t,n){var i=a[e];if(!i)throw new r.Exception.IllegalArgumentException("Undefined group in group list (group: "+e+", elementId: "+t+", constraint: "+n+")");var s=i[t];if(!s)throw new r.Exception.IllegalArgumentException("No constraints have been defined for the element with id: "+t+" in group "+e);var o=s[n];if(!o)throw new r.Exception.IllegalArgumentException("Constraint "+n+" in group "+e+" hasn't been bound to the element with id "+t);return{group:e,elementId:t,elementConstraint:n,params:o,async:u[n].async}}function B(e){var t=[],n=0;while(n0},max:function(e){var t=!0;return g(this,e)&&(t=parseFloat(this.value)<=parseFloat(e.value)),t},min:function(e){var t=!0;return g(this,e)&&(t=parseFloat(this.value)>=parseFloat(e.value)),t},range:function(e){var t=!0;return g(this,e)&&(t=this.value.replace(/\s/g,"")!=""&&parseFloat(this.value)<=parseFloat(e.max)&&parseFloat(this.value)>=parseFloat(e.min)),t},notBlank:function(e){return this.value.replace(/\s/g,"")!=""},blank:function(e){return this.value.replace(/\s/g,"")===""},matches:function(e){var t=!0;if(g(this,e)){var n,r;typeof e["regex"]=="string"?r=e.regex.replace(/^\//,"").replace(/\/$/,""):r=e.regex,typeof e["flags"]!="undefined"?n=new RegExp(r.toString().replace(/^\//,"").replace(/\/[^\/]*$/,""),e.flags):n=new RegExp(r),t=n.test(this.value)}return t},email:function(e){var t=!0;return g(this,e)&&(t=/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(this.value)),t},alpha:function(e){var t=!0;return g(this,e)&&(t=/^[A-Za-z]+$/.test(this.value)),t},numeric:function(e){var t=!0;return g(this,e)&&(t=/^[0-9]+$/.test(this.value)),t},integer:function(e){var t=!0;return g(this,e)&&(t=/^-?[0-9]+$/.test(this.value)),t},real:function(e){var t=!0;return g(this,e)&&(t=/^-?([0-9]+(\.[0-9]+)?|\.[0-9]+)$/.test(this.value)),t},alphaNumeric:function(e){var t=!0;return g(this,e)&&(t=/^[0-9A-Za-z]+$/.test(this.value)),t},completelyFilled:function(e){var t=[];for(var n=0;n=e.min&&this.value.length<=e.max),t},digits:function(e){var t=!0;if(g(this,e)){var n=this.value.replace(/\s/g,""),r=n.split(/\./);t=!1,n.length>0&&(r.length==1&&(r[1]=""),e.integer>0?t=r[0].length<=e.integer:t=!0,e.fraction>0&&(t=t&&r[1].length<=e.fraction))}return t},past:function(e){var t=!0;if(g(this,e)){var n=y.call(this,e);t=n.dateToValidaten.dateToTestAgainst}return t},url:function(e){var t=!0;return g(this,e)&&(t=/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(this.value)),t},step:function(e){var t=!0;if(g(this,e)){var n=parseFloat(this.value),r=parseFloat(e.max),i=parseFloat(e.min),s=parseFloat(e.value);t=n<=r&&n>=i&&n%s===0}return t},html5Required:function(e){return!this.validity.valueMissing},html5Email:w,html5URL:w,html5Number:w,html5DateTime:w,html5DateTimeLocal:w,html5Date:w,html5Month:w,html5Time:w,html5Week:w,html5Range:w,html5Tel:w,html5Color:w,html5Pattern:function(e){return!this.validity.patternMismatch},html5MaxLength:function(e){return!this.validity.tooLong},html5Min:function(e){return!this.validity.rangeUnderflow},html5Max:function(e){return!this.validity.rangeOverflow},html5Step:function(e){return!this.validity.stepMismatch}};return{Validator:d,init:p,wrapValidatorWithEmptyCheck:b,initializePublicValidators:h,compoundValidator:m,validate:E,runValidatorFor:U,interpolateConstraintDefaultMessage:W,createPublicValidator:v}}),function(e,t){typeof define=="function"&&define.amd?define("domain/CompositionGraph",t):(typeof e.regulaModules=="undefined"&&(e.regulaModules={}),e.regulaModules.CompositionGraph=t())}(this,function(){function n(n){var r=n.type,i=n.name,s=n.parent,o=typeof e[r]=="undefined"?{visited:!1,name:i,type:r,parents:[],children:[]}:e[r];s==null?t.children.push(o):(s.children.push(o),o.parents.push(s)),e[r]=o}function r(){var e={},n=function r(t,n){var i=typeof e[t.type]=="undefined"?{visited:t.visited,name:t.name,type:t.type,parents:[],children:[]}:e[t.type];n!==null&&i.parents.push(n);for(var s=0;s0&&(s={error:!0,message:n.generateExceptionMessage(e,o[t.constraintType],"You seem to have provided some optional or required parameters for @"+o[t.constraintType]+", but you are still missing the following "+u.length+" required parameter(s): "+i.explode(u,", ")),data:null}),s}function d(e,n){var r=t.getNodeByType(s[e]);r==null&&(t.addNode({type:s[e],name:e,parent:null}),r=t.getNodeByType(s[e]));for(var i=0;i0&&t.successful)t=c(e),n.push(t.data);return t.data=n,t}function c(e){var n={successful:!0,message:"",data:null},i=e.shift();return r(i).length==0&&(i=e.shift()),i=="@"?n=h(e):n={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid constraint. Constraint definitions need to start with '@'")+" "+n.message,data:null},n}function h(e){var r={Between:"Range",Matches:"Pattern",Empty:"Blank",NotEmpty:"NotBlank",IsAlpha:"Alpha",IsNumeric:"Integer",IsAlphaNumeric:"AlphaNumeric"},i=p(e);if(i.successful){a=i.data,a=r[a]?r[a]:a;if(n.constraintDefinitions[a]){i=m(e);if(i.successful){i=n.verifyConstraintDefinition(o,a,i.data);if(i.successful){var s=i.data;i.data={element:o,constraintName:a,definedParameters:s}}}}else i={successful:!1,message:t.generateExceptionMessage(o,a,"I cannot find the specified constraint name. If this is a custom constraint, you need to define it before you bind to it")+" "+i.message,data:null}}else i={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid constraint name in constraint definition")+" "+i.message,data:null};return i}function p(e){var n=r(e.shift()),i=d(n.charAt(0));if(i.successful){var s=1;while(s0&&i(n)==","&&s.successful)n.shift(),s=g(n),s.successful&&(e.put(u,s.data.name,s.data.value),r(i(n)).length==0&&n.shift());if(s.successful){var f=n.shift();r(f).length==0&&(f=n.shift()),f!=")"?s={successful:!1,message:t.generateExceptionMessage(o,a,"Cannot find matching closing ) in parameter list")+" "+s.message,data:null}:s.data=u}}else s={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid parameter definition")+" "+s.message,data:null}}}else i(n)!==undefined&&i(n)!="@"&&(s={successful:!1,message:t.generateExceptionMessage(o,a,"Unexpected character '"+i(n)+"'"+" after constraint definition")+" "+s.message,data:null});return s}function g(e){var n=y(e);if(n.successful){var r=n.data,i=e.shift();i=="="?(n=b(e),n.successful?n.data={name:r,value:n.data}:n={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid parameter value")+" "+n.message,data:null}):(e.unshift(i),n={successful:!1,message:t.generateExceptionMessage(o,a,"'=' expected after parameter name "+n.message),data:null})}else n={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid parameter name. You might have unmatched parentheses")+" "+n.message,data:null};return n}function y(e){var n=r(e.shift());n.length==0&&(n=e.shift());var i={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid starting character for parameter name. Can only include A-Z, a-z, and _"),data:null};if(typeof n!="undefined"){i=d(n.charAt(0));if(i.successful){var s=1;while(s0&&s.successful&&!u)i(e)=='"'?(u=!0,e.shift()):(s=k(e),r+=s.data);u||(s={successful:!1,message:t.generateExceptionMessage(o,a,"Unterminated string literal"),data:null})}else e.unshift(n),s={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid quoted string"),data:null};return s.successful=s.successful&&u,s.data=r,s}function k(e){var t="",n=e.shift();return n=="\\"&&(t=e.shift()),{successful:!0,message:"",data:n+t}}function L(e){var n="",r=e.shift(),s={successful:!0,message:"",data:null};if(r=="/"){n=r;var u=!1;while(e.length>0&&s.successful&&!u)i(e)=="/"?(n+=e.shift(),u=!0):(s=k(e),n+=s.data);u||(s={successful:!1,message:t.generateExceptionMessage(o,a,"Unterminated regex literal"),data:null})}else e.unshift(r),s={successful:!1,message:t.generateExceptionMessage(o,a,"Not a regular expression"),data:null};return s.successful=s.successful&&u,s.data=n,s}function A(e){var n=e.shift(),i={successful:!0,message:"",data:null};return r(n)=="true"||r(n)=="false"?i={successful:!0,message:"",data:n==="true"}:(e.unshift(n),i={successful:!1,message:t.generateExceptionMessage(o,a,"Not a boolean"),data:null}),i}function O(e){var n=[],s=e.shift(),u={successful:!0,message:"",data:null};if(s=="["){r(i(e)).length==0&&e.shift(),i(e)=="]"?u={successful:!0,message:"",data:""}:u=M(e);if(u.successful){n.push(u.data),r(i(e)).length==0&&e.shift();while(e.length>0&&i(e)==","&&u.successful)e.shift(),u=M(e),n.push(u.data),r(i(e)).length==0&&e.shift();u.data=n,s=e.shift(),r(s).length==0&&e.shift(),s!="]"&&(u={successful:!1,message:t.generateExceptionMessage(o,a,"Cannot find matching closing ] in group definition")+" "+u.message,data:null})}else u={successful:!1,message:t.generateExceptionMessage(o,a,"Invalid group definition")+" "+u.message,data:null}}else e.unshift(s),u={successful:!1,message:t.generateExceptionMessage(o,a,"Not a valid group definition"),data:null};return u}function M(e){var n={successful:!0,message:"",data:""},i=r(e.shift());i.length==0&&(i=e.shift()),n=d(i.charAt(0));if(n.successful){var s=1;while(s0){var o=0;while(o0?h=t.deletedGroupIndices.pop():h=t.firstCustomGroupIndex++,t.Group[c]=h,t.ReverseGroup[h]=c,o[c]={}}o[c][n.id]||(o[c][n.id]={}),o[c][n.id][r]=u}if(i.constraintDefinitions[r].html5)if(n.getAttribute("type")!==null&&i.constraintDefinitions[r].inputType!==null&&n.getAttribute("type")!==i.constraintDefinitions[r].inputType)a={successful:!1,message:s.generateExceptionMessage(n,r,"Element type of "+n.getAttribute("type")+" conflicts with type of constraint @"+r+": "+i.constraintDefinitions[r].inputType),data:null};else{var p=i.constraintDefinitions[r].attribute,d=i.constraintDefinitions[r].inputType;(p!==null&&n.getAttribute(p)===null||d!==null&&n.getAttribute("type")===null)&&y(n,r,u)}return a}function y(e,t,n){if(t===i.ReverseConstraint[i.Constraint.HTML5Required])e.setAttribute("required","true");else{var r=i.constraintDefinitions[t];for(var s=0;s0&&!t)throw new s.Exception.IllegalArgumentException("Element with id "+r+" does not have any constraints bound to it. "+s.explodeParameters(e))}function w(e){var n=e.elementId,r=e.group,s=e.constraint,u=typeof o[t.ReverseGroup[t.Group.Default]][n]!="undefined";if(u&&typeof r!="undefined"&&typeof s=="undefined"){var a=t.ReverseGroup[r];u=typeof a!="undefined"&&typeof o[a][n]!="undefined"}else if(u&&typeof r=="undefined"&&typeof s!="undefined"){var f=i.ReverseConstraint[s];u=typeof f!="undefined"&&typeof o[t.ReverseGroup[t.Group.Default]][n][f]!="undefined"}else if(u&&typeof r!="undefined"&&typeof s!="undefined"){var a=t.ReverseGroup[r],f=i.ReverseConstraint[s];u=typeof a!="undefined"&&typeof f!="undefined"&&typeof o[a][n]!="undefined"&&typeof o[a][n][f]!="undefined"}return u}var o=null,u={};return{initializeBoundConstraints:a,resetBoundConstraints:f,getBoundConstraints:l,removeElementAndGroupFromBoundConstraintsIfEmpty:c,bindAfterParsing:p,bindHTML5ValidationConstraints:d,bindFromOptions:v,unbind:b,isBound:w}}),function(e,t){typeof define=="function"&&define.amd?define("regula",["utils/MapUtils","utils/DOMUtils","service/BindingService","service/ExceptionService","service/ConstraintService","service/ValidationService","service/GroupService"],t):(e.regula=t(e.regulaModules.MapUtils,e.regulaModules.DOMUtils,e.regulaModules.BindingService,e.regulaModules.ExceptionService,e.regulaModules.ConstraintService,e.regulaModules.ValidationService,e.regulaModules.GroupService),e.regula._modules=e.regulaModules,e.regulaModules=undefined)}(this,function(e,t,n,r,i,s,o){function f(t){e.iterateOverMap(t,function(e,t,n){typeof u[e]!="undefined"&&(u[e]=t)})}function l(e){var i={successful:!0,message:"",data:null};if(typeof e=="undefined"||!e)n.resetBoundConstraints(),u.enableHTML5Validation&&t.supportsHTML5Validation()&&(i=n.bindHTML5ValidationConstraints({element:null})),i.successful&&(i=n.bindAfterParsing({element:null}));else{var s=e.elements;if(typeof s=="undefined"||!s)u.enableHTML5Validation&&t.supportsHTML5Validation()&&typeof e.element!="undefined"&&e.element!==null&&(i=n.bindHTML5ValidationConstraints({element:e.element})),i.successful&&(i=n.bindFromOptions(e));else{var o=0;while(i.successful&&o