From b0c696be9e9b1427190fba544fdd0293fcb00bc6 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Fri, 10 Mar 2017 00:05:40 -0500 Subject: [PATCH 01/34] Add silent mode to checkFormValidity function --- .gitignore | 2 ++ .npmignore | 4 +++- bower.json | 2 +- dist/angular-validation.min.js | 8 ++++---- package.json | 2 +- readme.md | 2 +- src/validation-common.js | 2 +- src/validation-service.js | 7 ++++--- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 088c748..06ab436 100644 --- a/.gitignore +++ b/.gitignore @@ -222,3 +222,5 @@ pip-log.txt #Mr Developer .mr.developer.cfg +yarn-error.log +yarn.lock \ No newline at end of file diff --git a/.npmignore b/.npmignore index 087b123..9a1941d 100644 --- a/.npmignore +++ b/.npmignore @@ -6,4 +6,6 @@ templates/ .gitignore app.js gulpfile.js -index.html \ No newline at end of file +index.html +yarn-error.log +yarn.lock \ No newline at end of file diff --git a/bower.json b/bower.json index 056b698..cb7129a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.16", + "version": "1.5.17", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index d41c7be..b6623ad 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.16 + * @version: 1.5.17 * @license: MIT - * @build: Tue Jan 24 2017 13:50:01 GMT-0500 (Eastern Standard Time) + * @build: Fri Mar 10 2017 00:02:53 GMT-0500 (Eastern Standard Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:h.typingLimit,s=h.getFormElementByName(l.$name);if(Array.isArray(i)){if($=[],O="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():(h.validate(i,!1),h.isFieldRequired()||A||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||h.isFieldRequired()||A)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=h.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=h.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):(h.updateErrorMsg(""),e.cancel(b),b=e(function(){d=h.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&($.push(n),parseInt(e)===i-1&&$.forEach(function(a){a.then(function(a){switch(F){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){O.length>0&&g.displayOnlyLastErrorMsg?O="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):O+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),h.updateErrorMsg(O,{isValid:!1}),h.addToValidationSummary(a.formElmObj,O)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=h.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&h.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),h.removeFromValidationSummary(j);var a=h.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=h.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),h.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&h.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=h.getFormElementByName(l.$name);h.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),h.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",h.validate(a,!1));var e=h.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,h=new i(n,t,r,l),O="",$=[],E=[],g=h.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,A=r.hasOwnProperty("validateOnEmpty")?h.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,F=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){a?(f(),h.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{h.defineValidation(),p();var e=h.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue;if(t&&t.hasOwnProperty("isValidationCancelled")){var n=o(i);w&&h.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}})}}}]); -angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,d=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;d&&(d.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var d=a.split("|");if(d){e.bFieldRequired=a.indexOf("required")>=0;for(var p=0,m=d.length;p=0,g=[];f?(g=d[p].substring(0,c-1).split(":"),g.push(d[p].substring(c))):g=d[p].split(":"),e.validators[p]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function d(){var e=this;return e.bFieldRequired}function p(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=p(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var d=r.validatorAttrs.validationErrorTo.charAt(0),p="."===d||"#"===d?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(p))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,d={message:""};"undefined"==typeof e&&(e="");for(var p=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(p),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){d.message.length>0&&K.displayOnlyLastErrorMsg?d.message=s+(n&&n.params?String.format(a,n.params):a):d.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,d.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);d.message.length>0&&K.displayOnlyLastErrorMsg?d.message=s+o:d.message+=s+o,O(i,e,d.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var d=l.split(".");return t.scope[d[0]][d[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,d=i&&3===i.length?i[1]:0,p=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,d,p)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),d=M(t.condition[0],s,l),p=M(t.condition[1],s,u);r=d&&p}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var d=a.params[0],p=f(r,d);if("boolean"==typeof p)s=!!p;else{if("object"!=typeof p)throw u;s=!!p.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(p.message&&(e+=p.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof p)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),d=t,p=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(d.condition,p.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=d.message;d.altText&&d.altText.length>0&&(o=d.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(d&&d.params?String.format(e,d.params):e),O(r,m,n.message,i,!0)})}p.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],d=f(a,u);if(Y.length>1)for(;Y.length>0;){var p=Y.pop();"function"==typeof p.abort&&p.abort()}if(Y.push(d),!d||"function"!=typeof d.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){d.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled;if(r.elm.prop("disabled")||r.scope.$eval(i))n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var o=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&o.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=p(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=d,X.prototype.initialize=u,X.prototype.mergeObjects=p,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); +angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,d=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;d&&(d.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var d=a.split("|");if(d){e.bFieldRequired=a.indexOf("required")>=0;for(var p=0,m=d.length;p=0,g=[];f?(g=d[p].substring(0,c-1).split(":"),g.push(d[p].substring(c))):g=d[p].split(":"),e.validators[p]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function d(){var e=this;return e.bFieldRequired}function p(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=p(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var d=r.validatorAttrs.validationErrorTo.charAt(0),p="."===d||"#"===d?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(p))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,d={message:""};"undefined"==typeof e&&(e="");for(var p=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(p),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){d.message.length>0&&K.displayOnlyLastErrorMsg?d.message=s+(n&&n.params?String.format(a,n.params):a):d.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,d.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);d.message.length>0&&K.displayOnlyLastErrorMsg?d.message=s+o:d.message+=s+o,O(i,e,d.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var d=l.split(".");return t.scope[d[0]][d[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,d=i&&3===i.length?i[1]:0,p=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,d,p)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),d=M(t.condition[0],s,l),p=M(t.condition[1],s,u);r=d&&p}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var d=a.params[0],p=f(r,d);if("boolean"==typeof p)s=!!p;else{if("object"!=typeof p)throw u;s=!!p.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(p.message&&(e+=p.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof p)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),d=t,p=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(d.condition,p.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=d.message;d.altText&&d.altText.length>0&&(o=d.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(d&&d.params?String.format(e,d.params):e),O(r,m,n.message,i,!0)})}p.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],d=f(a,u);if(Y.length>1)for(;Y.length>0;){var p=Y.pop();p&&"function"==typeof p.abort&&p.abort()}if(Y.push(d),!d||"function"!=typeof d.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){d.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled;if(r.elm.prop("disabled")||r.scope.$eval(i))n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var o=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&o.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=p(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=d,X.prototype.initialize=u,X.prototype.mergeObjects=p,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; -angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return $=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,g=n.validationAttrs.hasOwnProperty("validateOnEmpty")?commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);$&&n.commonObj.runValidationCallbackOnPromise(t,$)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e){var o=this,t="",a=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var n=0,i=e.$validationSummary.length;n0&&("function"==typeof l.ctrl.$setTouched&&l.ctrl.$setTouched(),o.commonObj.updateErrorMsg(e.$validationSummary[n].message,{isSubmitted:!0,isValid:l.isValid,obj:l}))}return a}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a 1) { while (_remotePromises.length > 0) { var previousPromise = _remotePromises.pop(); - if (typeof previousPromise.abort === "function") { + if (!!previousPromise && typeof previousPromise.abort === "function") { previousPromise.abort(); // run the abort if user declared it } } diff --git a/src/validation-service.js b/src/validation-service.js index 5d3204b..04a8c57 100644 --- a/src/validation-service.js +++ b/src/validation-service.js @@ -146,9 +146,10 @@ angular /** Check the form validity (can be called by an empty ValidationService and used by both Directive/Service) * Loop through Validation Summary and if any errors found then display them and return false on current function * @param object Angular Form or Scope Object + * @param bool silently, do a form validation silently * @return bool isFormValid */ - function checkFormValidity(obj) { + function checkFormValidity(obj, silently) { var self = this; var ctrl, elm, elmName = '', isValid = true; if(typeof obj === "undefined" || typeof obj.$validationSummary === "undefined") { @@ -166,10 +167,10 @@ angular if(!!formElmObj && !!formElmObj.elm && formElmObj.elm.length > 0) { // make the element as it was touched for CSS, only works in AngularJS 1.3+ - if (typeof formElmObj.ctrl.$setTouched === "function") { + if (typeof formElmObj.ctrl.$setTouched === "function" && !silently) { formElmObj.ctrl.$setTouched(); } - self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, { isSubmitted: true, isValid: formElmObj.isValid, obj: formElmObj }); + self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, { isSubmitted: (!!silently ? false : true), isValid: formElmObj.isValid, obj: formElmObj }); } } } From 45fc0e776031cc74d82c8d136472b88cd1b90f50 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Fri, 10 Mar 2017 00:12:21 -0500 Subject: [PATCH 02/34] Update change log --- changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index 99a9b6b..3ef321b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,7 @@ Angular-Validation change logs +1.5.17 (2017-03-10) Add silent mode to checkFormValidity function +1.5.16 (2017-01-24) Fix issue where empty Form Controller was throwing an error 1.5.15 (2017-01-19) Rename errorMessageVisible flag to isErrorMessageVisible. 1.5.14 (2017-01-18) Added errorMessageVisible at updateErrorMsg this help to know when the error message is displayed or not. 1.5.13 (2016-12-29) Make sure element exist before looking for `isValidationCancelled`, issue #139 From cf135c2dab8d973d7b2a7948bfca8114c534d28e Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Sun, 26 Mar 2017 23:50:57 -0400 Subject: [PATCH 03/34] typo - fix markdown changes in Github --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 8b476a3..560e036 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -#Angular Validation (Directive / Service) +# Angular Validation (Directive / Service) `Version: 1.5.17` ### Forms Validation with Angular made easy! ##### (Concept comes from the amazing Laravel) @@ -129,10 +129,10 @@ When used with IIS, you will need to map the JSON type ``` -###License +### License [MIT License](http://www.opensource.org/licenses/mit-license.php) -###Available Validator Rules +### Available Validator Rules All validators are written as `snake_case` but it's up to the user's taste and could also be used as `camelCase`. So for example `alpha_dash_spaces` and `alphaDashSpaces` are both equivalent. ##### NOTE: on an `input type="number"`, the `+` sign is an invalid character (browser restriction) even if you are using a `signed` validator. If you really wish to use the `+`, then change your input to a `type="text"`. From 84607ca6e71a0ed427534a2302d8abdd5e09aa35 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Fri, 31 Mar 2017 15:03:29 -0400 Subject: [PATCH 04/34] Fix disabled="false" as attribute to run validation evaluate the disabled="false" attribute value in Angular-Validation so that the validation kicks in when this value is set to "false". This was problem found with the 3rd party library nya-bootstrap-select --- bower.json | 2 +- changelog.txt | 1 + dist/angular-validation.min.js | 10 ++--- index.html | 6 +-- .../addon-3rdParty-withScope/index.html | 2 +- more-examples/addon-3rdParty/index.html | 2 +- package.json | 2 +- src/validation-common.js | 38 ++++++++++++++++--- src/validation-directive.js | 7 +++- src/validation-service.js | 7 +++- 10 files changed, 56 insertions(+), 21 deletions(-) diff --git a/bower.json b/bower.json index cb7129a..835b098 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.17", + "version": "1.5.18", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 3ef321b..31cca7e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.18 (2017-03-31) Fix disabled="false" as attribute to run validation. 1.5.17 (2017-03-10) Add silent mode to checkFormValidity function 1.5.16 (2017-01-24) Fix issue where empty Form Controller was throwing an error 1.5.15 (2017-01-19) Rename errorMessageVisible flag to isErrorMessageVisible. diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index b6623ad..a498e12 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.17 + * @version: 1.5.18 * @license: MIT - * @build: Fri Mar 10 2017 00:02:53 GMT-0500 (Eastern Standard Time) + * @build: Fri Mar 31 2017 14:32:56 GMT-0400 (Eastern Daylight Time) */ -angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:h.typingLimit,s=h.getFormElementByName(l.$name);if(Array.isArray(i)){if($=[],O="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():(h.validate(i,!1),h.isFieldRequired()||A||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||h.isFieldRequired()||A)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=h.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=h.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):(h.updateErrorMsg(""),e.cancel(b),b=e(function(){d=h.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&($.push(n),parseInt(e)===i-1&&$.forEach(function(a){a.then(function(a){switch(F){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){O.length>0&&g.displayOnlyLastErrorMsg?O="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):O+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),h.updateErrorMsg(O,{isValid:!1}),h.addToValidationSummary(a.formElmObj,O)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=h.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&h.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),h.removeFromValidationSummary(j);var a=h.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=h.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),h.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&h.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=h.getFormElementByName(l.$name);h.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),h.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",h.validate(a,!1));var e=h.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,h=new i(n,t,r,l),O="",$=[],E=[],g=h.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,A=r.hasOwnProperty("validateOnEmpty")?h.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,F=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){a?(f(),h.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{h.defineValidation(),p();var e=h.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue;if(t&&t.hasOwnProperty("isValidationCancelled")){var n=o(i);w&&h.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}})}}}]); -angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,d=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;d&&(d.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var d=a.split("|");if(d){e.bFieldRequired=a.indexOf("required")>=0;for(var p=0,m=d.length;p=0,g=[];f?(g=d[p].substring(0,c-1).split(":"),g.push(d[p].substring(c))):g=d[p].split(":"),e.validators[p]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function d(){var e=this;return e.bFieldRequired}function p(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=p(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var d=r.validatorAttrs.validationErrorTo.charAt(0),p="."===d||"#"===d?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(p))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,d={message:""};"undefined"==typeof e&&(e="");for(var p=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(p),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){d.message.length>0&&K.displayOnlyLastErrorMsg?d.message=s+(n&&n.params?String.format(a,n.params):a):d.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,d.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);d.message.length>0&&K.displayOnlyLastErrorMsg?d.message=s+o:d.message+=s+o,O(i,e,d.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var d=l.split(".");return t.scope[d[0]][d[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,d=i&&3===i.length?i[1]:0,p=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,d,p)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),d=M(t.condition[0],s,l),p=M(t.condition[1],s,u);r=d&&p}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var d=a.params[0],p=f(r,d);if("boolean"==typeof p)s=!!p;else{if("object"!=typeof p)throw u;s=!!p.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(p.message&&(e+=p.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof p)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),d=t,p=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(d.condition,p.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=d.message;d.altText&&d.altText.length>0&&(o=d.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(d&&d.params?String.format(e,d.params):e),O(r,m,n.message,i,!0)})}p.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],d=f(a,u);if(Y.length>1)for(;Y.length>0;){var p=Y.pop();p&&"function"==typeof p.abort&&p.abort()}if(Y.push(d),!d||"function"!=typeof d.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){d.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled;if(r.elm.prop("disabled")||r.scope.$eval(i))n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var o=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&o.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=p(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=d,X.prototype.initialize=u,X.prototype.mergeObjects=p,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); +angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||A||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||A)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(F){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,A=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,F=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue;if(t&&t.hasOwnProperty("isValidationCancelled")){var n=o(i);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}})}}}]); +angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+(n&&n.params?String.format(a,n.params):a):p.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+o:p.message+=s+o,O(i,e,p.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=l.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],s,l),d=M(t.condition[1],s,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)s=!!d;else{if("object"!=typeof d)throw u;s=!!d.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(p.condition,d.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=p.message;p.altText&&p.altText.length>0&&(o=p.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,i,!0)})}d.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),s=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),l=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(s||l)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; -angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return $=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,g=n.validationAttrs.hasOwnProperty("validateOnEmpty")?commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);$&&n.commonObj.runValidationCallbackOnPromise(t,$)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;aAngular-Validation Directive|Service (ghiscoding) - + - - + diff --git a/more-examples/addon-3rdParty-withScope/index.html b/more-examples/addon-3rdParty-withScope/index.html index 8748bea..c331e76 100644 --- a/more-examples/addon-3rdParty-withScope/index.html +++ b/more-examples/addon-3rdParty-withScope/index.html @@ -53,7 +53,7 @@ - + diff --git a/more-examples/addon-3rdParty/index.html b/more-examples/addon-3rdParty/index.html index fee3533..9377e23 100644 --- a/more-examples/addon-3rdParty/index.html +++ b/more-examples/addon-3rdParty/index.html @@ -119,7 +119,7 @@

ERRORS!

- + diff --git a/package.json b/package.json index a0aed52..4adf768 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.17", + "version": "1.5.18", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": "dist/angular-validation.min", diff --git a/src/validation-common.js b/src/validation-common.js index 972d459..0cfdba6 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -153,10 +153,10 @@ angular // also save it inside controllerAs form (if found) if (!!form && !!form.$name) { var formName = form.$name.indexOf('.') >= 0 ? form.$name.split('.')[1] : form.$name; - var ctrlForm = (!!_globalOptions.controllerAs && !!_globalOptions.controllerAs[formName]) - ? _globalOptions.controllerAs[formName] + var ctrlForm = (!!_globalOptions.controllerAs && !!_globalOptions.controllerAs[formName]) + ? _globalOptions.controllerAs[formName] : ((typeof self.elm.controller() !== "undefined") ? self.elm.controller()[formName] : null); - + if(!!ctrlForm) { ctrlForm.$validationSummary = arrayFindObjects(_validationSummary, 'formName', form.$name); } @@ -542,9 +542,22 @@ angular validator = validatorAutoDetectType(validator, strValue); } - // get the ngDisabled attribute if found + // get the disabled & ngDisabled attributes if found + var elmAttrDisabled = self.elm.prop("disabled"); var elmAttrNgDisabled = (!!self.attrs) ? self.attrs.ngDisabled : self.validatorAttrs.ngDisabled; + var isDisabled = (elmAttrDisabled === "") + ? true + : (typeof elmAttrDisabled === "boolean") + ? elmAttrDisabled + : (typeof elmAttrDisabled !== "undefined") ? self.scope.$eval(elmAttrDisabled) : false; + + var isNgDisabled = (elmAttrNgDisabled === "") + ? true + : (typeof elmAttrNgDisabled === "boolean") + ? elmAttrNgDisabled + : (typeof elmAttrNgDisabled !== "undefined") ? self.scope.$eval(elmAttrNgDisabled) : false; + // now that we have a Validator type, we can now validate our value // there is multiple type that can influence how the value will be validated switch(validator.type) { @@ -569,7 +582,7 @@ angular } // not required and not filled is always valid & 'disabled', 'ng-disabled' elements should always be valid - if ((!self.bFieldRequired && !strValue && !_validateOnEmpty) || (!!self.elm.prop("disabled") || !!self.scope.$eval(elmAttrNgDisabled))) { + if ((!self.bFieldRequired && !strValue && !_validateOnEmpty) || (isDisabled || isNgDisabled)) { isConditionValid = true; } @@ -1404,9 +1417,22 @@ angular // get the ngDisabled attribute if found var elmAttrNgDisabled = (!!self.attrs) ? self.attrs.ngDisabled : self.validatorAttrs.ngDisabled; + var elmAttrDisabled = self.elm.prop("disabled"); + + var isDisabled = (elmAttrDisabled === "") + ? true + : (typeof elmAttrDisabled === "boolean") + ? elmAttrDisabled + : (typeof elmAttrDisabled !== "undefined") ? self.scope.$eval(elmAttrDisabled) : false; + + var isNgDisabled = (elmAttrNgDisabled === "") + ? true + : (typeof elmAttrNgDisabled === "boolean") + ? elmAttrNgDisabled + : (typeof elmAttrNgDisabled !== "undefined") ? self.scope.$eval(elmAttrNgDisabled) : false; // a 'disabled' element should always be valid, there is no need to validate it - if (!!self.elm.prop("disabled") || !!self.scope.$eval(elmAttrNgDisabled)) { + if (isDisabled || isNgDisabled) { isValid = true; } else { // before running Regex test, we'll make sure that an input of type="number" doesn't hold invalid keyboard chars, if true skip Regex diff --git a/src/validation-directive.js b/src/validation-directive.js index fd5e4bb..5ff9517 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -48,7 +48,12 @@ // watch the `disabled` attribute for changes // if it become disabled then skip validation else it becomes enable then we need to revalidate it attrs.$observe("disabled", function(disabled) { - if (disabled) { + var isDisabled = (disabled === "") + ? true + : (typeof disabled === "boolean") ? disabled + : (typeof disabled !== "undefined") ? scope.$eval(disabled) : false; + + if (isDisabled === true) { // Turn off validation when element is disabled & remove it from validation summary cancelValidation(); commonObj.removeFromValidationSummary(_elmName); diff --git a/src/validation-service.js b/src/validation-service.js index 04a8c57..6ce3f73 100644 --- a/src/validation-service.js +++ b/src/validation-service.js @@ -547,7 +547,12 @@ angular // use a timeout so that the digest of removing the `disabled` attribute on the DOM is completed // because commonObj.validate() checks for both the `disabled` and `ng-disabled` attribute so it basically fails without the $timeout because of the digest $timeout(function() { - if (disabled) { + var isDisabled = (disabled === "") + ? true + : (typeof disabled === "boolean") ? disabled + : (typeof disabled !== "undefined") ? scope.$eval(disabled) : false; + + if (isDisabled) { // Remove it from validation summary attrs.ctrl.$setValidity('validation', true); self.commonObj.updateErrorMsg('', { isValid: true, obj: formElmObj }); From 8f5ebf0a537c7c563daab95e9612edd8055efdeb Mon Sep 17 00:00:00 2001 From: Jeremy Solt Date: Mon, 17 Apr 2017 19:57:29 -0500 Subject: [PATCH 05/34] Fix revalidate for directive --- src/validation-directive.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/validation-directive.js b/src/validation-directive.js index 5ff9517..3bd2dcc 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -100,7 +100,8 @@ ctrl.revalidateCalled = true; var value = ctrl.$modelValue; - if (!!elm && elm.hasOwnProperty("isValidationCancelled")) { + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + if (!!formElmObj && formElmObj.hasOwnProperty("isValidationCancelled")) { // attempt to validate & run validation callback if user requested it var validationPromise = attemptToValidate(value); if(!!_validationCallback) { From d253eab5c35cddd9839d9e6adceeb60932b26916 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Mon, 17 Apr 2017 23:46:09 -0400 Subject: [PATCH 06/34] Fix #150 angularValidation.revalidate problems Thanks to @jsolt for fixing the issue --- bower.json | 2 +- changelog.txt | 1 + dist/angular-validation.min.js | 6 +++--- package.json | 2 +- readme.md | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index 835b098..0f464c8 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.18", + "version": "1.5.19", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 31cca7e..e088f53 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.19 (2017-04-17) Fix #150 angularValidation.revalidate problems 1.5.18 (2017-03-31) Fix disabled="false" as attribute to run validation. 1.5.17 (2017-03-10) Add silent mode to checkFormValidity function 1.5.16 (2017-01-24) Fix issue where empty Form Controller was throwing an error diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index a498e12..618e84c 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.18 + * @version: 1.5.19 * @license: MIT - * @build: Fri Mar 31 2017 14:32:56 GMT-0400 (Eastern Daylight Time) + * @build: Mon Apr 17 2017 23:41:06 GMT-0400 (Eastern Daylight Time) */ -angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||A||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||A)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(F){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,A=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,F=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue;if(t&&t.hasOwnProperty("isValidationCancelled")){var n=o(i);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}})}}}]); +angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+(n&&n.params?String.format(a,n.params):a):p.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+o:p.message+=s+o,O(i,e,p.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=l.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],s,l),d=M(t.condition[1],s,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)s=!!d;else{if("object"!=typeof d)throw u;s=!!d.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(p.condition,d.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=p.message;p.altText&&p.altText.length>0&&(o=p.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,i,!0)})}d.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),s=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),l=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(s||l)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return g=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,$=n.validationAttrs.hasOwnProperty("validateOnEmpty")?commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);g&&n.commonObj.runValidationCallbackOnPromise(t,g)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a Date: Thu, 20 Apr 2017 12:20:22 -0400 Subject: [PATCH 07/34] Add unminified version and fix #153 bug in validation service --- bower.json | 2 +- dist/angular-validation.js | 3350 ++++++++++++++++++++++++++++++++ dist/angular-validation.min.js | 6 +- gulpfile.js | 12 + package.json | 2 +- readme.md | 2 +- src/validation-service.js | 2 +- 7 files changed, 3369 insertions(+), 7 deletions(-) create mode 100644 dist/angular-validation.js diff --git a/bower.json b/bower.json index 0f464c8..110ecee 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.19", + "version": "1.5.20", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/dist/angular-validation.js b/dist/angular-validation.js new file mode 100644 index 0000000..323f9fc --- /dev/null +++ b/dist/angular-validation.js @@ -0,0 +1,3350 @@ +/** + * Angular-Validation Directive and Service (ghiscoding) + * http://github.com/ghiscoding/angular-validation + * @author: Ghislain B. + * @version: 1.5.20 + * @license: MIT + * @build: Thu Apr 20 2017 12:18:09 GMT-0400 (Eastern Daylight Time) + */ +/** + * Angular-Validation Directive (ghiscoding) + * https://github.com/ghiscoding/angular-validation + * + * @author: Ghislain B. + * @started: 2014-02-04 + * + * @desc: If a field becomes invalid, the text inside the error or
will show up because the error string gets filled + * Though when the field becomes valid then the error message becomes an empty string, + * it will be transparent to the user even though the still exist but becomes invisible since the text is empty. + * + */ + angular + .module('ghiscoding.validation', ['pascalprecht.translate']) + .directive('validation', ['$q', '$timeout', 'ValidationCommon', function($q, $timeout, ValidationCommon) { + return { + restrict: "A", + require: "ngModel", + link: function(scope, elm, attrs, ctrl) { + // create an object of the common validation + var commonObj = new ValidationCommon(scope, elm, attrs, ctrl); + var _arrayErrorMessage = ''; + var _promises = []; + var _timer; + var _watchers = []; + var _globalOptions = commonObj.getGlobalOptions(); + + // Possible element attributes + var _elmName = attrs.name; + var _validationCallback = (attrs.hasOwnProperty('validationCallback')) ? attrs.validationCallback : null; + var _validateOnEmpty = (attrs.hasOwnProperty('validateOnEmpty')) ? commonObj.parseBool(attrs.validateOnEmpty) : !!_globalOptions.validateOnEmpty; + + //-- Possible validation-array attributes + // on a validation array, how many does it require to be valid? + // As soon as 'one' is valid, or does it need 'all' array values to make the input valid? + var _validArrayRequireHowMany = (attrs.hasOwnProperty('validArrayRequireHowMany')) ? attrs.validArrayRequireHowMany : "one"; + var _validationArrayObjprop = (attrs.hasOwnProperty('validationArrayObjprop')) ? attrs.validationArrayObjprop : null; + + // construct the functions, it's just to make the code cleaner and put the functions at bottom + var construct = { + attemptToValidate: attemptToValidate, + cancelValidation : cancelValidation + } + + // create & save watcher inside an array in case we want to deregister it when removing a validator + _watchers.push({ elmName: _elmName, watcherHandler: createWatch() }); + + // watch the `disabled` attribute for changes + // if it become disabled then skip validation else it becomes enable then we need to revalidate it + attrs.$observe("disabled", function(disabled) { + var isDisabled = (disabled === "") + ? true + : (typeof disabled === "boolean") ? disabled + : (typeof disabled !== "undefined") ? scope.$eval(disabled) : false; + + if (isDisabled === true) { + // Turn off validation when element is disabled & remove it from validation summary + cancelValidation(); + commonObj.removeFromValidationSummary(_elmName); + } else { + // revalidate & re-attach the onBlur event + revalidateAndAttachOnBlur(); + } + }); + + // if DOM element gets destroyed, we need to cancel validation, unbind onBlur & remove it from $validationSummary + elm.on('$destroy', function() { + cancelAndUnbindValidation(); + }); + + // watch for a validation attribute changing to empty, if that is the case, unbind everything from it + scope.$watch(function() { + return elm.attr('validation'); + }, function(validation) { + if(typeof validation === "undefined" || validation === '') { + // if validation gets empty, we need to cancel validation, unbind onBlur & remove it from $validationSummary + cancelAndUnbindValidation(); + }else { + // If validation attribute gets filled/re-filled (could be by interpolation) + // we need to redefine the validation so that we can grab the new "validation" element attribute + // and finally revalidate & re-attach the onBlur event + commonObj.defineValidation(); + revalidateAndAttachOnBlur(); + + // if watcher not already exist, then create & save watcher inside an array in case we want to deregister it later + var foundWatcher = commonObj.arrayFindObject(_watchers, 'elmName', ctrl.$name); + if(!foundWatcher) { + _watchers.push({ elmName: _elmName, watcherHandler: createWatch() }); + } + } + }); + + // attach the onBlur event handler on the element + elm.bind('blur', blurHandler); + + // attach the angularValidation.revalidate event handler on the scope + scope.$on('angularValidation.revalidate', function(event, args){ + if (args == ctrl.$name) + { + ctrl.revalidateCalled = true; + var value = ctrl.$modelValue; + + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + if (!!formElmObj && formElmObj.hasOwnProperty("isValidationCancelled")) { + // attempt to validate & run validation callback if user requested it + var validationPromise = attemptToValidate(value); + if(!!_validationCallback) { + commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + } + else { + ctrl.$setValidity('validation', true); + } + } + }); + + //---- + // Private functions declaration + //---------------------------------- + + /** Validator function to attach to the element, this will get call whenever the input field is updated + * and is also customizable through the (typing-limit) for which inactivity this.timer will trigger validation. + * @param string value: value of the input field + * @param int typingLimit: when user stop typing, in how much time it will start validating + * @return object validation promise + */ + function attemptToValidate(value, typingLimit) { + var deferred = $q.defer(); + var isValid = false; + + // get the waiting delay time if passed as argument or get it from common Object + var waitingLimit = (typeof typingLimit !== "undefined") ? typingLimit : commonObj.typingLimit; + + // get the form element custom object and use it after + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + + // if the input value is an array (like a 3rd party addons) then attempt to validate + // by exploding the array into individual input values and then validate them one value by one + if(Array.isArray(value)) { + // reset the promises array + _promises = []; + _arrayErrorMessage = ''; + waitingLimit = 0; + + // If we get a filled array, we will explode the array and try to validate each input value independently and + // Else when array is or become empty, we still want to validate it but without waiting time, + // a "required" validation needs to be invalid right away. + // NOTE: because most 3rd party addons support AngularJS older than 1.3, the $touched property on the element is most often not implemented + // but is required for Angular-Validation to properly display error messages and I have to force a $setTouched and by doing so force to show error message instantly on screen. + // unless someone can figure out a better approach that is universal to all addons. I could in fact also use $dirty but even that is most often not implement by adons either. + if(value.length > 0) { + // make the element as it was touched for CSS, only works in AngularJS 1.3+ + if (typeof formElmObj.ctrl.$setTouched === "function") { + formElmObj.ctrl.$setTouched(); + } + return explodeArrayAndAttemptToValidate(value, typeof value); + }else { + waitingLimit = 0; + } + } + + // if a field holds invalid characters which are not numbers inside an `input type="number"`, then it's automatically invalid + // we will still call the `.validate()` function so that it shows also the possible other error messages + if(!!value && !!value.badInput) { + return invalidateBadInputField(); + } + + // pre-validate without any events just to pre-fill our validationSummary with all field errors + // passing False as the 2nd argument to hide errors from being displayed on screen + commonObj.validate(value, false); + + // if field is not required and his value is empty, cancel validation and exit out + if(!commonObj.isFieldRequired() && !_validateOnEmpty && (value === "" || value === null || typeof value === "undefined")) { + cancelValidation(); + deferred.resolve({ isFieldValid: true, formElmObj: formElmObj, value: value }); + return deferred.promise; + }else if(!!formElmObj) { + formElmObj.isValidationCancelled = false; + } + + // invalidate field before doing any validation + if(!!value || commonObj.isFieldRequired() || _validateOnEmpty) { + ctrl.$setValidity('validation', false); + } + + // select(options) will be validated on the spot + if(elm.prop('tagName').toUpperCase() === "SELECT") { + isValid = commonObj.validate(value, true); + ctrl.$setValidity('validation', isValid); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + return deferred.promise; + } + + // onKeyDown event is the default of Angular, no need to even bind it, it will fall under here anyway + // in case the field is already pre-filled, we need to validate it without looking at the event binding + if(typeof value !== "undefined") { + // when no timer, validate right away without a $timeout. This seems quite important on the array input value check + if(typingLimit === 0) { + isValid = commonObj.validate(value, true); + scope.$evalAsync(ctrl.$setValidity('validation', isValid )); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + $timeout.cancel(_timer); + }else { + // Start validation only after the user has stopped typing in a field + // everytime a new character is typed, it will cancel/restart the timer & we'll erase any error mmsg + commonObj.updateErrorMsg(''); + $timeout.cancel(_timer); + _timer = $timeout(function() { + isValid = commonObj.validate(value, true); + scope.$evalAsync(ctrl.$setValidity('validation', isValid )); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + }, waitingLimit); + } + } + + return deferred.promise; + } // attemptToValidate() + + /** Attempt to validate an input value that was previously exploded from the input array + * Each attempt will return a promise but only after reaching the last index, will we analyze the final validation. + * @param string: input value + * @param int: position index + * @param int: size of original array + */ + function attemptToValidateArrayInput(inputValue, index, arraySize) { + var promise = attemptToValidate(inputValue, 0); + if(!!promise && typeof promise.then === "function") { + _promises.push(promise); + + // if we reached the last index + // then loop through all promises to run validation on each array input values + if(parseInt(index) === (arraySize - 1)) { + _promises.forEach(function(promise) { + promise.then(function(result) { + // user requires how many values of the array to make the form input to be valid? + // If require "one", as soon as an array value changes is valid, the complete input becomes valid + // If require "all", as soon as an array value changes is invalid, the complete input becomes invalid + switch(_validArrayRequireHowMany) { + case "all" : + if(result.isFieldValid === false) { + result.formElmObj.translatePromise.then(function(translation) { + // if user is requesting to see only the last error message, we will use '=' instead of usually concatenating with '+=' + // then if validator rules has 'params' filled, then replace them inside the translation message (foo{0} {1}...), same syntax as String.format() in C# + if (_arrayErrorMessage.length > 0 && _globalOptions.displayOnlyLastErrorMsg) { + _arrayErrorMessage = '[' + result.value + '] :: ' + ((!!result.formElmObj.validator && !!result.formElmObj.validator.params) ? String.format(translation, result.formElmObj.validator.params) : translation); + } else { + _arrayErrorMessage += ' [' + result.value + '] :: ' + ((!!result.formElmObj.validator && !!result.formElmObj.validator.params) ? String.format(translation, result.formElmObj.validator.params) : translation); + } + commonObj.updateErrorMsg(_arrayErrorMessage, { isValid: false }); + commonObj.addToValidationSummary(result.formElmObj, _arrayErrorMessage); + }); + } + break; + case "one" : + default : + if(result.isFieldValid === true) { + ctrl.$setValidity('validation', true); + cancelValidation(); + } + } + }); + }); + } + } + } + + /** Definition of our blur event handler that will be used to attached on an element + * @param object event + */ + function blurHandler(event) { + // get the form element custom object and use it after + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + var value = (typeof ctrl.$modelValue !== "undefined") ? ctrl.$modelValue : event.target.value; + + if (!!formElmObj && formElmObj.hasOwnProperty("isValidationCancelled")) { + // attempt to validate & run validation callback if user requested it + var validationPromise = attemptToValidate(value, 0); + if(!!_validationCallback) { + commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + }else { + ctrl.$setValidity('validation', true); + } + } + + /** Explode the input array and attempt to validate every single input values that comes out of it. + * Input array could be passed as 2 different types (array of string, array of objects) + * If we are dealing with an array of strings, we will consider the strings being the input value to validate + * But if instead it is an array of objects, we need to user to provide which object property name to use + * ex. : array of objects, var arrObj = [{ id: 1, label: 'tag1' }, { id: 2, label: 'tag2' }] + * --> we want the user to tell the directive that the input values are in the property name 'label' + * @param Array: input array + * @param string: array type + */ + function explodeArrayAndAttemptToValidate(inputArray, arrayType) { + var arraySize = inputArray.length; + + // array of strings, 1 for loop to get all input values + if(arrayType === "string") { + for (var key in inputArray) { + attemptToValidateArrayInput(inputArray[key], key, arraySize); + } + } + // array of objects, 2 for loops to get all input values via an object property name defined by the user + else if(arrayType === "object") { + for (var key in inputArray) { + if (inputArray.hasOwnProperty(key)) { + var obj = inputArray[key]; + for (var prop in obj) { + // check if there's a property on the object, compare it to what the user defined as the object property label + // then attempt to validate the array input value + if(obj.hasOwnProperty(prop)) { + if(!!_validationArrayObjprop && prop !== _validationArrayObjprop) { + continue; + } + attemptToValidateArrayInput(obj[prop], key, arraySize); + } + } + } + } + } + } + + /** Cancel the validation, unbind onBlur and remove from $validationSummary */ + function cancelAndUnbindValidation() { + // unbind everything and cancel the validation + cancelValidation(); + commonObj.removeFromValidationSummary(_elmName); + + // deregister the $watch from the _watchers array we kept it + var foundWatcher = commonObj.arrayFindObject(_watchers, 'elmName', ctrl.$name); + if(!!foundWatcher && typeof foundWatcher.watcherHandler === "function") { + var deregister = foundWatcher.watcherHandler(); // deregister the watch by calling his handler + _watchers.shift(); + } + } + + /** Cancel current validation test and blank any leftover error message */ + function cancelValidation() { + // get the form element custom object and use it after + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + if(!!formElmObj) { + formElmObj.isValidationCancelled = true; + } + $timeout.cancel(_timer); + commonObj.updateErrorMsg(''); + ctrl.$setValidity('validation', true); + + // unbind onBlur handler (if found) so that it does not fail on a non-required element that is now dirty & empty + unbindBlurHandler(); + } + + /** watch the element for any value change, validate it once that happen + * @return new watcher + */ + function createWatch() { + return scope.$watch(function() { + var modelValue = ctrl.$modelValue; + if(isKeyTypedBadInput()) { + return { badInput: true }; + } + else if(!!_validationArrayObjprop && Array.isArray(modelValue) && modelValue.length === 0 && Object.keys(modelValue).length > 0) { + // when the modelValue is an Array but is length 0, this mean it's an Object disguise as an array + // since an Array of length 0 won't trigger a watch change, we need to return it back to an object + // for example Dropdown Multiselect when using selectionLimit of 1 will return [id: 1, label: 'John'], what we really want is the object { id: 1, label: 'John'} + // convert the object array to a real object that will go inside an array + var arr = [], obj = {}; + obj[_validationArrayObjprop] = modelValue[_validationArrayObjprop]; // convert [label: 'John'] to {label: 'John'} + arr.push(obj); // push to array: [{label: 'John'}] + return arr; + } + return modelValue; + }, function(newValue, oldValue) { + if(!!newValue && !!newValue.badInput) { + unbindBlurHandler(); + return invalidateBadInputField(); + } + // attempt to validate & run validation callback if user requested it + var validationPromise = attemptToValidate(newValue); + if(!!_validationCallback) { + commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + }, true); + } + + /** Invalidate the field that was tagged as bad input, cancel the timer validation, + * display an invalid key error and add it as well to the validation summary. + */ + function invalidateBadInputField() { + $timeout.cancel(_timer); + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + commonObj.updateErrorMsg('INVALID_KEY_CHAR', { isValid: false, translate: true }); + commonObj.addToValidationSummary(formElmObj, 'INVALID_KEY_CHAR', true); + } + + /** Was the characters typed by the user bad input or not? + * @return bool + */ + function isKeyTypedBadInput() { + return (!!elm.prop('validity') && elm.prop('validity').badInput === true); + } + + /** Re-evaluate the element and revalidate it, also re-attach the onBlur event on the element */ + function revalidateAndAttachOnBlur() { + // Revalidate the input when enabled (without displaying the error) + var value = ctrl.$modelValue || ''; + if(!Array.isArray(value)) { + ctrl.$setValidity('validation', commonObj.validate(value, false)); + } + + // get the form element custom object and use it after + var formElmObj = commonObj.getFormElementByName(ctrl.$name); + if(!!formElmObj) { + formElmObj.isValidationCancelled = false; // make sure validation re-enabled as well + } + + // unbind previous handler (if any) not to have double handlers and then re-attach just 1 handler + unbindBlurHandler(); + elm.bind('blur', blurHandler); + } + + /** If found unbind the blur handler */ + function unbindBlurHandler() { + if(typeof blurHandler === "function") { + elm.unbind('blur', blurHandler); + } + } + + } // link() + }; // return; + }]); // directive +/** + * angular-validation-common (ghiscoding) + * https://github.com/ghiscoding/angular-validation + * + * @author: Ghislain B. + * @desc: angular-validation common functions used by both the Directive & Service + * + */ +angular + .module('ghiscoding.validation') + .factory('ValidationCommon', ['$rootScope', '$timeout', '$translate', 'ValidationRules', function ($rootScope, $timeout, $translate, ValidationRules) { + // global variables of our object (start with _var), these variables are shared between the Directive & Service + var _bFieldRequired = false; // by default we'll consider our field not required, if validation attribute calls it, then we'll start validating + var _INACTIVITY_LIMIT = 1000; // constant of maximum user inactivity time limit, this is the default cosntant but can be variable through typingLimit variable + var _formElements = []; // Array of all Form Elements, this is not a DOM Elements, these are custom objects defined as { fieldName, elm, attrs, ctrl, isValid, message } + var _globalOptions = { // Angular-Validation global options, could be define by scope.$validationOptions or by validationService.setGlobalOptions() + resetGlobalOptionsOnRouteChange: true // do we want to reset the Global Options on a route change? True by default + }; + var _remotePromises = []; // keep track of promises called and running when using the Remote validator + var _validationSummary = []; // Array Validation Error Summary + var _validateOnEmpty = false; // do we want to validate on empty field? False by default + + // watch on route change, then reset some global variables, so that we don't carry over other controller/view validations + $rootScope.$on("$routeChangeStart", function (event, next, current) { + resetGlobalOptions(_globalOptions.resetGlobalOptionsOnRouteChange); + }); + $rootScope.$on("$stateChangeStart", function (event, next, current) { + resetGlobalOptions(_globalOptions.resetGlobalOptionsOnRouteChange); + }); + + // service constructor + var validationCommon = function (scope, elm, attrs, ctrl) { + this.bFieldRequired = false; // by default we'll consider our field as not required, if validation attribute calls it, then we'll start validating + this.validators = []; + this.typingLimit = _INACTIVITY_LIMIT; + this.scope = scope; + this.elm = elm; + this.ctrl = ctrl; + this.validatorAttrs = attrs; + this.validateOnEmpty = false; // do we want to always validate, even when field isn't required? False by default + this.validRequireHowMany = "all"; + + if(!!scope && !!scope.$validationOptions) { + _globalOptions = scope.$validationOptions; // save the global options + } + + // user could pass his own scope, useful in a case of an isolate scope + if (!!scope && (!!_globalOptions.isolatedScope || !!_globalOptions.scope)) { + this.scope = _globalOptions.isolatedScope || _globalOptions.scope; // overwrite original scope (isolatedScope/scope are equivalent arguments) + _globalOptions = mergeObjects(scope.$validationOptions, _globalOptions); // reuse the validationOption from original scope + } + + // if the resetGlobalOptionsOnRouteChange doesn't exist, make sure to set it to True by default + if(typeof _globalOptions.resetGlobalOptionsOnRouteChange === "undefined") { + _globalOptions.resetGlobalOptionsOnRouteChange = true; + } + + // only the angular-validation Directive can possibly reach this condition with all properties filled + // on the other hand the angular-validation Service will `initialize()` function to initialize the same set of variables + if (!!this.elm && !!this.validatorAttrs && !!this.ctrl && !!this.scope) { + addToFormElementObjectList(this.elm, this.validatorAttrs, this.ctrl, this.scope); + this.defineValidation(); + } + }; + + // list of available published public functions of this object + validationCommon.prototype.addToValidationSummary = addToValidationSummary; // add an element to the $validationSummary + validationCommon.prototype.arrayFindObject = arrayFindObject; // search an object inside an array of objects + validationCommon.prototype.defineValidation = defineValidation; // define our validation object + validationCommon.prototype.getFormElementByName = getFormElementByName; // get the form element custom object by it's name + validationCommon.prototype.getFormElements = getFormElements; // get the array of form elements (custom objects) + validationCommon.prototype.getGlobalOptions = getGlobalOptions; // get the global options used by all validators (usually called by the validationService) + validationCommon.prototype.isFieldRequired = isFieldRequired; // return boolean knowing if the current field is required + validationCommon.prototype.initialize = initialize; // initialize current object with passed arguments + validationCommon.prototype.mergeObjects = mergeObjects; // merge 2 javascript objects, Overwrites obj1's values with obj2's (basically Object2 as higher priority over Object1) + validationCommon.prototype.parseBool = parseBool; // parse a boolean value, string or bool + validationCommon.prototype.removeFromValidationSummary = removeFromValidationSummary; // remove an element from the $validationSummary + validationCommon.prototype.removeFromFormElementObjectList = removeFromFormElementObjectList; // remove named items from formElements list + validationCommon.prototype.runValidationCallbackOnPromise = runValidationCallbackOnPromise; // run a validation callback method when the promise resolve + validationCommon.prototype.setDisplayOnlyLastErrorMsg = setDisplayOnlyLastErrorMsg; // setter on the behaviour of displaying only the last error message + validationCommon.prototype.setGlobalOptions = setGlobalOptions; // set global options used by all validators (usually called by the validationService) + validationCommon.prototype.updateErrorMsg = updateErrorMsg; // update on screen an error message below current form element + validationCommon.prototype.validate = validate; // validate current element + + // override some default String functions + if(window.Element && !Element.prototype.closest) { + Element.prototype.closest = elementPrototypeClosest; // Element Closest Polyfill for the browsers that don't support it (fingers point to IE) + } + String.prototype.trim = stringPrototypeTrim; // extend String object to have a trim function + String.prototype.format = stringPrototypeFormat; // extend String object to have a format function like C# + String.format = stringFormat; // extend String object to have a format function like C# + + + // return the service object + return validationCommon; + + //---- + // Public functions declaration + //---------------------------------- + + /** Add the error to the validation summary + * @param object self + * @param string message: error message + * @param bool need to translate: false by default + */ + function addToValidationSummary(self, message, needToTranslate) { + if (typeof self === "undefined" || self == null) { + return; + } + + // get the element name, whichever we find it + var elmName = (!!self.ctrl && !!self.ctrl.$name) + ? self.ctrl.$name + : (!!self.attrs && !!self.attrs.name) + ? self.attrs.name + : self.elm.attr('name'); + + var form = getElementParentForm(elmName, self); // find the parent form (only found if it has a name) + var index = arrayFindObjectIndex(_validationSummary, 'field', elmName); // find index of object in our array + + // if message is empty, remove it from the validation summary + if (index >= 0 && message === '') { + _validationSummary.splice(index, 1); + } else if (message !== '') { + if(!!needToTranslate) { + message = $translate.instant(message); + } + var friendlyName = (!!self.attrs && !!self.friendlyName) ? $translate.instant(self.friendlyName) : ''; + var errorObj = { field: elmName, friendlyName: friendlyName, message: message, formName: (!!form) ? form.$name : null }; + + // if error already exist then refresh the error object inside the array, else push it to the array + if (index >= 0) { + _validationSummary[index] = errorObj; + } else { + _validationSummary.push(errorObj); + } + } + + // save validation summary into scope root + self.scope.$validationSummary = _validationSummary; + + // and also save it inside the current scope form (if found) + if (!!form) { + // since validationSummary contain errors of all forms + // we need to find only the errors of current form and them into the current scope form object + form.$validationSummary = arrayFindObjects(_validationSummary, 'formName', form.$name); + } + + // also save it inside the ControllerAs alias if it was passed in the global options + if (!!_globalOptions && !!_globalOptions.controllerAs) { + _globalOptions.controllerAs.$validationSummary = _validationSummary; + + // also save it inside controllerAs form (if found) + if (!!form && !!form.$name) { + var formName = form.$name.indexOf('.') >= 0 ? form.$name.split('.')[1] : form.$name; + var ctrlForm = (!!_globalOptions.controllerAs && !!_globalOptions.controllerAs[formName]) + ? _globalOptions.controllerAs[formName] + : ((typeof self.elm.controller() !== "undefined") ? self.elm.controller()[formName] : null); + + if(!!ctrlForm) { + ctrlForm.$validationSummary = arrayFindObjects(_validationSummary, 'formName', form.$name); + } + } + } + + return _validationSummary; + } + + /** Define our validation object + * @return object self + */ + function defineValidation() { + var self = this; + var customUserRegEx = {}; + self.validators = []; // reset the global validators + + // analyze the possible element attributes + self = analyzeElementAttributes(self); + + // get the rules(or validation), inside directive it's named (validation), inside service(rules) + var rules = self.validatorAttrs.rules || self.validatorAttrs.validation; + + // We first need to see if the validation holds a custom user regex, if it does then deal with it first + // So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe + if(rules.indexOf("pattern=/") >= 0) { + var matches = rules.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/); + if (!matches || matches.length < 3) { + throw 'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.'; + } + var pattern = matches[1]; + var altMsg = (!!matches[2]) ? matches[2].replace(/\|(.*)/, '') : ''; + + // convert the string into a real RegExp pattern + var match = pattern.match(new RegExp('^/(.*?)/([gimy]*)$')); + var regex = new RegExp(match[1], match[2]); + + customUserRegEx = { + altMsg: altMsg, + message: altMsg.replace(/:alt=/, ''), + pattern: regex + }; + + // rewrite the rules so that it doesn't contain any regular expression + // we simply remove the pattern so that it won't break the Angular-Validation since it also use the pipe | + rules = rules.replace('pattern=' + pattern, 'pattern'); + } + // DEPRECATED, in prior version of 1.3.34 and less, the way of writing a regular expression was through regex:/.../:regex + // this is no longer supported but is still part of the code so that it won't break for anyone using previous way of validating + // Return string will have the complete regex pattern removed but we will keep ':regex' so that we can still loop over it + else if (rules.indexOf("regex:") >= 0) { + var matches = rules.match("regex:(.*?):regex"); + if (matches.length < 2) { + throw 'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.'; + } + var regAttrs = matches[1].split(':='); + customUserRegEx = { + message: regAttrs[0], + pattern: regAttrs[1] + }; + + // rewrite the rules so that it doesn't contain the regex: ... :regex ending + // we simply remove it so that it won't break if there's a pipe | inside the actual regex + rules = rules.replace(matches[0], 'regex:'); + } + + // at this point it's safe to split with pipe (since regex was previously stripped out) + var validations = rules.split('|'); + + if (validations) { + self.bFieldRequired = (rules.indexOf("required") >= 0); + + // loop through all validators of the element + for (var i = 0, ln = validations.length; i < ln; i++) { + // check if user provided an alternate text to his validator (validator:alt=Alternate Text) + var posAltText = validations[i].indexOf("alt="); + var hasAltText = posAltText >= 0; + var params = []; + + // alternate text might have the character ":" inside it, so we need to compensate + // since altText is always at the end, we can before the altText and add back this untouched altText to our params array + if(hasAltText) { + params = validations[i].substring(0,posAltText-1).split(':'); // split before altText, so we won't touch it + params.push(validations[i].substring(posAltText)); // add back the altText to our split params array + }else { + // params split will be:: [0]=rule, [1]=ruleExtraParams OR altText, [2] altText + params = validations[i].split(':'); + } + + self.validators[i] = ValidationRules.getElementValidators({ + altText: hasAltText === true ? (params.length === 2 ? params[1] : params[2]) : '', + customRegEx: customUserRegEx, + rule: params[0], + ruleParams: (hasAltText && params.length === 2) ? null : params[1] + }); + } + } + return self; + } // defineValidation() + + /** Return a Form element object by it's name + * @param string element input name + * @return array object elements + */ + function getFormElementByName(elmName) { + return arrayFindObject(_formElements, 'fieldName', elmName); + } + + /** Return all Form elements + * @param string form name + * @return array object elements + */ + function getFormElements(formName) { + if(!!formName) { + return arrayFindObjects(_formElements, 'formName', formName); + } + return _formElements; + } + + /** Get global options used by all validators + * @return object global options + */ + function getGlobalOptions() { + return _globalOptions; + } + + /** Initialize the common object + * @param object scope + * @param object elm + * @param object attrs + * @param object ctrl + */ + function initialize(scope, elm, attrs, ctrl) { + this.scope = scope; + this.elm = elm; + this.ctrl = ctrl; + this.validatorAttrs = attrs; + + addToFormElementObjectList(elm, attrs, ctrl, scope); + this.defineValidation(); + } + + /** @return isFieldRequired */ + function isFieldRequired() { + var self = this; + return self.bFieldRequired; + } + + /** + * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1 + * When both object have the same property, the Object2 will higher priority over Object1 (basically that property will be overwritten inside Object1) + * @param obj1 + * @param obj2 + * @return obj3 a new object based on obj1 and obj2 + */ + function mergeObjects(obj1, obj2) { + var obj3 = {}; + for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; } + for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; } + + return obj3; + } + + /** Remove objects from FormElement list. + * @param element input name to remove + */ + function removeFromFormElementObjectList(elmName) { + var index = arrayFindObjectIndex(_formElements, 'fieldName', elmName); // find index of object in our array + if (index >= 0) { + _formElements.splice(index, 1); + } + } + + /** Remove an element from the $validationSummary array + * @param string elmName: element name + * @param object validationSummary + */ + function removeFromValidationSummary(elmName, validationSummaryObj) { + var self = this; + var form = getElementParentForm(elmName, self); // find the parent form (only found if it has a name) + var vsObj = validationSummaryObj || _validationSummary; + + var index = arrayFindObjectIndex(vsObj, 'field', elmName); // find index of object in our array + // if message is empty, remove it from the validation summary object + if (index >= 0) { + vsObj.splice(index, 1); + } + // also remove from 'local' validationSummary + index = arrayFindObjectIndex(_validationSummary, 'field', elmName); // find index of object in our array + if (index >= 0) { + _validationSummary.splice(index, 1); + } + + self.scope.$validationSummary = _validationSummary; + + // overwrite the scope form (if found) + if (!!form) { + // since validationSummary contain errors of all forms + // we need to find only the errors of current form and them into the current scope form object + form.$validationSummary = arrayFindObjects(_validationSummary, 'formName', form.$name); + } + + // overwrite the ControllerAs alias if it was passed in the global options + if (!!_globalOptions && !!_globalOptions.controllerAs) { + _globalOptions.controllerAs.$validationSummary = _validationSummary; + + // also overwrite it inside controllerAs form (if found) + if (!!form) { + var formName = form.$name.indexOf('.') >= 0 ? form.$name.split('.')[1] : form.$name; + if(!!_globalOptions.controllerAs[formName]) { + _globalOptions.controllerAs[formName].$validationSummary = arrayFindObjects(_validationSummary, 'formName', form.$name); + } + } + } + + + return _validationSummary; + } + + /** Evaluate a function name passed as string and run it from the scope. + * The function name could be passed with/without brackets "()", in any case we will run the function + * @param object self object + * @param string function passed as a string + * @param mixed result + */ + function runEvalScopeFunction(self, fnString) { + var result; + + // Find if our function has the brackets "()" + // if yes then run it through $eval else find it in the scope and then run it + if(/\({1}.*\){1}/gi.test(fnString)) { + result = self.scope.$eval(fnString); + }else { + var fct = objectFindById(self.scope, fnString, '.'); + if(typeof fct === "function") { + result = fct(); + } + } + return result; + } + + /** Run a validation callback function once the promise return + * @param object validation promise + * @param string callback function name (could be with/without the brackets () ) + */ + function runValidationCallbackOnPromise(promise, callbackFct) { + var self = this; + + if(typeof promise.then === "function") { + promise.then(function() { + runEvalScopeFunction(self, callbackFct); + }); + } + } + + /** Setter on the behaviour of displaying only the last error message of each element. + * By default this is false, so the behavior is to display all error messages of each element. + * @param boolean value + */ + function setDisplayOnlyLastErrorMsg(boolValue) { + _globalOptions.displayOnlyLastErrorMsg = boolValue; + } + + /** Set and initialize global options used by all validators + * @param object attrs: global options + * @return object self + */ + function setGlobalOptions(options) { + var self = this; + + // merge both attributes but 2nd object (attrs) as higher priority, so that for example debounce property inside `attrs` as higher priority over `validatorAttrs` + // so the position inside the mergeObject call is very important + _globalOptions = mergeObjects(_globalOptions, options); // save in global + + return self; + } + + /** in general we will display error message at the next element after our input as + * but in some cases user might want to define which DOM id to display error (as validation attribute) + * @param string message: error message to display + * @param object arguments that could be passed to the function + */ + function updateErrorMsg(message, attrs) { + var self = this; + + // attrs.obj if set, should be a commonObj, and can be self. + // In addition we need to set validatorAttrs, as they are defined as attrs on obj. + if (!!attrs && attrs.obj) { + self = attrs.obj; + self.validatorAttrs = attrs.obj.attrs; + } + + // element name could be defined in the `attrs` or in the self object + var elm = (!!attrs && attrs.elm) ? attrs.elm : self.elm; + var elmName = (!!elm && elm.attr('name')) ? elm.attr('name') : null; + + // Make sure that element has a name="" attribute else it will not work + if (typeof elmName === "undefined" || elmName === null) { + var ngModelName = (!!elm) ? elm.attr('ng-model') : 'unknown'; + throw 'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="' + ngModelName + '"'; + } + + // user might have passed a message to be translated + var errorMsg = (!!attrs && !!attrs.translate) ? $translate.instant(message) : message; + errorMsg = errorMsg.trim(); + + // get the name attribute of current element, make sure to strip dirty characters, for example remove a , we need to strip the "[]" + // also replace any possible '.' inside the input name by '-' + var elmInputName = elmName.replace(/[|&;$%@"<>()+,\[\]\{\}]/g, '').replace(/\./g, '-'); + var errorElm = null; + + // find the element which we'll display the error message, this element might be defined by the user with 'validationErrorTo' + if (!!self.validatorAttrs && self.validatorAttrs.hasOwnProperty('validationErrorTo')) { + // validationErrorTo can be used in 3 different ways: with '.' (element error className) or with/without '#' (element error id) + var firstChar = self.validatorAttrs.validationErrorTo.charAt(0); + var selector = (firstChar === '.' || firstChar === '#') ? self.validatorAttrs.validationErrorTo : '#' + self.validatorAttrs.validationErrorTo; + errorElm = angular.element(document.querySelector(selector)); + } + // errorElm can be empty due to: + // 1. validationErrorTo has not been set + // 2. validationErrorTo has been mistyped, and if mistyped, use regular functionality + if (!errorElm || errorElm.length === 0) { + // most common way, let's try to find our + errorElm = angular.element(document.querySelector('.validation-' + elmInputName)); + } + + // form might have already been submitted + var isSubmitted = (!!attrs && attrs.isSubmitted) ? attrs.isSubmitted : false; + + // invalid & isDirty, display the error message... if not exist then create it, else udpate the text + if (!_globalOptions.hideErrorUnderInputs && !!attrs && !attrs.isValid && (isSubmitted || self.ctrl.$dirty || self.ctrl.$touched || self.ctrl.revalidateCalled)) { + (errorElm.length > 0) ? errorElm.html(errorMsg) : elm.after('
' + errorMsg + '
'); + self.ctrl.isErrorMessageVisible = true; + } else { + errorElm.html(''); // element is pristine or no validation applied, error message has to be blank + self.ctrl.isErrorMessageVisible = undefined; + } + } + + /** Validate function, from the input value it will go through all validators (separated by pipe) + * that were passed to the input element and will validate it. If field is invalid it will update + * the error text of the span/div element dedicated for that error display. + * @param string value: value of the input field + * @param bool showError: do we want to show the error or hide it (false is useful for adding error to $validationSummary without displaying it on screen) + * @return bool isFieldValid + */ + function validate(strValue, showError) { + var self = this; + var isConditionValid = true; + var isFieldValid = true; + var nbValid = 0; + var validator; + var validatedObject = {}; + + // make an object to hold the message so that we can reuse the object by reference + // in some of the validation check (for example "matching" and "remote") + var validationElmObj = { + message: '' + } + + // to make proper validation, our element value cannot be an undefined variable (we will at minimum make it an empty string) + // For example, in some particular cases "undefined" returns always True on regex.test() which is incorrect especially on max_len:x + if (typeof strValue === "undefined") { + strValue = ''; + } + + // get some common variables + var elmName = (!!self.ctrl && !!self.ctrl.$name) + ? self.ctrl.$name + : (!!self.attrs && !!self.attrs.name) + ? self.attrs.name + : self.elm.attr('name'); + + var formElmObj = getFormElementByName(elmName); + var rules = self.validatorAttrs.rules || self.validatorAttrs.validation; + + // loop through all validators (could be multiple) + for (var j = 0, jln = self.validators.length; j < jln; j++) { + validator = self.validators[j]; + + // When AutoDetect it will auto-detect the type and rewrite the conditions or regex pattern, depending on type found + if (validator.type === "autoDetect") { + validator = validatorAutoDetectType(validator, strValue); + } + + // get the disabled & ngDisabled attributes if found + var elmAttrDisabled = self.elm.prop("disabled"); + var elmAttrNgDisabled = (!!self.attrs) ? self.attrs.ngDisabled : self.validatorAttrs.ngDisabled; + + var isDisabled = (elmAttrDisabled === "") + ? true + : (typeof elmAttrDisabled === "boolean") + ? elmAttrDisabled + : (typeof elmAttrDisabled !== "undefined") ? self.scope.$eval(elmAttrDisabled) : false; + + var isNgDisabled = (elmAttrNgDisabled === "") + ? true + : (typeof elmAttrNgDisabled === "boolean") + ? elmAttrNgDisabled + : (typeof elmAttrNgDisabled !== "undefined") ? self.scope.$eval(elmAttrNgDisabled) : false; + + // now that we have a Validator type, we can now validate our value + // there is multiple type that can influence how the value will be validated + switch(validator.type) { + case "conditionalDate": + isConditionValid = validateConditionalDate(strValue, validator, rules); + break; + case "conditionalNumber": + isConditionValid = validateConditionalNumber(strValue, validator); + break; + case "javascript": + isConditionValid = validateCustomJavascript(strValue, validator, self, formElmObj, showError, validationElmObj); + break; + case "matching": + isConditionValid = validateMatching(strValue, validator, self, validationElmObj); + break; + case "remote": + isConditionValid = validateRemote(strValue, validator, self, formElmObj, showError, validationElmObj); + break; + default: + isConditionValid = validateWithRegex(strValue, validator, rules, self); + break; + } + + // not required and not filled is always valid & 'disabled', 'ng-disabled' elements should always be valid + if ((!self.bFieldRequired && !strValue && !_validateOnEmpty) || (isDisabled || isNgDisabled)) { + isConditionValid = true; + } + + if (!isConditionValid) { + isFieldValid = false; + + // run $translate promise, use closures to keep access to all necessary variables + (function (formElmObj, isConditionValid, validator) { + var msgToTranslate = validator.message; + var errorMessageSeparator = _globalOptions.errorMessageSeparator || ' '; + if (!!validator.altText && validator.altText.length > 0) { + msgToTranslate = validator.altText.replace("alt=", ""); + } + + var trsltPromise = $translate(msgToTranslate); + formElmObj.translatePromise = trsltPromise; + formElmObj.validator = validator; + + trsltPromise.then(function (translation) { + // if user is requesting to see only the last error message, we will use '=' instead of usually concatenating with '+=' + // then if validator rules has 'params' filled, then replace them inside the translation message (foo{0} {1}...), same syntax as String.format() in C# + if (validationElmObj.message.length > 0 && _globalOptions.displayOnlyLastErrorMsg) { + validationElmObj.message = errorMessageSeparator + ((!!validator && !!validator.params) ? String.format(translation, validator.params) : translation); + } else { + validationElmObj.message += errorMessageSeparator + ((!!validator && !!validator.params) ? String.format(translation, validator.params) : translation); + } + addToValidationAndDisplayError(self, formElmObj, validationElmObj.message, isFieldValid, showError); + }) + ["catch"](function (data) { + // error caught: + // alternate text might not need translation if the user sent his own custom message or is already translated + // so just send it directly into the validation summary. + if (!!validator.altText && validator.altText.length > 0) { + // if user is requesting to see only the last error message + if (validationElmObj.message.length > 0 && _globalOptions.displayOnlyLastErrorMsg) { + validationElmObj.message = errorMessageSeparator + msgToTranslate; + } else { + validationElmObj.message += errorMessageSeparator + msgToTranslate; + } + addToValidationAndDisplayError(self, formElmObj, validationElmObj.message, isFieldValid, showError); + } else { + throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.", data); + } + }); + })(formElmObj, isConditionValid, validator); + } // if(!isConditionValid) + + if(isConditionValid) { + nbValid++; + } + + // when user want the field to become valid as soon as we have 1 validator passing + if(self.validRequireHowMany == nbValid && !!isConditionValid) { + isFieldValid = true; + break; + } + } // for() loop + + // only log the invalid message in the $validationSummary + if (isConditionValid) { + addToValidationSummary(self, ''); + self.updateErrorMsg('', { isValid: isConditionValid }); + } + + if (!!formElmObj) { + formElmObj.isValid = isFieldValid; + if (isFieldValid) { + formElmObj.message = ''; + } + } + return isFieldValid; + } // validate() + + //---- + // Private functions declaration + //---------------------------------- + + /** Add to the Form Elements Array of Object List + * @param object elm + * @param object attrs + * @param object ctrl + * @param object scope + */ + function addToFormElementObjectList(elm, attrs, ctrl, scope) { + var elmName = (!!attrs.name) ? attrs.name : elm.attr('name'); + var form = getElementParentForm(elmName, { scope: scope }); // find the parent form (only found if it has a name) + var friendlyName = (!!attrs && !!attrs.friendlyName) ? $translate.instant(attrs.friendlyName) : ''; + var formElm = { fieldName: elmName, friendlyName: friendlyName, elm: elm, attrs: attrs, ctrl: ctrl, scope: scope, isValid: false, message: '', formName: (!!form) ? form.$name : null }; + var index = arrayFindObjectIndex(_formElements, 'fieldName', elm.attr('name')); // find index of object in our array + if (index >= 0) { + _formElements[index] = formElm; + } else { + _formElements.push(formElm); + } + return _formElements; + } + + /** Will add error to the validationSummary and also display the error message if requested + * @param object self + * @param object formElmObj + * @param string message: error message + * @param bool is field valid? + * @param bool showError + */ + function addToValidationAndDisplayError(self, formElmObj, message, isFieldValid, showError) { + // trim any white space + message = message.trim(); + + // if validation is cancelled, then erase error message + if(!!formElmObj && formElmObj.isValidationCancelled === true) { + message = ''; + } + + // log the invalid message in the $validationSummary + // that is if the preValidationSummary is set to True, non-existent or we simply want to display error) + if(!!_globalOptions.preValidateValidationSummary || typeof _globalOptions.preValidateValidationSummary === "undefined" || showError) { + addToValidationSummary(formElmObj, message); + } + + // change the Form element object boolean flag from the `formElements` variable, used in the `checkFormValidity()` + if (!!formElmObj) { + //formElmObj.message = message; + } + + // if user is pre-validating all form elements, display error right away + if (!!self.validatorAttrs.preValidateFormElements || !!_globalOptions.preValidateFormElements) { + // make the element as it was touched for CSS, only works in AngularJS 1.3+ + if (!!formElmObj && typeof self.ctrl.$setTouched === "function") { + formElmObj.ctrl.$setTouched(); + } + // only display errors on page load, when elements are not yet dirty + if (self.ctrl.$dirty === false) { + updateErrorMsg(message, { isSubmitted: true, isValid: isFieldValid, obj: formElmObj }); + } + } + + // error Display + if (showError && !!formElmObj && !formElmObj.isValid) { + self.updateErrorMsg(message, { isValid: isFieldValid, obj: formElmObj }); + } else if (!!formElmObj && formElmObj.isValid) { + addToValidationSummary(formElmObj, ''); + } + } + + /** Analyse the certain attributes that the element can have or could be passed by global options + * @param object self + * @return self + */ + function analyzeElementAttributes(self) { + // debounce (alias of typingLimit) timeout after user stop typing and validation comes in play + self.typingLimit = _INACTIVITY_LIMIT; + if (self.validatorAttrs.hasOwnProperty('debounce')) { + self.typingLimit = parseInt(self.validatorAttrs.debounce, 10); + } else if (self.validatorAttrs.hasOwnProperty('typingLimit')) { + self.typingLimit = parseInt(self.validatorAttrs.typingLimit, 10); + } else if (!!_globalOptions && _globalOptions.hasOwnProperty('debounce')) { + self.typingLimit = parseInt(_globalOptions.debounce, 10); + } + + // how many Validators it needs to pass for the field to become valid, "all" by default + self.validRequireHowMany = self.validatorAttrs.hasOwnProperty('validRequireHowMany') + ? self.validatorAttrs.validRequireHowMany + : _globalOptions.validRequireHowMany; + + // do we want to validate on empty field? Useful on `custom` and `remote` + _validateOnEmpty = self.validatorAttrs.hasOwnProperty('validateOnEmpty') + ? parseBool(self.validatorAttrs.validateOnEmpty) + : _globalOptions.validateOnEmpty; + + return self; + } + + /** Quick function to find an object inside an array by it's given field name and value, return the object found or null + * @param Array sourceArray + * @param string searchId: search property id + * @param string searchValue: value to search + * @return object found from source array or null + */ + function arrayFindObject(sourceArray, searchId, searchValue) { + if (!!sourceArray) { + for (var i = 0; i < sourceArray.length; i++) { + if (sourceArray[i][searchId] === searchValue) { + return sourceArray[i]; + } + } + } + return null; + } + + /** Quick function to find all object(s) inside an array of objects by it's given field name and value, return array of object found(s) or empty array + * @param Array sourceArray + * @param string searchId: search property id + * @param string searchValue: value to search + * @return array of object found from source array + */ + function arrayFindObjects(sourceArray, searchId, searchValue) { + var results = []; + if (!!sourceArray) { + for (var i = 0; i < sourceArray.length; i++) { + if (sourceArray[i][searchId] === searchValue) { + results.push(sourceArray[i]); + } + } + } + return results; + } + + /** Quick function to find an object inside an array by it's given field name and value, return the index position found or -1 + * @param Array sourceArray + * @param string searchId: search property id + * @param string searchValue: value to search + * @return int index position found + */ + function arrayFindObjectIndex(sourceArray, searchId, searchValue) { + if (!!sourceArray) { + for (var i = 0; i < sourceArray.length; i++) { + if (sourceArray[i][searchId] === searchValue) { + return i; + } + } + } + + return -1; + } + + /** From a javascript plain form object, find its equivalent Angular object + * @param object formObj + * @param object self + * @return object angularParentForm or null + */ + function findAngularParentFormInScope(formObj, self) { + var formName = (!!formObj) ? formObj.getAttribute("name") : null; + + if (!!formObj && !!formName) { + parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0) + ? objectFindById(self.scope, formName, '.') + : self.scope[formName]; + + if(!!parentForm) { + if (typeof parentForm.$name === "undefined") { + parentForm.$name = formName; // make sure it has a $name, since we use that variable later on + } + return parentForm; + } + } + + return null; + } + + /** Get the element's parent Angular form (if found) + * @param string: element input name + * @param object self + * @return object scope form + */ + function getElementParentForm(elmName, self) { + // get the parentForm directly by it's formName if it was passed in the global options + if(!!_globalOptions && !!_globalOptions.formName) { + var parentForm = document.querySelector('[name="'+_globalOptions.formName+'"]'); + if(!!parentForm) { + parentForm.$name = _globalOptions.formName; // make sure the parentForm as a $name for later usage + return parentForm; + } + } + + // from the element passed, get his parent form (this doesn't work with every type of element, for example it doesn't work with
or special angular element) + var forms = document.getElementsByName(elmName); + var parentForm = null; + + for (var i = 0; i < forms.length; i++) { + var form = forms[i].form; + var angularParentForm = findAngularParentFormInScope(form, self); + if(!!angularParentForm) { + return angularParentForm; + } + } + + // if we haven't found a form yet, then we have a special angular element, let's try with .closest + if(!form) { + var element = document.querySelector('[name="'+elmName+'"]'); + if(!!element) { + var form = element.closest("form"); + var angularParentForm = findAngularParentFormInScope(form, self); + if(!!angularParentForm) { + return angularParentForm; + } + } + } + + // falling here with a form name but without a form object found in the scope is often due to isolate scope + // we can hack it and define our own form inside this isolate scope, in that way we can still use something like: isolateScope.form1.$validationSummary + if (!!form) { + var formName = (!!form) ? form.getAttribute("name") : null; + if(!!formName) { + var obj = { $name: formName, specialNote: 'Created by Angular-Validation for Isolated Scope usage' }; + + if (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0) { + var formSplit = formName.split('.'); + return self.scope[formSplit[0]][formSplit[1]] = obj + } + return self.scope[formName] = obj; + } + } + return null; + } + + /** Check if the given argument is numeric + * @param mixed n + * @return bool + */ + function isNumeric(n) { + return !isNaN(parseFloat(n)) && isFinite(n); + } + + /** Find a property inside an object. + * If a delimiter is passed as argument, we will split the search ID before searching + * @param object: source object + * @param string: searchId + * @return mixed: property found + */ + function objectFindById(sourceObject, searchId, delimiter) { + var split = (!!delimiter) ? searchId.split(delimiter) : searchId; + + for (var k = 0, kln = split.length; k < kln; k++) { + if(!!sourceObject[split[k]]) { + sourceObject = sourceObject[split[k]]; + } + } + return sourceObject; + } + + /** Parse a boolean value, we also want to parse on string values + * @param string/int value + * @return bool + */ + function parseBool(value) { + if(typeof value === "boolean" || typeof value === "number") { + return (value === true || value === 1); + } + else if (typeof value === "string") { + value = value.replace(/^\s+|\s+$/g, "").toLowerCase(); + if (value === "true" || value === "1" || value === "false" || value === "0") + return (value === "true" || value === "1"); + } + return; // returns undefined + } + + /** Parse a date from a String and return it as a Date Object to be valid for all browsers following ECMA Specs + * Date type ISO (default), US, UK, Europe, etc... Other format could be added in the switch case + * @param String dateStr: date String + * @param String dateType: date type (ISO, US, etc...) + * @return object date + */ + function parseDate(dateStr, dateType) { + // variables declaration + var dateSubStr = '', dateSeparator = '-', dateSplit = [], timeSplit = [], year = '', month = '', day = ''; + + // Parse using the date type user selected, (separator could be dot, slash or dash) + switch (dateType.toUpperCase()) { + case 'EURO_LONG': + case 'EURO-LONG': // UK, Europe long format is: dd/mm/yyyy hh:mm:ss + dateSubStr = dateStr.substring(0, 10); + dateSeparator = dateStr.substring(2, 3); + dateSplit = splitDateString(dateSubStr, dateSeparator); + day = dateSplit[0]; + month = dateSplit[1]; + year = dateSplit[2]; + timeSplit = (dateStr.length > 8) ? dateStr.substring(9).split(':') : null; + break; + case 'UK': + case 'EURO': + case 'EURO_SHORT': + case 'EURO-SHORT': + case 'EUROPE': // UK, Europe format is: dd/mm/yy hh:mm:ss + dateSubStr = dateStr.substring(0, 8); + dateSeparator = dateStr.substring(2, 3); + dateSplit = splitDateString(dateSubStr, dateSeparator); + day = dateSplit[0]; + month = dateSplit[1]; + year = (parseInt(dateSplit[2]) < 50) ? ('20' + dateSplit[2]) : ('19' + dateSplit[2]); // below 50 we'll consider that as century 2000's, else in century 1900's + timeSplit = (dateStr.length > 8) ? dateStr.substring(9).split(':') : null; + break; + case 'US_LONG': + case 'US-LONG': // US long format is: mm/dd/yyyy hh:mm:ss + dateSubStr = dateStr.substring(0, 10); + dateSeparator = dateStr.substring(2, 3); + dateSplit = splitDateString(dateSubStr, dateSeparator); + month = dateSplit[0]; + day = dateSplit[1]; + year = dateSplit[2]; + timeSplit = (dateStr.length > 8) ? dateStr.substring(9).split(':') : null; + break; + case 'US': + case 'US_SHORT': + case 'US-SHORT': // US short format is: mm/dd/yy hh:mm:ss OR + dateSubStr = dateStr.substring(0, 8); + dateSeparator = dateStr.substring(2, 3); + dateSplit = splitDateString(dateSubStr, dateSeparator); + month = dateSplit[0]; + day = dateSplit[1]; + year = (parseInt(dateSplit[2]) < 50) ? ('20' + dateSplit[2]) : ('19' + dateSplit[2]); // below 50 we'll consider that as century 2000's, else in century 1900's + timeSplit = (dateStr.length > 8) ? dateStr.substring(9).split(':') : null; + break; + case 'ISO': + default: // ISO format is: yyyy-mm-dd hh:mm:ss (separator could be dot, slash or dash: ".", "/", "-") + dateSubStr = dateStr.substring(0, 10); + dateSeparator = dateStr.substring(4, 5); + dateSplit = splitDateString(dateSubStr, dateSeparator); + year = dateSplit[0]; + month = dateSplit[1]; + day = dateSplit[2]; + timeSplit = (dateStr.length > 10) ? dateStr.substring(11).split(':') : null; + break; + } + + // parse the time if it exist else put them at 0 + var hour = (!!timeSplit && timeSplit.length === 3) ? timeSplit[0] : 0; + var min = (!!timeSplit && timeSplit.length === 3) ? timeSplit[1] : 0; + var sec = (!!timeSplit && timeSplit.length === 3) ? timeSplit[2] : 0; + + // Construct a valid Date Object that follows the ECMA Specs + // Note that, in JavaScript, months run from 0 to 11, rather than 1 to 12! + return new Date(year, month - 1, day, hour, min, sec); + } + + /** Reset all the available Global Options of Angular-Validation + * @param bool do a Reset? + */ + function resetGlobalOptions(doReset) { + if (doReset) { + _globalOptions = { + displayOnlyLastErrorMsg: false, // reset the option of displaying only the last error message + errorMessageSeparator: ' ', // separator between each error messages (when multiple errors exist) + hideErrorUnderInputs: false, // reset the option of hiding error under element + preValidateFormElements: false, // reset the option of pre-validate all form elements, false by default + preValidateValidationSummary: true, // reset the option of pre-validate all form elements, false by default + isolatedScope: null, // reset used scope on route change + scope: null, // reset used scope on route change + validateOnEmpty: false, // reset the flag of Validate Always + validRequireHowMany: 'all', // how many Validators it needs to pass for the field to become valid, "all" by default + resetGlobalOptionsOnRouteChange: true + }; + _formElements = []; // array containing all form elements, valid or invalid + _validationSummary = []; // array containing the list of invalid fields inside a validationSummary + } + } + + /** From a date substring split it by a given separator and return a split array + * @param string dateSubStr + * @param string dateSeparator + * @return array date splitted + */ + function splitDateString(dateSubStr, dateSeparator) { + var dateSplit = []; + + switch (dateSeparator) { + case '/': + dateSplit = dateSubStr.split('/'); break; + case '.': + dateSplit = dateSubStr.split('.'); break; + case '-': + default: + dateSplit = dateSubStr.split('-'); break; + } + + return dateSplit; + } + + /** Test values with condition, I have created a switch case for all possible conditions. + * @param string condition: condition to filter with + * @param any value1: 1st value to compare, the type could be anything (number, String or even Date) + * @param any value2: 2nd value to compare, the type could be anything (number, String or even Date) + * @return boolean: a boolean result of the tested condition (true/false) + */ + function testCondition(condition, value1, value2) { + var result = false; + + switch (condition) { + case '<': result = (value1 < value2); break; + case '<=': result = (value1 <= value2); break; + case '>': result = (value1 > value2); break; + case '>=': result = (value1 >= value2); break; + case '!=': + case '<>': result = (value1 != value2); break; + case '!==': result = (value1 !== value2); break; + case '=': + case '==': result = (value1 == value2); break; + case '===': result = (value1 === value2); break; + default: result = false; break; + } + return result; + } + + /** Element Closest Polyfill for the browsers that don't support it (fingers point to IE) + * https://developer.mozilla.org/en-US/docs/Web/API/Element/closest + */ + function elementPrototypeClosest() { + Element.prototype.closest = + function(s) { + var matches = (this.document || this.ownerDocument).querySelectorAll(s), + i, + el = this; + + do { + i = matches.length; + while (--i >= 0 && matches.item(i) !== el) {}; + } while ((i < 0) && (el = el.parentElement)); + return el; + }; + } + + /** Override javascript trim() function so that it works accross all browser platforms */ + function stringPrototypeTrim() { + return this.replace(/^\s+|\s+$/g, ''); + } + + /** Override javascript format() function to be the same as the effect as the C# String.Format + * Input: "Some {0} are showing {1}".format("inputs", "invalid"); + * Output: "Some inputs are showing invalid" + * @param string + * @param replacements + */ + function stringPrototypeFormat() { + var args = (Array.isArray(arguments[0])) ? arguments[0] : arguments; + return this.replace(/{(\d+)}/g, function (match, number) { + return (typeof args[number] !== "undefined") ? args[number] : match; + }); + } + + /** Override javascript String.format() function to be the same as the effect as the C# String.Format + * Input: String.format("Some {0} are showing {1}", "inputs", "invalid"); + * Output: "Some inputs are showing invalid" + * @param string + * @param replacements + */ + function stringFormat(format) { + var args = (Array.isArray(arguments[1])) ? arguments[1] : Array.prototype.slice.call(arguments, 1); + + return format.replace(/{(\d+)}/g, function (match, number) { + return (typeof args[number] !== "undefined") ? args[number] : match; + }); + } + + /** Validating a Conditional Date, user want to valid if his date is smaller/higher compare to another. + * @param string value + * @param object validator + * @param object rules + * @return bool isValid + */ + function validateConditionalDate(strValue, validator, rules) { + var isValid = true; + var isWellFormed = isValid = false; + + // 1- make sure Date is well formed (if it's already a Date object then it's already good, else check that with Regex) + if((strValue instanceof Date)) { + isWellFormed = true; + }else { + // run the Regex test through each iteration, if required (\S+) and is null then it's invalid automatically + var regex = new RegExp(validator.pattern, validator.patternFlag); + isWellFormed = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null) ? false : regex.test(strValue); + } + + // 2- date is well formed, then go ahead with conditional date check + if (isWellFormed) { + // For Date comparison, we will need to construct a Date Object that follows the ECMA so then it could work in all browser + // Then convert to timestamp & finally we can compare both dates for filtering + var dateType = validator.dateType; // date type (ISO, EURO, US-SHORT, US-LONG) + var timestampValue = (strValue instanceof Date) ? strValue : parseDate(strValue, dateType).getTime(); // our input value parsed into a timestamp + + // if 2 params, then it's a between condition + if (validator.params.length == 2) { + // this is typically a "between" condition, a range of number >= and <= + var timestampParam0 = parseDate(validator.params[0], dateType).getTime(); + var timestampParam1 = parseDate(validator.params[1], dateType).getTime(); + var isValid1 = testCondition(validator.condition[0], timestampValue, timestampParam0); + var isValid2 = testCondition(validator.condition[1], timestampValue, timestampParam1); + isValid = (isValid1 && isValid2); + } else { + // else, 1 param is a simple conditional date check + var timestampParam = parseDate(validator.params[0], dateType).getTime(); + isValid = testCondition(validator.condition, timestampValue, timestampParam); + } + } + + return isValid; + } + + /** Validating a Conditional Number, user want to valid if his number is smaller/higher compare to another. + * @param string value + * @param object validator + * @return bool isValid + */ + function validateConditionalNumber(strValue, validator) { + var isValid = true; + + // if 2 params, then it's a between condition + if (validator.params.length == 2) { + // this is typically a "between" condition, a range of number >= and <= + var isValid1 = testCondition(validator.condition[0], parseFloat(strValue), parseFloat(validator.params[0])); + var isValid2 = testCondition(validator.condition[1], parseFloat(strValue), parseFloat(validator.params[1])); + isValid = (isValid1 && isValid2); + } else { + // else, 1 param is a simple conditional number check + isValid = testCondition(validator.condition, parseFloat(strValue), parseFloat(validator.params[0])); + } + + return isValid; + } + + /** Make a Custom Javascript Validation, this should return a boolean or an object as { isValid: bool, message: msg } + * The argument of `validationElmObj` is mainly there only because it's passed by reference (pointer reference) and + * by the time the $translate promise is done with the translation then the promise in our function will have the latest error message. + * @param string value + * @param object validator + * @param object self + * @param object formElmObj + * @param bool showError + * @param object element validation object (passed by reference) + * @return bool isValid + */ + function validateCustomJavascript(strValue, validator, self, formElmObj, showError, validationElmObj) { + var isValid = true; + var missingErrorMsg = "Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }" + var invalidResultErrorMsg = 'Custom Javascript Validation requires a declared function (in your Controller), please review your code.'; + + if (!!strValue || !!_validateOnEmpty) { + var fct = null; + var fname = validator.params[0]; + var result = runEvalScopeFunction(self, fname); + + // analyze the result, could be a boolean or object type, anything else will throw an error + if (typeof result === "boolean") { + isValid = (!!result); + } + else if (typeof result === "object") { + isValid = (!!result.isValid); + } + else { + throw invalidResultErrorMsg; + } + + if (isValid === false) { + formElmObj.isValid = false; + + // is field is invalid and we have an error message given, then add it to validationSummary and display error + // use of $timeout to make sure we are always at the end of the $digest + // if user passed the error message from inside the custom js function, $translate would come and overwrite this error message and so being sure that we are at the end of the $digest removes this issue. + $timeout(function() { + var errorMsg = validationElmObj.message + ' '; + if(!!result.message) { + errorMsg += result.message || validator.altText; + } + if(errorMsg === ' ' && !!validator.altText) { + errorMsg += validator.altText; + } + if(errorMsg === ' ') { + throw missingErrorMsg; + } + + addToValidationAndDisplayError(self, formElmObj, errorMsg, false, showError); + }); + } + else if (isValid === true) { + // if field is valid from the remote check (isValid) and from the other validators check (isFieldValid) + // clear up the error message and make the field directly as Valid with $setValidity since remote check arrive after all other validators check + formElmObj.isValid = true; + addToValidationAndDisplayError(self, formElmObj, '', true, showError); + } + + if(typeof result === "undefined") { + throw invalidResultErrorMsg; + } + } + + return isValid; + } + + /** Validating a match input checking, it could a check to be the same as another input or even being different. + * The argument of `validationElmObj` is mainly there only because it's passed by reference (pointer reference) and + * by the time the $translate promise is done with the translation then the promise in our function will have the latest error message. + * @param string value + * @param object validator + * @param object self + * @param object element validation object (passed by reference) + * @return bool isValid + */ + function validateMatching(strValue, validator, self, validationElmObj) { + var isValid = true; + + // get the element 'value' ngModel to compare to (passed as params[0], via an $eval('ng-model="modelToCompareName"') + // for code purpose we'll name the other parent element "parent..." + // and we will name the current element "matching..." + var parentNgModel = validator.params[0]; + var parentNgModelVal = self.scope.$eval(parentNgModel); + var otherElm = angular.element(document.querySelector('[name="'+parentNgModel+'"]')); + var matchingValidator = validator; // keep reference of matching confirmation validator + var matchingCtrl = self.ctrl; // keep reference of matching confirmation controller + var formElmMatchingObj = getFormElementByName(self.ctrl.$name); + + isValid = (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue); + + // if element to compare against has a friendlyName or if matching 2nd argument was passed, we will use that as a new friendlyName + // ex.: :: we would use the friendlyName of 'Password1' not input1 + // or :: we would use Password2 not input1 + if(!!otherElm && !!otherElm.attr('friendly-name')) { + validator.params[1] = otherElm.attr('friendly-name'); + } + else if(validator.params.length > 1) { + validator.params[1] = validator.params[1]; + } + + // Watch for the parent ngModel, if it change we need to re-validate the child (confirmation) + self.scope.$watch(parentNgModel, function(newVal, oldVal) { + var isWatchValid = testCondition(matchingValidator.condition, matchingCtrl.$viewValue, newVal); + + // only inspect on a parent input value change + if(newVal !== oldVal) { + // If Valid then erase error message ELSE make matching field Invalid + if(isWatchValid) { + addToValidationAndDisplayError(self, formElmMatchingObj, '', true, true); + }else { + formElmMatchingObj.isValid = false; + var msgToTranslate = matchingValidator.message; + if (!!matchingValidator.altText && matchingValidator.altText.length > 0) { + msgToTranslate = matchingValidator.altText.replace("alt=", ""); + } + $translate(msgToTranslate).then(function (translation) { + var errorMessageSeparator = _globalOptions.errorMessageSeparator || ' '; + validationElmObj.message = errorMessageSeparator + ((!!matchingValidator && !!matchingValidator.params) ? String.format(translation, matchingValidator.params) : translation); + addToValidationAndDisplayError(self, formElmMatchingObj, validationElmObj.message, isWatchValid, true); + }); + } + matchingCtrl.$setValidity('validation', isWatchValid); // change the validity of the matching input + } + }, true); // .$watch() + + return isValid; + } + + /** Make an AJAX Remote Validation with a backend server, this should return a promise with the result as a boolean or a { isValid: bool, message: msg } + * The argument of `validationElmObj` is mainly there only because it's passed by reference (pointer reference) and + * by the time the $translate promise is done with the translation then the promise in our function will have the latest error message. + * @param string value + * @param object validator + * @param object self + * @param object formElmObj + * @param bool showError + * @param object element validation object (passed by reference) + * @return bool isValid + */ + function validateRemote(strValue, validator, self, formElmObj, showError, validationElmObj) { + var isValid = true; + var missingErrorMsg = "Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }" + var invalidResultErrorMsg = 'Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.'; + + if ((!!strValue && !!showError) || !!_validateOnEmpty) { + self.ctrl.$processing = true; // $processing can be use in the DOM to display a remote processing message to the user + + var fct = null; + var fname = validator.params[0]; + var promise = runEvalScopeFunction(self, fname); + + // if we already have previous promises running, we might want to abort them (if user specified an abort function) + if (_remotePromises.length > 1) { + while (_remotePromises.length > 0) { + var previousPromise = _remotePromises.pop(); + if (!!previousPromise && typeof previousPromise.abort === "function") { + previousPromise.abort(); // run the abort if user declared it + } + } + } + _remotePromises.push(promise); // always add to beginning of array list of promises + + if (!!promise && typeof promise.then === "function") { + self.ctrl.$setValidity('remote', false); // make the field invalid before processing it + + // process the promise + (function (altText) { + promise.then(function (result) { + result = result.data || result; + _remotePromises.pop(); // remove the last promise from array list of promises + self.ctrl.$processing = false; // finished resolving, no more pending + + var errorMsg = validationElmObj.message + ' '; + + // analyze the result, could be a boolean or object type, anything else will throw an error + if (typeof result === "boolean") { + isValid = (!!result); + } + else if (typeof result === "object") { + isValid = (!!result.isValid); + } + else { + throw invalidResultErrorMsg; + } + + if (isValid === false) { + formElmObj.isValid = false; + errorMsg += result.message || altText; + if(errorMsg === ' ') { + throw missingErrorMsg; + } + + // is field is invalid and we have an error message given, then add it to validationSummary and display error + addToValidationAndDisplayError(self, formElmObj, errorMsg, false, showError); + } + else if (isValid === true) { + // if field is valid from the remote check (isValid) and from the other validators check (isFieldValid) + // clear up the error message and make the field directly as Valid with $setValidity since remote check arrive after all other validators check + formElmObj.isValid = true; + self.ctrl.$setValidity('remote', true); + addToValidationAndDisplayError(self, formElmObj, '', true, showError); + } + }); + })(validator.altText); + } else { + throw invalidResultErrorMsg; + } + } + + return isValid; + } + + /** Validating through a regular regex pattern checking + * @param string value + * @param object validator + * @param object rules + * @param object self + * @return bool isValid + */ + function validateWithRegex(strValue, validator, rules, self) { + var isValid = true; + + // get the ngDisabled attribute if found + var elmAttrNgDisabled = (!!self.attrs) ? self.attrs.ngDisabled : self.validatorAttrs.ngDisabled; + var elmAttrDisabled = self.elm.prop("disabled"); + + var isDisabled = (elmAttrDisabled === "") + ? true + : (typeof elmAttrDisabled === "boolean") + ? elmAttrDisabled + : (typeof elmAttrDisabled !== "undefined") ? self.scope.$eval(elmAttrDisabled) : false; + + var isNgDisabled = (elmAttrNgDisabled === "") + ? true + : (typeof elmAttrNgDisabled === "boolean") + ? elmAttrNgDisabled + : (typeof elmAttrNgDisabled !== "undefined") ? self.scope.$eval(elmAttrNgDisabled) : false; + + // a 'disabled' element should always be valid, there is no need to validate it + if (isDisabled || isNgDisabled) { + isValid = true; + } else { + // before running Regex test, we'll make sure that an input of type="number" doesn't hold invalid keyboard chars, if true skip Regex + if (typeof strValue === "string" && strValue === "" && !!self.elm.prop('type') && self.elm.prop('type').toUpperCase() === "NUMBER") { + isValid = false; + } else { + // run the Regex test through each iteration, if required (\S+) and is null then it's invalid automatically + var regex = new RegExp(validator.pattern, validator.patternFlag); + isValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null) ? false : regex.test(strValue); + } + } + + return isValid; + } + + /** AutoDetect type is a special case and will detect if the given value is of type numeric or not. + * then it will rewrite the conditions or regex pattern, depending on type found + * @param object validator + * @return object rewritten validator + */ + function validatorAutoDetectType(validator, strValue) { + if (isNumeric(strValue)) { + return { + condition: validator.conditionNum, + message: validator.messageNum, + params: validator.params, + type: "conditionalNumber" + }; + }else { + return { + pattern: validator.patternLength, + message: validator.messageLength, + params: validator.params, + type: "regex" + }; + } + + return {}; + } + + }]); // validationCommon service + +/** + * angular-validation-rules (ghiscoding) + * https://github.com/ghiscoding/angular-validation + * + * @author: Ghislain B. + * @desc: angular-validation rules definition + * Each rule objects must have 3 properties {pattern, message, type} + * and in some cases you could also define a 4th properties {params} to pass extras, for example: max_len will know his maximum length by this extra {params} + * Rule.type can be {autoDetect, conditionalDate, conditionalNumber, matching, regex} + * + * WARNING: Rule patterns are defined as String type so don't forget to escape your characters: \\ + */ +angular + .module('ghiscoding.validation') + .factory('ValidationRules', [function () { + // return the service object + var service = { + getElementValidators: getElementValidators + }; + return service; + + //---- + // Functions declaration + //---------------------------------- + + /** Get the element active validators and store it inside an array which will be returned + * @param object args: all attributes + */ + function getElementValidators(args) { + // grab all passed attributes + var alternateText = (typeof args.altText !== "undefined") ? args.altText.replace("alt=", "") : null; + var customUserRegEx = (args.hasOwnProperty('customRegEx')) ? args.customRegEx : null; + var rule = (args.hasOwnProperty('rule')) ? args.rule : null; + var ruleParams = (args.hasOwnProperty('ruleParams')) ? args.ruleParams : null; + + // validators on the current DOM element, an element can have 1+ validators + var validator = {}; + + switch(rule) { + case "accepted": + validator = { + pattern: /^(yes|on|1|true)$/i, + message: "INVALID_ACCEPTED", + type: "regex" + }; + break; + case "alpha" : + validator = { + pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i, + message: "INVALID_ALPHA", + type: "regex" + }; + break; + case "alphaSpaces" : + case "alpha_spaces" : + validator = { + pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i, + message: "INVALID_ALPHA_SPACE", + type: "regex" + }; + break; + case "alphaNum" : + case "alpha_num" : + validator = { + pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i, + message: "INVALID_ALPHA_NUM", + type: "regex" + }; + break; + case "alphaNumSpaces" : + case "alpha_num_spaces" : + validator = { + pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i, + message: "INVALID_ALPHA_NUM_SPACE", + type: "regex" + }; + break; + case "alphaDash" : + case "alpha_dash" : + validator = { + pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i, + message: "INVALID_ALPHA_DASH", + type: "regex" + }; + break; + case "alphaDashSpaces" : + case "alpha_dash_spaces" : + validator = { + pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i, + message: "INVALID_ALPHA_DASH_SPACE", + type: "regex" + }; + break; + case "between" : + case "range" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5"; + } + validator = { + patternLength: "^(.|[\\r\\n]){" + ranges[0] + "," + ranges[1] + "}$", + messageLength: "INVALID_BETWEEN_CHAR", + conditionNum: [">=","<="], + messageNum: "INVALID_BETWEEN_NUM", + params: [ranges[0], ranges[1]], + type: "autoDetect" + }; + break; + case "betweenLen" : + case "between_len" : + case "stringLen" : + case "string_len" : + case "stringLength" : + case "string_length" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5"; + } + validator = { + pattern: "^(.|[\\r\\n]){" + ranges[0] + "," + ranges[1] + "}$", + message: "INVALID_BETWEEN_CHAR", + params: [ranges[0], ranges[1]], + type: "regex" + }; + break; + case "betweenNum" : + case "between_num" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5"; + } + validator = { + condition: [">=","<="], + message: "INVALID_BETWEEN_NUM", + params: [ranges[0], ranges[1]], + type: "conditionalNumber" + }; + break; + case "boolean": + validator = { + pattern: /^(true|false|0|1)$/i, + message: "INVALID_BOOLEAN", + type: "regex" + }; + break; + case "checked": + validator = { + pattern: /^true$/i, + message: "INVALID_CHECKBOX_SELECTED", + type: "regex" + }; + break; + case "creditCard" : + case "credit_card" : + validator = { + pattern: /^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/, + message: "INVALID_CREDIT_CARD", + type: "regex" + }; + break; + case "custom" : + case "javascript" : + validator = { + message: '', // there is no error message defined on this one since user will provide his own error message via remote response or `alt=` + params: [ruleParams], + type: "javascript" + }; + break; + case "dateEuro" : + case "date_euro" : + validator = { + // accept long & short year (1996 or 96) + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_EURO", + type: "regex" + }; + break; + case "dateEuroBetween" : + case "date_euro_between" : + case "betweenDateEuro" : + case "between_date_euro" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015"; + } + validator = { + condition: [">=","<="], + dateType: "EURO_LONG", + params: [ranges[0], ranges[1]], + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_EURO_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateEuroMax" : + case "date_euro_max" : + case "maxDateEuro" : + case "max_date_euro" : + validator = { + condition: "<=", + dateType: "EURO_LONG", + params: [ruleParams], + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_EURO_MAX", + type: "conditionalDate" + }; + break; + case "dateEuroMin" : + case "date_euro_min" : + case "minDateEuro" : + case "min_date_euro" : + validator = { + condition: ">=", + dateType: "EURO_LONG", + params: [ruleParams], + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_EURO_MIN", + type: "conditionalDate" + }; + break; + case "dateEuroLong" : + case "date_euro_long" : + validator = { + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_EURO_LONG", + type: "regex" + }; + break; + case "dateEuroLongBetween" : + case "date_euro_long_between" : + case "betweenDateEuroLong" : + case "between_date_euro_long" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015"; + } + validator = { + condition: [">=","<="], + dateType: "EURO_LONG", + params: [ranges[0], ranges[1]], + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_EURO_LONG_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateEuroLongMax" : + case "date_euro_long_max" : + case "maxDateEuroLong" : + case "max_date_euro_long" : + validator = { + condition: "<=", + dateType: "EURO_LONG", + params: [ruleParams], + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_EURO_LONG_MAX", + type: "conditionalDate" + }; + break; + case "dateEuroLongMin" : + case "date_euro_long_min" : + case "minDateEuroLong" : + case "min_date_euro_long" : + validator = { + condition: ">=", + dateType: "EURO_LONG", + params: [ruleParams], + pattern: /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_EURO_LONG_MIN", + type: "conditionalDate" + }; + break; + case "dateEuroShort" : + case "date_euro_short" : + validator = { + pattern: /^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/, + message: "INVALID_DATE_EURO_SHORT", + type: "regex" + }; + break; + case "dateEuroShortBetween" : + case "date_euro_short_between" : + case "betweenDateEuroShort" : + case "between_date_euro_short" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15"; + } + validator = { + condition: [">=","<="], + dateType: "EURO_SHORT", + params: [ranges[0], ranges[1]], + pattern: /^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/, + message: "INVALID_DATE_EURO_SHORT_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateEuroShortMax" : + case "date_euro_short_max" : + case "maxDateEuroShort" : + case "max_date_euro_short" : + validator = { + condition: "<=", + dateType: "EURO_SHORT", + params: [ruleParams], + pattern: /^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/, + message: "INVALID_DATE_EURO_SHORT_MAX", + type: "conditionalDate" + }; + break; + case "dateEuroShortMin" : + case "date_euro_short_min" : + case "minDateEuroShort" : + case "min_date_euro_short" : + validator = { + condition: ">=", + dateType: "EURO_SHORT", + params: [ruleParams], + pattern: /^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/, + message: "INVALID_DATE_EURO_SHORT_MIN", + type: "conditionalDate" + }; + break; + case "dateIso" : + case "date_iso" : + validator = { + pattern: /^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/, + message: "INVALID_DATE_ISO", + type: "regex" + }; + break; + case "dateIsoBetween" : + case "date_iso_between" : + case "betweenDateIso" : + case "between_date_iso" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31"; + } + validator = { + condition: [">=","<="], + dateType: "ISO", + params: [ranges[0], ranges[1]], + pattern: /^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/, + message: "INVALID_DATE_ISO_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateIsoMax" : + case "date_iso_max" : + case "maxDateIso" : + case "max_date_iso" : + validator = { + condition: "<=", + dateType: "ISO", + params: [ruleParams], + pattern: /^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/, + message: "INVALID_DATE_ISO_MAX", + type: "conditionalDate" + }; + break; + case "dateIsoMin" : + case "date_iso_min" : + case "minDateIso" : + case "min_date_iso" : + validator = { + condition: ">=", + dateType: "ISO", + params: [ruleParams], + pattern: /^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/, + message: "INVALID_DATE_ISO_MIN", + type: "conditionalDate" + }; + break; + case "dateUs" : + case "date_us" : + validator = { + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_US", + type: "regex" + }; + break; + case "dateUsBetween" : + case "date_us_between" : + case "betweenDateUs" : + case "between_date_us" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015"; + } + validator = { + condition: [">=","<="], + dateType: "US_LONG", + params: [ranges[0], ranges[1]], + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_US_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateUsMax" : + case "date_us_max" : + case "maxDateUs" : + case "max_date_us" : + validator = { + condition: "<=", + dateType: "US_LONG", + params: [ruleParams], + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_US_MAX", + type: "conditionalDate" + }; + break; + case "dateUsMin" : + case "date_us_min" : + case "minDateUs" : + case "min_date_us" : + validator = { + condition: ">=", + dateType: "US_LONG", + params: [ruleParams], + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/, + message: "INVALID_DATE_US_MIN", + type: "conditionalDate" + }; + break; + case "dateUsLong" : + case "date_us_long" : + validator = { + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_US_LONG", + type: "regex" + }; + break; + case "dateUsLongBetween" : + case "date_us_long_between" : + case "betweenDateUsLong" : + case "between_date_us_long" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015"; + } + validator = { + condition: [">=","<="], + dateType: "US_LONG", + params: [ranges[0], ranges[1]], + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_US_LONG_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateUsLongMax" : + case "date_us_long_max" : + case "maxDateUsLong" : + case "max_date_us_long" : + validator = { + condition: "<=", + dateType: "US_LONG", + params: [ruleParams], + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_US_LONG_MAX", + type: "conditionalDate" + }; + break; + case "dateUsLongMin" : + case "date_us_long_min" : + case "minDateUsLong" : + case "min_date_us_long" : + validator = { + condition: ">=", + dateType: "US_LONG", + params: [ruleParams], + pattern: /^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/, + message: "INVALID_DATE_US_LONG_MIN", + type: "conditionalDate" + }; + break; + case "dateUsShort" : + case "date_us_short" : + validator = { + pattern: /^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/, + message: "INVALID_DATE_US_SHORT", + type: "regex" + }; + break; + case "dateUsShortBetween" : + case "date_us_short_between" : + case "betweenDateUsShort" : + case "between_date_us_short" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15"; + } + validator = { + condition: [">=","<="], + dateType: "US_SHORT", + params: [ranges[0], ranges[1]], + pattern: /^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/, + message: "INVALID_DATE_US_SHORT_BETWEEN", + type: "conditionalDate" + }; + break; + case "dateUsShortMax" : + case "date_us_short_max" : + case "maxDateUsShort" : + case "max_date_us_short" : + validator = { + condition: "<=", + dateType: "US_SHORT", + params: [ruleParams], + pattern: /^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/, + message: "INVALID_DATE_US_SHORT_MAX", + type: "conditionalDate" + }; + break; + case "dateUsShortMin" : + case "date_us_short_min" : + case "minDateUsShort" : + case "min_date_us_short" : + validator = { + condition: ">=", + dateType: "US_SHORT", + params: [ruleParams], + pattern: /^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/, + message: "INVALID_DATE_US_SHORT_MIN", + type: "conditionalDate" + }; + break; + case "different" : + case "differentInput" : + case "different_input" : + var args = ruleParams.split(','); + validator = { + condition: "!=", + message: "INVALID_INPUT_DIFFERENT", + params: args, + type: "matching" + }; + break; + case "digits" : + validator = { + pattern: "^\\d{" + ruleParams + "}$", + message: "INVALID_DIGITS", + params: [ruleParams], + type: "regex" + }; + break; + case "digitsBetween" : + case "digits_between" : + var ranges = ruleParams.split(','); + if (ranges.length !== 2) { + throw "This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5"; + } + validator = { + pattern: "^\\d{" + ranges[0] + "," + ranges[1] + "}$", + message: "INVALID_DIGITS_BETWEEN", + params: [ranges[0], ranges[1]], + type: "regex" + }; + break; + case "email" : + case "emailAddress" : + case "email_address" : + validator = { + // Email RFC 5322, pattern pulled from http://www.regular-expressions.info/email.html + // but removed necessity of a TLD (Top Level Domain) which makes this email valid: admin@mailserver1 + pattern: /^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i, + message: "INVALID_EMAIL", + type: "regex" + }; + break; + case "exactLen" : + case "exact_len" : + validator = { + pattern: "^(.|[\\r\\n]){" + ruleParams + "}$", + message: "INVALID_EXACT_LEN", + params: [ruleParams], + type: "regex" + }; + break; + case "float" : + validator = { + pattern: /^\d*\.{1}\d+$/, + message: "INVALID_FLOAT", + type: "regex" + }; + break; + case "floatSigned" : + case "float_signed" : + validator = { + pattern: /^[-+]?\d*\.{1}\d+$/, + message: "INVALID_FLOAT_SIGNED", + type: "regex" + }; + break; + case "iban" : + validator = { + pattern: /^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i, + message: "INVALID_IBAN", + type: "regex" + }; + break; + case "enum" : + case "in" : + case "inList" : + case "in_list" : + var list = RegExp().escape(ruleParams).replace(/,/g, '|'); // escape string & replace comma (,) by pipe (|) + validator = { + pattern: "^(" + list + ")$", + patternFlag: 'i', + message: "INVALID_IN_LIST", + params: [ruleParams], + type: "regex" + }; + break; + case "int" : + case "integer" : + validator = { + pattern: /^\d+$/, + message: "INVALID_INTEGER", + type: "regex" + }; + break; + case "intSigned" : + case "integerSigned" : + case "int_signed" : + case "integer_signed" : + validator = { + pattern: /^[+-]?\d+$/, + message: "INVALID_INTEGER_SIGNED", + type: "regex" + }; + break; + case "ip" : + case "ipv4" : + validator = { + pattern: /^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/, + message: "INVALID_IPV4", + type: "regex" + }; + break; + case "ipv6" : + validator = { + pattern: /^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i, + message: "INVALID_IPV6", + type: "regex" + }; + break; + case "compare" : + case "match" : + case "matchInput" : + case "match_input" : + case "same" : + var args = ruleParams.split(','); + validator = { + condition: "===", + message: "INVALID_INPUT_MATCH", + params: args, + type: "matching" + }; + break; + case "max" : + validator = { + patternLength: "^(.|[\\r\\n]){0," + ruleParams + "}$", + messageLength: "INVALID_MAX_CHAR", + conditionNum: "<=", + messageNum: "INVALID_MAX_NUM", + params: [ruleParams], + type: "autoDetect" + }; + break; + case "maxLen" : + case "max_len" : + case "maxLength" : + case "max_length" : + validator = { + pattern: "^(.|[\\r\\n]){0," + ruleParams + "}$", + message: "INVALID_MAX_CHAR", + params: [ruleParams], + type: "regex" + }; + break; + case "maxNum" : + case "max_num" : + validator = { + condition: "<=", + message: "INVALID_MAX_NUM", + params: [ruleParams], + type: "conditionalNumber" + }; + break; + case "min" : + validator = { + patternLength: "^(.|[\\r\\n]){" + ruleParams + ",}$", + messageLength: "INVALID_MIN_CHAR", + conditionNum: ">=", + messageNum: "INVALID_MIN_NUM", + params: [ruleParams], + type: "autoDetect" + }; + break; + case "minLen" : + case "min_len" : + case "minLength" : + case "min_length" : + validator = { + pattern: "^(.|[\\r\\n]){" + ruleParams + ",}$", + message: "INVALID_MIN_CHAR", + params: [ruleParams], + type: "regex" + }; + break; + case "minNum" : + case "min_num" : + validator = { + condition: ">=", + message: "INVALID_MIN_NUM", + params: [ruleParams], + type: "conditionalNumber" + }; + break; + case "notIn" : + case "not_in" : + case "notInList" : + case "not_in_list" : + var list = RegExp().escape(ruleParams).replace(/,/g, '|'); // escape string & replace comma (,) by pipe (|) + validator = { + pattern: "^((?!(" + list + ")).)+$", + patternFlag: 'i', + message: "INVALID_NOT_IN_LIST", + params: [ruleParams], + type: "regex" + }; + break; + case "numeric" : + validator = { + pattern: /^\d*\.?\d+$/, + message: "INVALID_NUMERIC", + type: "regex" + }; + break; + case "numericSigned" : + case "numeric_signed" : + validator = { + pattern: /^[-+]?\d*\.?\d+$/, + message: "INVALID_NUMERIC_SIGNED", + type: "regex" + }; + break; + case "phone" : + validator = { + pattern: /^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/, + message: "INVALID_PHONE_US", + type: "regex" + }; + break; + case "phoneInternational" : + case "phone_international" : + validator = { + pattern: /^\+(?:[0-9]\x20?){6,14}[0-9]$/, + message: "INVALID_PHONE_INTERNATIONAL", + type: "regex" + }; + break; + case "pattern" : + case "regex" : + // Custom User Regex is a special case, the properties (message, pattern) were created and dealt separately prior to the for loop + validator = { + pattern: customUserRegEx.pattern, + message: "INVALID_PATTERN", + params: [customUserRegEx.message], + type: "regex" + }; + break; + case "remote" : + validator = { + message: '', // there is no error message defined on this one since user will provide his own error message via remote response or `alt=` + params: [ruleParams], + type: "remote" + }; + break; + case "required" : + validator = { + pattern: /\S+/, + message: "INVALID_REQUIRED", + type: "regex" + }; + break; + case "size" : + validator = { + patternLength: "^(.|[\\r\\n]){" + ruleParams + "}$", + messageLength: "INVALID_EXACT_LEN", + conditionNum: "==", + messageNum: "INVALID_EXACT_NUM", + params: [ruleParams], + type: "autoDetect" + }; + break; + case "url" : + validator = { + pattern: /^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i, + message: "INVALID_URL", + type: "regex" + }; + break; + case "time" : + validator = { + pattern: /^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/, + message: "INVALID_TIME", + type: "regex" + }; + break; + } // switch() + + // add the possible alternate text user might have provided + validator.altText = alternateText; + + return validator; + } // getElementValidators() +}]); + +/** extend RegExp object to have an escape function + * @param string text + * @return escaped string + */ +RegExp.prototype.escape = function(text) { + if (!arguments.callee.sRE) { + var specials = [ + '/', '.', '*', '+', '?', '|', + '(', ')', '[', ']', '{', '}', '\\' + ]; + arguments.callee.sRE = new RegExp( + '(\\' + specials.join('|\\') + ')', 'g' + ); + } + return text.replace(arguments.callee.sRE, '\\$1'); +} +/** + * Angular-Validation Service (ghiscoding) + * https://github.com/ghiscoding/angular-validation + * + * @author: Ghislain B. + * @desc: angular-validation service definition + * Provide a way to programmatically create validators and validate a form directly from within the controller. + * This Service is totally independant from the Directive, it could be used separately but the minimum it needs is the `validation-rules.js` file. + */ +angular + .module('ghiscoding.validation') + .service('ValidationService', ['$interpolate', '$q', '$timeout', 'ValidationCommon', function ($interpolate, $q, $timeout, ValidationCommon) { + // global variables of our object (start with _var) + var _blurHandler; + var _watchers = []; + var _validateOnEmpty; + var _validationCallback; + var _globalOptions; + + // service constructor + var ValidationService = function (globalOptions) { + this.isValidationCancelled = false; // is the validation cancelled? + this.timer = null; // timer of user inactivity time + this.validationAttrs = {}; // Current Validator attributes + this.commonObj = new ValidationCommon(); // Object of validationCommon service + + // if global options were passed to the constructor + if (!!globalOptions) { + this.setGlobalOptions(globalOptions); + } + + _globalOptions = this.commonObj.getGlobalOptions(); + } + + // list of available published public functions of this object + ValidationService.prototype.addValidator = addValidator; // add a Validator to current element + ValidationService.prototype.checkFormValidity = checkFormValidity; // check the form validity (can be called by an empty ValidationService and used by both Directive/Service) + ValidationService.prototype.removeValidator = removeValidator; // remove a Validator from an element + ValidationService.prototype.resetForm = resetForm; // reset the form (reset it to Pristine and Untouched) + ValidationService.prototype.setDisplayOnlyLastErrorMsg = setDisplayOnlyLastErrorMsg; // setter on the behaviour of displaying only the last error message + ValidationService.prototype.setGlobalOptions = setGlobalOptions; // set and initialize global options used by all validators + ValidationService.prototype.clearInvalidValidatorsInSummary = clearInvalidValidatorsInSummary; // clear clearInvalidValidatorsInSummary + + return ValidationService; + + //---- + // Public Functions declaration + //---------------------------------- + + /** Add a validator on a form element, the argument could be passed as 1 single object (having all properties) or 2 to 3 string arguments + * @param mixed var1: could be a string (element name) or an object representing the validator + * @param string var2: [optional] validator rules + * @param string var3: [optional] friendly name + */ + function addValidator(var1, var2, var3) { + var self = this; + var attrs = {}; + + // find if user provided 2 string arguments else it will be a single object with all properties + if(typeof var1 === "string" && typeof var2 === "string") { + attrs.elmName = var1; + attrs.rules = var2; + attrs.friendlyName = (typeof var3 === "string") ? var3 : ''; + }else { + attrs = var1; + } + + // Make sure that we have all required attributes to work properly + if(typeof attrs !== "object" || !attrs.hasOwnProperty('elmName') || !attrs.hasOwnProperty('rules') || (!attrs.hasOwnProperty('scope') && typeof self.validationAttrs.scope === "undefined") ) { + throw 'Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}'; + } + + // get the scope from the validator or from the global options (validationAttrs) + var scope = (!!attrs.scope) ? attrs.scope : self.validationAttrs.scope; + + // find the DOM element & make sure it's a filled object before going further + // we will exclude disabled/ng-disabled element from being validated + attrs.elm = angular.element(document.querySelector('[name="'+attrs.elmName+'"]')); + if(typeof attrs.elm !== "object" || attrs.elm.length === 0) { + return self; + } + + // copy the element attributes name to use throughout validationCommon + // when using dynamic elements, we might have encounter unparsed or uncompiled data, we need to get Angular result with $interpolate + if(new RegExp("{{(.*?)}}").test(attrs.elmName)) { + attrs.elmName = $interpolate(attrs.elmName)(scope); + } + attrs.name = attrs.elmName; + + // user could pass his own scope, useful in a case of an isolate scope + if (!!self.validationAttrs.isolatedScope) { + var tempValidationOptions = scope.$validationOptions || null; // keep global validationOptions + scope = self.validationAttrs.isolatedScope; // rewrite original scope + if(!!tempValidationOptions) { + scope.$validationOptions = tempValidationOptions; // reuse the validationOption from original scope + } + } + + // Possible element attributes + _validationCallback = (self.validationAttrs.hasOwnProperty('validationCallback')) ? self.validationAttrs.validationCallback : null; + _validateOnEmpty = (self.validationAttrs.hasOwnProperty('validateOnEmpty')) ? self.commonObj.parseBool(self.validationAttrs.validateOnEmpty) : !!_globalOptions.validateOnEmpty; + + // onBlur make validation without waiting + attrs.elm.bind('blur', _blurHandler = function(event) { + // get the form element custom object and use it after + var formElmObj = self.commonObj.getFormElementByName(attrs.elmName); + + if (!!formElmObj && !formElmObj.isValidationCancelled) { + // re-initialize to use current element & validate without delay + self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); + + // attempt to validate & run validation callback if user requested it + var validationPromise = attemptToValidate(self, event.target.value, 0); + if(!!_validationCallback) { + self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + } + }); + + // merge both attributes but 2nd object (attrs) as higher priority, so that for example debounce property inside `attrs` as higher priority over `validatorAttrs` + // so the position inside the mergeObject call is very important + attrs = self.commonObj.mergeObjects(self.validationAttrs, attrs); + + // watch the `disabled` attribute for changes + // if it become disabled then skip validation else it becomes enable then we need to revalidate it + watchNgDisabled(self, scope, attrs); + + // if DOM element gets destroyed, we need to cancel validation, unbind onBlur & remove it from $validationSummary + attrs.elm.on('$destroy', function() { + // get the form element custom object and use it after + var formElmObj = self.commonObj.getFormElementByName(self.commonObj.ctrl.$name); + + // unbind everything and cancel the validation + if(!!formElmObj) { + cancelValidation(self, formElmObj); + self.commonObj.removeFromValidationSummary(attrs.name); + } + }); + + // save the watcher inside an array in case we want to deregister it when removing a validator + _watchers.push({ elmName: attrs.elmName, watcherHandler: createWatch(scope, attrs, self) }); + + return self; + } // addValidator() + + /** Check the form validity (can be called by an empty ValidationService and used by both Directive/Service) + * Loop through Validation Summary and if any errors found then display them and return false on current function + * @param object Angular Form or Scope Object + * @param bool silently, do a form validation silently + * @return bool isFormValid + */ + function checkFormValidity(obj, silently) { + var self = this; + var ctrl, elm, elmName = '', isValid = true; + if(typeof obj === "undefined" || typeof obj.$validationSummary === "undefined") { + throw 'checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)'; + } + + // loop through $validationSummary and display errors when found on each field + for(var i = 0, ln = obj.$validationSummary.length; i < ln; i++) { + isValid = false; + elmName = obj.$validationSummary[i].field; + + if(!!elmName) { + // get the form element custom object and use it after + var formElmObj = self.commonObj.getFormElementByName(elmName); + + if(!!formElmObj && !!formElmObj.elm && formElmObj.elm.length > 0) { + // make the element as it was touched for CSS, only works in AngularJS 1.3+ + if (typeof formElmObj.ctrl.$setTouched === "function" && !silently) { + formElmObj.ctrl.$setTouched(); + } + self.commonObj.updateErrorMsg(obj.$validationSummary[i].message, { isSubmitted: (!!silently ? false : true), isValid: formElmObj.isValid, obj: formElmObj }); + } + } + } + return isValid; + } + + /** Remove all objects in validationsummary and matching objects in FormElementList. + * This is for use in a wizard type setting, where you 'move back' to a previous page in wizard. + * In this case you need to remove invalid validators that will exist in 'the future'. + * @param object Angular Form or Scope Object + */ + function clearInvalidValidatorsInSummary(obj) { + var self = this; + if (typeof obj === "undefined" || typeof obj.$validationSummary === "undefined") { + throw 'clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)'; + } + // Get list of names to remove + var elmName = []; + for (var i = 0, ln = obj.$validationSummary.length; i < ln; i++) { + elmName.push(obj.$validationSummary[i].field); + } + // Loop on list of names. Cannot loop on obj.$validationSummary as you are removing objects from it in the loop. + for (i = 0, ln = elmName.length; i < ln; i++) { + if (!!elmName[i]) { + self.commonObj.removeFromFormElementObjectList(elmName[i]); + self.commonObj.removeFromValidationSummary(elmName[i], obj.$validationSummary); + } + } + } + + /** Remove a validator and also any withstanding error message from that element + * @param object Angular Form or Scope Object + * @param object arguments that could be passed to the function + * @return object self + */ + function removeValidator(obj, args) { + var self = this; + var formElmObj; + + if(typeof obj === "undefined" || typeof obj.$validationSummary === "undefined") { + throw 'removeValidator() only works with Validation that were defined by the Service (not by the Directive) and requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)'; + } + + // Note: removeAttr() will remove validation attribute from the DOM (if defined by Directive), but as no effect when defined by the Service + // removeValidator() 2nd argument could be passed an Array or a string of element name(s) + // if it's an Array we will loop through all elements to be removed + // else just remove the 1 element defined as a string + if (args instanceof Array) { + for (var i = 0, ln = args.length; i < ln; i++) { + formElmObj = self.commonObj.getFormElementByName(args[i]); + formElmObj.elm.removeAttr('validation'); + removeWatcherAndErrorMessage(self, formElmObj, obj.$validationSummary); + } + } + else if(args instanceof Object && !!args.formElmObj) { + formElmObj = args.formElmObj; + formElmObj.elm.removeAttr('validation'); + removeWatcherAndErrorMessage(args.self, formElmObj, obj.$validationSummary); + } + else { + formElmObj = self.commonObj.getFormElementByName(args); + formElmObj.elm.removeAttr('validation'); + removeWatcherAndErrorMessage(self, formElmObj, obj.$validationSummary); + } + + return self; + } + + /** Reset a Form, reset all input element to Pristine, Untouched & remove error dislayed (if any) + * @param object Angular Form or Scope Object + * @param object arguments that could be passed to the function + */ + function resetForm(obj, args) { + var self = this; + var formElmObj; + var args = args || {}; + var shouldRemoveValidator = (typeof args.removeAllValidators !== "undefined") ? args.removeAllValidators : false; + var shouldEmptyValues = (typeof args.emptyAllInputValues !== "undefined") ? args.emptyAllInputValues : false; + + if(typeof obj === "undefined" || typeof obj.$name === "undefined") { + throw 'resetForm() requires a valid Angular Form object passed as argument to work properly (ex.: $scope.form1).'; + } + + // get all Form input elements and loop through all of them to set them Pristine, Untouched and also remove errors displayed + var formElements = self.commonObj.getFormElements(obj.$name); + if(formElements instanceof Array) { + for (var i = 0, ln = formElements.length; i < ln; i++) { + formElmObj = formElements[i]; + + // should we empty input elment values as well? + if(!!shouldEmptyValues) { + formElmObj.elm.val(null); + } + + // should we remove all validators? + // if yes, then run removeValidator() and since that already removes message & make input valid, no need to run the $setUntouched() and $setPristine() + // else make the field $setUntouched() and $setPristine() + if(!!shouldRemoveValidator) { + removeValidator(obj, { self: self, formElmObj: formElmObj}); + }else { + // make the element as it was touched for CSS, only works in AngularJS 1.3+ + if (typeof formElmObj.ctrl.$setUntouched === "function") { + formElmObj.ctrl.$setUntouched(); + } + formElmObj.ctrl.$setPristine(); + self.commonObj.updateErrorMsg('', { isValid: false, obj: formElmObj }); + } + } + } + } + + /** Setter on the behaviour of displaying only the last error message of each element. + * By default this is false, so the behavior is to display all error messages of each element. + * @param boolean value + */ + function setDisplayOnlyLastErrorMsg(boolValue) { + var self = this; + var isDisplaying = (typeof boolValue === "boolean") ? boolValue : true; + self.commonObj.setDisplayOnlyLastErrorMsg(isDisplaying); + } + + /** Set and initialize global options used by all validators + * @param object: global options + * @return object self + */ + function setGlobalOptions(options) { + var self = this; + self.validationAttrs = options; // save in global + self.commonObj.setGlobalOptions(options); + + return self; + } + + //---- + // Private functions declaration + //---------------------------------- + + /** Validator function to attach to the element, this will get call whenever the input field is updated + * and is also customizable through the (typing-limit) for which inactivity this.timer will trigger validation. + * @param object self + * @param string value: value of the input field + * @param int typingLimit: when user stop typing, in how much time it will start validating + * @return object validation promise + */ + function attemptToValidate(self, value, typingLimit) { + var deferred = $q.defer(); + var isValid = false; + + // get the waiting delay time if passed as argument or get it from common Object + var waitingLimit = (typeof typingLimit !== "undefined") ? typingLimit : self.commonObj.typingLimit; + + // get the form element custom object and use it after + var formElmObj = self.commonObj.getFormElementByName(self.commonObj.ctrl.$name); + + // if a field holds invalid characters which are not numbers inside an `input type="number"`, then it's automatically invalid + // we will still call the `.validate()` function so that it shows also the possible other error messages + if(!!value && !!value.badInput) { + return invalidateBadInputField(self, attrs.name); + } + + // pre-validate without any events just to pre-fill our validationSummary with all field errors + // passing false as 2nd argument for not showing any errors on screen + self.commonObj.validate(value, false); + + // if field is not required and his value is empty, cancel validation and exit out + if(!self.commonObj.isFieldRequired() && !_validateOnEmpty && (value === "" || value === null || typeof value === "undefined")) { + cancelValidation(self, formElmObj); + deferred.resolve({ isFieldValid: true, formElmObj: formElmObj, value: value }); + return deferred.promise; + }else { + formElmObj.isValidationCancelled = false; + } + + // invalidate field before doing any validation + if(!!value || self.commonObj.isFieldRequired() || _validateOnEmpty) { + self.commonObj.ctrl.$setValidity('validation', false); + } + + // if a field holds invalid characters which are not numbers inside an `input type="number"`, then it's automatically invalid + // we will still call the `.validate()` function so that it shows also the possible other error messages + if((value === "" || typeof value === "undefined") && self.commonObj.elm.prop('type').toUpperCase() === "NUMBER") { + $timeout.cancel(self.timer); + isValid = self.commonObj.validate(value, true); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + return deferred.promise; + } + + // select(options) will be validated on the spot + if(self.commonObj.elm.prop('tagName').toUpperCase() === "SELECT") { + isValid = self.commonObj.validate(value, true); + self.commonObj.ctrl.$setValidity('validation', isValid); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + return deferred.promise; + } + + // onKeyDown event is the default of Angular, no need to even bind it, it will fall under here anyway + // in case the field is already pre-filled, we need to validate it without looking at the event binding + if(typeof value !== "undefined") { + // when no timer, validate right away without a $timeout. This seems quite important on the array input value check + if(typingLimit === 0) { + isValid = self.commonObj.validate(value, true); + self.commonObj.scope.$evalAsync(self.commonObj.ctrl.$setValidity('validation', isValid )); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + $timeout.cancel(self.timer); + }else { + // Make the validation only after the user has stopped activity on a field + // everytime a new character is typed, it will cancel/restart the timer & we'll erase any error mmsg + self.commonObj.updateErrorMsg(''); + $timeout.cancel(self.timer); + self.timer = $timeout(function() { + isValid = self.commonObj.validate(value, true); + self.commonObj.scope.$evalAsync(self.commonObj.ctrl.$setValidity('validation', isValid )); + deferred.resolve({ isFieldValid: isValid, formElmObj: formElmObj, value: value }); + }, waitingLimit); + } + } + + return deferred.promise; + } // attemptToValidate() + + /** Cancel current validation test and blank any leftover error message + * @param object obj + * @param object formElmObj: form element object + */ + function cancelValidation(obj, formElmObj) { + // get the form element custom object and use it after + var ctrl = (!!formElmObj && !!formElmObj.ctrl) ? formElmObj.ctrl : obj.commonObj.ctrl; + + if(!!formElmObj) { + formElmObj.isValidationCancelled = true; + } + $timeout.cancel(self.timer); + ctrl.$setValidity('validation', true); + obj.commonObj.updateErrorMsg('', { isValid: true, obj: formElmObj }); + + // unbind onBlur handler (if found) so that it does not fail on a non-required element that is now dirty & empty + unbindBlurHandler(obj, formElmObj); + } + + /** watch the element for any value change, validate it once that happen + * @return new watcher + */ + function createWatch(scope, attrs, self) { + return scope.$watch(function() { + attrs.ctrl = angular.element(attrs.elm).controller('ngModel'); + + if(isKeyTypedBadInput(self, attrs.elmName)) { + return { badInput: true }; + } + return attrs.ctrl.$modelValue; + }, function (newValue, oldValue) { + if(!!newValue && !!newValue.badInput) { + var formElmObj = self.commonObj.getFormElementByName(attrs.elmName); + unbindBlurHandler(self, formElmObj); + return invalidateBadInputField(self, attrs.name); + } + // when previous value was set and new value is not, this is most probably an invalid character entered in a type input="text" + // we will still call the `.validate()` function so that it shows also the possible other error messages + if(newValue === undefined && (oldValue !== undefined && !isNaN(oldValue))) { + $timeout.cancel(self.timer); + self.commonObj.ctrl.$setValidity('validation', self.commonObj.validate('', true)); + return; + } + // from the DOM element, find the Angular controller of this element & add value as well to list of attribtues + attrs.ctrl = angular.element(attrs.elm).controller('ngModel'); + attrs.value = newValue; + + self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); + + var waitingTimer = (typeof newValue === "undefined" || (typeof newValue === "number" && isNaN(newValue))) ? 0 : undefined; + // attempt to validate & run validation callback if user requested it + var validationPromise = attemptToValidate(self, newValue, waitingTimer); + if(!!_validationCallback) { + self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + }, true); // $watch() + } + + /** Invalidate the field that was tagged as bad input, cancel the timer validation, + * display an invalid key error and add it as well to the validation summary. + * @param object self + * @param string: element input name + */ + function invalidateBadInputField(self, elmName) { + $timeout.cancel(self.timer); + var formElmObj = self.commonObj.getFormElementByName(elmName); + self.commonObj.updateErrorMsg('INVALID_KEY_CHAR', { isValid: false, translate: true, obj: formElmObj }); + self.commonObj.addToValidationSummary(formElmObj, 'INVALID_KEY_CHAR', true); + } + + /** Was the characters typed by the user bad input or not? + * @param object self + * @param string: element input name + * @return bool + */ + function isKeyTypedBadInput(self, elmName) { + var formElmObj = self.commonObj.getFormElementByName(elmName); + return (!!formElmObj && !!formElmObj.elm.prop('validity') && formElmObj.elm.prop('validity').badInput === true); + } + + /** Remove a watcher and any withstanding error message from the element + * @param object self + * @param object formElmObj: form element object + * @param object validationSummary + */ + function removeWatcherAndErrorMessage(self, formElmObj, validationSummary) { + var scope = + !!self.commonObj.scope + ? self.commonObj.scope + : !!formElmObj.scope + ? formElmObj.scope + : null; + if(typeof scope === "undefined") { + throw 'removeValidator() requires a valid $scope object passed but unfortunately could not find it.'; + } + + // deregister the $watch from the _watchers array we kept it + var foundWatcher = self.commonObj.arrayFindObject(_watchers, 'elmName', formElmObj.fieldName); + if(!!foundWatcher) { + foundWatcher.watcherHandler(); // deregister the watch by calling his handler + _watchers.shift(); + } + + // make the validation cancelled so it won't get called anymore in the blur eventHandler + formElmObj.isValidationCancelled = true; + formElmObj.isValid = true; + formElmObj.attrs.validation = ""; + cancelValidation(self, formElmObj); + + // now to remove any errors, we need to make the element untouched, pristine and remove the validation + // also remove it from the validationSummary list and remove any displayed error + if (typeof formElmObj.ctrl.$setUntouched === "function") { + // make the element untouched in CSS, only works in AngularJS 1.3+ + formElmObj.ctrl.$setUntouched(); + } + self.commonObj.scope = scope; + formElmObj.ctrl.$setPristine(); + self.commonObj.removeFromValidationSummary(formElmObj.fieldName, validationSummary); + } + + /** If found unbind the blur hanlder + * @param object self + * @param object formElmObj: form element object + */ + function unbindBlurHandler(obj, formElmObj) { + formElmObj.isValidationCancelled = true; + if(typeof _blurHandler === "function") { + var elm = (!!formElmObj && !!formElmObj.elm) ? formElmObj.elm : obj.commonObj.elm; + elm.unbind('blur', _blurHandler); + } + } + + /** Watch for an disabled/ngDisabled attribute change, + * if it become disabled then skip validation else it becomes enable then we need to revalidate it + * @param object self + * @param object scope + * @param object attributes + */ + function watchNgDisabled(self, scope, attrs) { + scope.$watch(function() { + return (typeof attrs.elm.attr('ng-disabled') === "undefined") ? null : scope.$eval(attrs.elm.attr('ng-disabled')); //this will evaluate attribute value `{{}}`` + }, function(disabled) { + if(typeof disabled === "undefined" || disabled === null) { + return null; + } + + // get current ctrl of element & re-initialize to use current element + attrs.ctrl = angular.element(attrs.elm).controller('ngModel'); + self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); + + // get the form element custom object and use it after + var formElmObj = self.commonObj.getFormElementByName(attrs.name); + + // use a timeout so that the digest of removing the `disabled` attribute on the DOM is completed + // because commonObj.validate() checks for both the `disabled` and `ng-disabled` attribute so it basically fails without the $timeout because of the digest + $timeout(function() { + var isDisabled = (disabled === "") + ? true + : (typeof disabled === "boolean") ? disabled + : (typeof disabled !== "undefined") ? scope.$eval(disabled) : false; + + if (isDisabled) { + // Remove it from validation summary + attrs.ctrl.$setValidity('validation', true); + self.commonObj.updateErrorMsg('', { isValid: true, obj: formElmObj }); + self.commonObj.removeFromValidationSummary(attrs.name); + } else { + // Re-Validate the input when enabled (without displaying the error) + var value = attrs.ctrl.$viewValue || ''; + + // re-initialize to use current element & validate without delay (without displaying the error) + self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); + attrs.ctrl.$setValidity('validation', self.commonObj.validate(value, false)); + + // make sure it's re-enable the validation as well + if(!!formElmObj) { + formElmObj.isValidationCancelled = false; + } + + // re-attach the onBlur handler + attrs.elm.bind('blur', _blurHandler = function(event) { + if (!!formElmObj && !formElmObj.isValidationCancelled) { + // attempt to validate & run validation callback if user requested it + var validationPromise = attemptToValidate(self, event.target.value, 10); + if(!!_validationCallback) { + self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + } + }); + } + }, 0, false); + + // these cannot be done inside the $timeout, when doing it would cancel validation for all element because of the delay + if (disabled) { + // Turn off validation when element is disabled & remove from validationSummary (seems I need to remove from summary inside $timeout and outside) + // make the element as it was untouched for CSS, only works in AngularJS 1.3+ + if (typeof attrs.ctrl.$setUntouched === "function") { + attrs.ctrl.$setUntouched(); + } + attrs.ctrl.$setValidity('validation', true); + self.commonObj.removeFromValidationSummary(attrs.name); + } + }); + } + +}]); // ValidationService \ No newline at end of file diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index 618e84c..76f8a0d 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.19 + * @version: 1.5.20 * @license: MIT - * @build: Mon Apr 17 2017 23:41:06 GMT-0400 (Eastern Daylight Time) + * @build: Thu Apr 20 2017 12:18:09 GMT-0400 (Eastern Daylight Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+(n&&n.params?String.format(a,n.params):a):p.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+o:p.message+=s+o,O(i,e,p.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=l.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],s,l),d=M(t.condition[1],s,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)s=!!d;else{if("object"!=typeof d)throw u;s=!!d.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(p.condition,d.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=p.message;p.altText&&p.altText.length>0&&(o=p.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,i,!0)})}d.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),s=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),l=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(s||l)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; -angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return g=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,$=n.validationAttrs.hasOwnProperty("validateOnEmpty")?commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);g&&n.commonObj.runValidationCallbackOnPromise(t,g)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a Date: Thu, 20 Apr 2017 12:22:09 -0400 Subject: [PATCH 08/34] update changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index e088f53..a31f2d2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.20 (2017-04-20) Add an unminified version and Fix #153 bug in validation service. 1.5.19 (2017-04-17) Fix #150 angularValidation.revalidate problems 1.5.18 (2017-03-31) Fix disabled="false" as attribute to run validation. 1.5.17 (2017-03-10) Add silent mode to checkFormValidity function From 25993a6a3cd44a68b0bd5e93ccfd8adf21409ad6 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Mon, 15 May 2017 00:51:42 -0400 Subject: [PATCH 09/34] Fix #151 validation rule "different" makes "required" not enforced --- bower.json | 2 +- dist/angular-validation.js | 13 ++++++++----- dist/angular-validation.min.js | 6 +++--- package.json | 2 +- readme.md | 2 +- src/validation-common.js | 9 ++++++--- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bower.json b/bower.json index 110ecee..c18636e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.20", + "version": "1.5.21", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/dist/angular-validation.js b/dist/angular-validation.js index 323f9fc..124ef27 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -2,9 +2,9 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.20 + * @version: 1.5.21 * @license: MIT - * @build: Thu Apr 20 2017 12:18:09 GMT-0400 (Eastern Daylight Time) + * @build: Sun May 14 2017 23:35:23 GMT-0400 (Eastern Daylight Time) */ /** * Angular-Validation Directive (ghiscoding) @@ -949,7 +949,6 @@ angular var nbValid = 0; var validator; var validatedObject = {}; - // make an object to hold the message so that we can reuse the object by reference // in some of the validation check (for example "matching" and "remote") var validationElmObj = { @@ -1720,7 +1719,9 @@ angular var matchingCtrl = self.ctrl; // keep reference of matching confirmation controller var formElmMatchingObj = getFormElementByName(self.ctrl.$name); - isValid = (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue); + isValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null) + ? false + : (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue); // if element to compare against has a friendlyName or if matching 2nd argument was passed, we will use that as a new friendlyName // ex.: :: we would use the friendlyName of 'Password1' not input1 @@ -1734,7 +1735,9 @@ angular // Watch for the parent ngModel, if it change we need to re-validate the child (confirmation) self.scope.$watch(parentNgModel, function(newVal, oldVal) { - var isWatchValid = testCondition(matchingValidator.condition, matchingCtrl.$viewValue, newVal); + var isWatchValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null) + ? false + : (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue); // only inspect on a parent input value change if(newVal !== oldVal) { diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index 76f8a0d..45b6cd1 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.20 + * @version: 1.5.21 * @license: MIT - * @build: Thu Apr 20 2017 12:18:09 GMT-0400 (Eastern Daylight Time) + * @build: Sun May 14 2017 23:35:23 GMT-0400 (Eastern Daylight Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); -angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=V(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var s=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",l={field:n,friendlyName:s,message:t,formName:i?i.$name:null};o>=0?Q[o]=l:Q.push(l)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",s=i.match(new RegExp("^/(.*?)/([gimy]*)$")),l=new RegExp(s[1],s[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:l},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function s(e){return e?A(z,"formName",e):z}function l(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var s=t&&t.translate?a.instant(e):e;s=s.trim();var l=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+l)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(s):n.after('
'+s+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,s=!0,l=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+(n&&n.params?String.format(a,n.params):a):p.message+=s+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,l,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=s+o:p.message+=s+o,O(i,e,p.message,l,t)})}(m,s,r)),s&&u++,i.validRequireHowMany==u&&s){l=!0;break}}return s&&(n(i,""),i.updateErrorMsg("",{isValid:s})),m&&(m.isValid=l,l&&(m.message="")),l}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),s=t&&t.friendlyName?a.instant(t.friendlyName):"",l={fieldName:i,friendlyName:s,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(z,"fieldName",e.attr("name"));return u>=0?z[u]=l:z.push(l),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=l.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[l]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],s=n[1],l=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,s-1,l,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,s=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var l=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],s,l),d=M(t.condition[1],s,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,s,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var s=!0,l="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)s=!!d;else{if("object"!=typeof d)throw u;s=!!d.isValid}if(s===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw l;O(r,n,e,!1,i)})):s===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return s}function H(e,t,r,n){var i=!0,s=t.params[0],l=r.scope.$eval(s),u=angular.element(document.querySelector('[name="'+s+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=M(t.condition,e,l)&&!!e,u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(s,function(e,t){var i=M(p.condition,d.$viewValue,e);if(e!==t){if(i)O(r,m,"",!0,!0);else{m.isValid=!1;var o=p.message;p.altText&&p.altText.length>0&&(o=p.altText.replace("alt=","")),a(o).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,i,!0)})}d.$setValidity("validation",i)}},!0),i}function I(e,t,a,r,n,i){var o=!0,s="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",l="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw l;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw l;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw s;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),s=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),l=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(s||l)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=s,X.prototype.getGlobalOptions=l,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); +angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=E(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?Q[o]=s:Q.push(s)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function l(e){return e?A(z,"formName",e):z}function s(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=E(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=E(n,"field",e);if(i>=0&&n.splice(i,1),i=E(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=E(z,"fieldName",e.attr("name"));return u>=0?z[u]=s:z.push(s),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var s=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],l,s),d=M(t.condition[1],l,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,l,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function H(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function I(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=l,X.prototype.getGlobalOptions=s,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return g=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,$=n.validationAttrs.hasOwnProperty("validateOnEmpty")?n.commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);g&&n.commonObj.runValidationCallbackOnPromise(t,g)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a :: we would use the friendlyName of 'Password1' not input1 @@ -1295,7 +1296,9 @@ angular // Watch for the parent ngModel, if it change we need to re-validate the child (confirmation) self.scope.$watch(parentNgModel, function(newVal, oldVal) { - var isWatchValid = testCondition(matchingValidator.condition, matchingCtrl.$viewValue, newVal); + var isWatchValid = ((!validator.pattern || validator.pattern.toString() === "/\\S+/" || (!!rules && validator.pattern === "required")) && strValue === null) + ? false + : (testCondition(validator.condition, strValue, parentNgModelVal) && !!strValue); // only inspect on a parent input value change if(newVal !== oldVal) { From d0e330e125b7acf6260f738f14392eb90a7243fd Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Mon, 15 May 2017 00:54:04 -0400 Subject: [PATCH 10/34] update changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index a31f2d2..0a4aea3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.21 (2017-05-14) Fix #151 validation rule "different" disables rule "required". 1.5.20 (2017-04-20) Add an unminified version and Fix #153 bug in validation service. 1.5.19 (2017-04-17) Fix #150 angularValidation.revalidate problems 1.5.18 (2017-03-31) Fix disabled="false" as attribute to run validation. From 1cf429cbcfa083fc1f76c61604f47b03f59a5ea8 Mon Sep 17 00:00:00 2001 From: wbiz Date: Wed, 7 Jun 2017 22:17:35 +1000 Subject: [PATCH 11/34] support simplified Chinese --- locales/validation/zh_CN.json | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 locales/validation/zh_CN.json diff --git a/locales/validation/zh_CN.json b/locales/validation/zh_CN.json new file mode 100644 index 0000000..f428d4f --- /dev/null +++ b/locales/validation/zh_CN.json @@ -0,0 +1,105 @@ +{ + "INVALID_ACCEPTED": "必须接受。 ", + "INVALID_ALPHA": "可能只包含字母。 ", + "INVALID_ALPHA_SPACE": "可能只包含字母和空格。 ", + "INVALID_ALPHA_NUM": "可能只包含字母和数字。 ", + "INVALID_ALPHA_NUM_SPACE": "只能包含字母,数字和空格。 ", + "INVALID_ALPHA_DASH": "只能包含字母,数字和破折号。 ", + "INVALID_ALPHA_DASH_SPACE": "可能只包含字母,数字,破折号和空格。 ", + "INVALID_BETWEEN_CHAR": "文本长度必须在{0}和{1}个字符之间。 ", + "INVALID_BETWEEN_NUM": "需要是{0}到{1}之间的数值。 ", + "INVALID_BOOLEAN": "可能只包含真实或虚假的价值。 ", + "INVALID_CREDIT_CARD": "必须是有效的信用卡号。 ", + "INVALID_DATE_EURO": "必须是有效的日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy)。 ", + "INVALID_DATE_EURO_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy)。 ", + "INVALID_DATE_EURO_MAX": "需要是有效的日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy), 等于或低于 {0}。 ", + "INVALID_DATE_EURO_MIN": "需要是有效的日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy), 等于或高于 {0}。 ", + "INVALID_DATE_EURO_LONG": "必须是有效的日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy)。 ", + "INVALID_DATE_EURO_LONG_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy)。 ", + "INVALID_DATE_EURO_LONG_MAX": "需要是有效的日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy), 等于或低于 {0}。 ", + "INVALID_DATE_EURO_LONG_MIN": "需要是有效的日期格式 (dd-mm-yyyy) 或 (dd/mm/yyyy), 等于或高于 {0}。 ", + "INVALID_DATE_EURO_SHORT": "必须是有效的日期格式 (dd-mm-yy) 或 (dd/mm/yy)。 ", + "INVALID_DATE_EURO_SHORT_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (dd-mm-yy) 或 (dd/mm/yy)。 ", + "INVALID_DATE_EURO_SHORT_MAX": "需要是有效的日期格式 (dd-mm-yy) 或 (dd/mm/yy), 等于或低于 {0}。 ", + "INVALID_DATE_EURO_SHORT_MIN": "需要是有效的日期格式 (dd-mm-yy) 或 (dd/mm/yy), 等于或高于 {0}。 ", + "INVALID_DATE_ISO": "必须是有效的日期格式 (yyyy-mm-dd)。 ", + "INVALID_DATE_ISO_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (yyyy-mm-dd)。 ", + "INVALID_DATE_ISO_MAX": "需要是有效的日期格式 (yyyy-mm-dd), 等于或低于 {0}。 ", + "INVALID_DATE_ISO_MIN": "需要是有效的日期格式 (yyyy-mm-dd), 等于或高于 {0}。 ", + "INVALID_DATE_US": "必须是有效的日期格式 (mm/dd/yyyy) 或 (mm-dd-yyyy)。 ", + "INVALID_DATE_US_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (mm/dd/yyyy) 或 (mm-dd-yyyy)。 ", + "INVALID_DATE_US_MAX": "需要是有效的日期格式 (mm/dd/yyyy) 或 (mm-dd-yyyy), 等于或低于 {0}。 ", + "INVALID_DATE_US_MIN": "需要是有效的日期格式 (mm/dd/yyyy) 或 (mm-dd-yyyy), 等于或高于 {0}。 ", + "INVALID_DATE_US_LONG": "必须是有效的日期格式 (mm/dd/yyyy) 或 (mm-dd-yyyy)。 ", + "INVALID_DATE_US_LONG_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (mm/dd/yyyy) 或 (mm-dd-yyyy)。 ", + "INVALID_DATE_US_LONG_MAX": "需要是有效的日期格式(mm / dd / yy)OR(mm-dd-yy),等于或低于{0}。 ", + "INVALID_DATE_US_LONG_MIN": "需要是有效的日期格式(mm / dd / yy)或(mm-dd-yy),等于或低于{0}。 ", + "INVALID_DATE_US_SHORT": "必须是有效的日期格式 (mm/dd/yy) 或 (mm-dd-yy)。 ", + "INVALID_DATE_US_SHORT_BETWEEN": "需要在{0}和{1}之间的有效日期格式 (mm/dd/yy) 或 (mm-dd-yy)。 ", + "INVALID_DATE_US_SHORT_MAX": "需要是有效的日期格式 (mm/dd/yy) 或 (mm-dd-yy), 等于或低于 {0}。 ", + "INVALID_DATE_US_SHORT_MIN": "需要是有效的日期格式 (mm/dd/yy) 或 (mm-dd-yy), 等于或低于 {0}。 ", + "INVALID_DIGITS": "必须是{0}位数。 ", + "INVALID_DIGITS_BETWEEN": "必须介于{0}到{1}位数之间。 ", + "INVALID_EMAIL": "必须是一个有效的电子邮箱地址。 ", + "INVALID_EXACT_LEN": "必须有{0}个字符的长度。 ", + "INVALID_EXACT_NUM": "“必须完全是{0}。 ", + "INVALID_FLOAT": "可能只包含一个正的浮点值(不包括整数)。 ", + "INVALID_FLOAT_SIGNED": "可能只包含正值或负值浮点值(不包括整数)。 ", + "INVALID_IBAN": "必须是有效的IBAN。 ", + "INVALID_IN_LIST": "必须是这个列表中的选择:({0})。 ", + "INVALID_INPUT_DIFFERENT": "字段必须与指定字段[{1}]不同。 ", + "INVALID_INPUT_MATCH": "确认字段与指定字段[{1}]不匹配。 ", + "INVALID_INTEGER": "必须是正整数。 ", + "INVALID_INTEGER_SIGNED": "必须是正整数或负整数。 ", + "INVALID_IPV4": "必须是有效的IP(IPV4)。 ", + "INVALID_IPV6": "必须是有效的IP(IPV6)。 ", + "INVALID_IPV6_HEX": "必须是有效的IP(IPV6 Hex)。 ", + "INVALID_KEY_CHAR": "在”数字“类型的字段上输入的键盘无效。 ", + "INVALID_MAX_CHAR": "不能超过{0}个字符。 ", + "INVALID_MAX_NUM": "需要是数值,等于或低于{0}。 ", + "INVALID_MIN_CHAR": "必须至少{0}个字符。 ", + "INVALID_MIN_NUM": "需要是数值,等于或高于{0}。 ", + "INVALID_NOT_IN_LIST": "必须是这个列表之外的选择:({0})。 ", + "INVALID_NUMERIC": "必须是正数。 ", + "INVALID_NUMERIC_SIGNED": "必须是正数或负数。 ", + "INVALID_PATTERN": "必须遵循以下格式:{0}。 ", + "INVALID_PATTERN_DATA": "必须遵循此格式{{data}}。 ", + "INVALID_PHONE_US": "必须是有效的电话号码,必须包含区号。 ", + "INVALID_PHONE_INTERNATIONAL": "必须是有效的国际电话号码。 ", + "INVALID_REQUIRED": "此项是必须的。 ", + "INVALID_URL": "必须是有效的URL。 ", + "INVALID_TIME": "必须是有效的时间格式(hh:mm)或(hh:mm:ss)。 ", + "INVALID_CHECKBOX_SELECTED": "必须选中复选框。 ", + + "AREA1": "TextArea: 字母数字+最小(15)+ 必需", + "ERRORS": "错误", + "CHANGE_LANGUAGE": "改变语言", + "FORM_PREVALIDATED": "表格预先验证", + "INPUT1": "远程验证 - 为有效答案键入'abc' ", + "INPUT2": "数字正数或负数 - 输入类型='数字 - 非数字字符错误 ", + "INPUT3": "浮动数范围(不包括整数) - between_num:x,y OR min_num:x | max_num:y ", + "INPUT4": "多个验证+日期代码的自定义正则表达式(YYWW)", + "INPUT5": "电子邮件", + "INPUT6": "URL", + "INPUT7": "IP (IPV4)", + "INPUT8": "信用卡", + "INPUT9": "间于(2,6)之间的字符", + "INPUT10": "日期标准格式 (yyyy-mm-dd)", + "INPUT11": "美国长日期格式 (mm/dd/yyyy)", + "INPUT12": "时间 (hh:mm OR hh:mm:ss) -- 非必要项", + "INPUT13": "字母横杠空格 + 必需 + 最小(5) 字符 -- 必须使用: validation-error-to=' '", + "INPUT14": "字母数字+必需 - 未禁用", + "INPUT15": "密码", + "INPUT16": "确认密码", + "INPUT17": "不同的密码", + "INPUT18": "字母数字+确切(3)+必需 - 减震(3秒)", + "INPUT19": "标准日期格式 (yyyy-mm-dd) -- 最小条件> = 2001-01-01", + "INPUT20": "美国短日期格式 (mm/dd/yy) -- 在12/01/99和12/31/15之间", + "INPUT21": "在这些词中选择(香蕉,橙子,冰淇淋,酸甜)", + "FIRST_NAME": "名字", + "LAST_NAME": "姓", + "RESET_FORM": "重置表", + "SAVE": "保存", + "SELECT1": "必需(选择) - 验证(模糊)事件", + "SHOW_VALIDATION_SUMMARY": "显示验证摘要" +} \ No newline at end of file From 012585ad9ff5e32945188bfddf0a0a0c8e05df66 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Wed, 7 Jun 2017 22:02:38 -0400 Subject: [PATCH 12/34] Merged #157 to add Simplified Chinese locale Thanks to @wbiz for providing Simplified Chinese locale --- bower.json | 2 +- changelog.txt | 1 + dist/angular-validation.js | 4 ++-- dist/angular-validation.min.js | 4 ++-- package.json | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index c18636e..b46da93 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.21", + "version": "1.5.22", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 0a4aea3..91ea023 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.22 (2017-06-07) Merged #157 to add Simplified Chinese locale. 1.5.21 (2017-05-14) Fix #151 validation rule "different" disables rule "required". 1.5.20 (2017-04-20) Add an unminified version and Fix #153 bug in validation service. 1.5.19 (2017-04-17) Fix #150 angularValidation.revalidate problems diff --git a/dist/angular-validation.js b/dist/angular-validation.js index 124ef27..b4c22f8 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -2,9 +2,9 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.21 + * @version: 1.5.22 * @license: MIT - * @build: Sun May 14 2017 23:35:23 GMT-0400 (Eastern Daylight Time) + * @build: Wed Jun 07 2017 22:01:12 GMT-0400 (Eastern Daylight Time) */ /** * Angular-Validation Directive (ghiscoding) diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index 45b6cd1..4310a1f 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,9 +2,9 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.21 + * @version: 1.5.22 * @license: MIT - * @build: Sun May 14 2017 23:35:23 GMT-0400 (Eastern Daylight Time) + * @build: Wed Jun 07 2017 22:01:12 GMT-0400 (Eastern Daylight Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=E(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?Q[o]=s:Q.push(s)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function l(e){return e?A(z,"formName",e):z}function s(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=E(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=E(n,"field",e);if(i>=0&&n.splice(i,1),i=E(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=E(z,"fieldName",e.attr("name"));return u>=0?z[u]=s:z.push(s),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var s=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],l,s),d=M(t.condition[1],l,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,l,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function H(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function I(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=l,X.prototype.getGlobalOptions=s,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); diff --git a/package.json b/package.json index 08ede07..895d399 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.21", + "version": "1.5.22", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": "dist/angular-validation.min", From b6c3799f23228a603046f242e63e256fda3ec2a5 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Wed, 7 Jun 2017 22:07:57 -0400 Subject: [PATCH 13/34] typo --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 58c3ce7..637c08d 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ # Angular Validation (Directive / Service) -`Version: 1.5.21` +`Version: 1.5.22` ### Forms Validation with Angular made easy! ##### (Concept comes from the amazing Laravel) From 6df1c01e19909ec20477d19ff7accf5027667ed9 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 16 Aug 2017 19:19:01 +0200 Subject: [PATCH 14/34] fix reference error The "parentForm" variable is not initialized therefore leads to: ``` ReferenceError: parentForm is not defined ``` --- src/validation-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-common.js b/src/validation-common.js index 8b83b95..d17fd6c 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -816,7 +816,7 @@ angular var formName = (!!formObj) ? formObj.getAttribute("name") : null; if (!!formObj && !!formName) { - parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0) + var parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0) ? objectFindById(self.scope, formName, '.') : self.scope[formName]; From 26281c21aa994161f0f14894e0d53f5b8ef4921e Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 16 Aug 2017 19:46:19 +0200 Subject: [PATCH 15/34] fix Cannot read property 'indexOf' of undefined The `.rules` property could be an empty string in which case the code dies because it uses `self.validatorAttrs.validation` which could be undefined, therefore the `.indexOf` check fails. This fixes TypeError: Cannot read property 'indexOf' of undefined. --- src/validation-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-common.js b/src/validation-common.js index 8b83b95..bb818af 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -178,7 +178,7 @@ angular self = analyzeElementAttributes(self); // get the rules(or validation), inside directive it's named (validation), inside service(rules) - var rules = self.validatorAttrs.rules || self.validatorAttrs.validation; + var rules = self.validatorAttrs.hasOwnProperty('rules') ? self.validatorAttrs.rules : self.validatorAttrs.validation; // We first need to see if the validation holds a custom user regex, if it does then deal with it first // So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe From 68e0e172806c2e6745ebd9b4b9327afcd03cac28 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 16 Aug 2017 19:52:10 +0200 Subject: [PATCH 16/34] even better failsafe --- src/validation-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-common.js b/src/validation-common.js index bb818af..a5d2657 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -178,7 +178,7 @@ angular self = analyzeElementAttributes(self); // get the rules(or validation), inside directive it's named (validation), inside service(rules) - var rules = self.validatorAttrs.hasOwnProperty('rules') ? self.validatorAttrs.rules : self.validatorAttrs.validation; + var rules = self.validatorAttrs.rules || self.validatorAttrs.validation || ''; // We first need to see if the validation holds a custom user regex, if it does then deal with it first // So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe From c7114fc6acfb606eb4049843afbda14ddf95b18b Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Thu, 17 Aug 2017 00:36:41 -0400 Subject: [PATCH 17/34] merged PR #162 and PR #163 --- bower.json | 2 +- dist/angular-validation.js | 8 ++++---- dist/angular-validation.min.js | 6 +++--- package.json | 2 +- protractor/badInput_spec.js | 6 ++---- readme.md | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/bower.json b/bower.json index b46da93..e98e793 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.22", + "version": "1.5.23", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/dist/angular-validation.js b/dist/angular-validation.js index b4c22f8..870a1ae 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -2,9 +2,9 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.22 + * @version: 1.5.23 * @license: MIT - * @build: Wed Jun 07 2017 22:01:12 GMT-0400 (Eastern Daylight Time) + * @build: Thu Aug 17 2017 00:34:56 GMT-0400 (Eastern Daylight Time) */ /** * Angular-Validation Directive (ghiscoding) @@ -617,7 +617,7 @@ angular self = analyzeElementAttributes(self); // get the rules(or validation), inside directive it's named (validation), inside service(rules) - var rules = self.validatorAttrs.rules || self.validatorAttrs.validation; + var rules = self.validatorAttrs.rules || self.validatorAttrs.validation || ''; // We first need to see if the validation holds a custom user regex, if it does then deal with it first // So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe @@ -1255,7 +1255,7 @@ angular var formName = (!!formObj) ? formObj.getAttribute("name") : null; if (!!formObj && !!formName) { - parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0) + var parentForm = (!!_globalOptions && !!_globalOptions.controllerAs && formName.indexOf('.') >= 0) ? objectFindById(self.scope, formName, '.') : self.scope[formName]; diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index 4310a1f..fae0d3d 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.22 + * @version: 1.5.23 * @license: MIT - * @build: Wed Jun 07 2017 22:01:12 GMT-0400 (Eastern Daylight Time) + * @build: Thu Aug 17 2017 00:34:56 GMT-0400 (Eastern Daylight Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); -angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=E(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?Q[o]=s:Q.push(s)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation;if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function l(e){return e?A(z,"formName",e):z}function s(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=E(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=E(n,"field",e);if(i>=0&&n.splice(i,1),i=E(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=E(z,"fieldName",e.attr("name"));return u>=0?z[u]=s:z.push(s),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a],parentForm)?("undefined"==typeof parentForm.$name&&(parentForm.$name=a),parentForm):null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function q(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var s=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=M(t.condition[0],l,s),d=M(t.condition[1],l,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=M(t.condition,l,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function H(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function I(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){q(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=l,X.prototype.getGlobalOptions=s,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); +angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=E(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?Q[o]=s:Q.push(s)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation||"";if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function l(e){return e?A(z,"formName",e):z}function s(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=E(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=E(n,"field",e);if(i>=0&&n.splice(i,1),i=E(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=E(z,"fieldName",e.attr("name"));return u>=0?z[u]=s:z.push(s),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a];if(r)return"undefined"==typeof r.$name&&(r.$name=a),r}return null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function F(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:q(e,o).getTime();if(2==t.params.length){var s=q(t.params[0],o).getTime(),u=q(t.params[1],o).getTime(),p=M(t.condition[0],l,s),d=M(t.condition[1],l,u);r=p&&d}else{var m=q(t.params[0],o).getTime();r=M(t.condition,l,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function H(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function I(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){F(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){F(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=l,X.prototype.getGlobalOptions=s,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return g=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,$=n.validationAttrs.hasOwnProperty("validateOnEmpty")?n.commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);g&&n.commonObj.runValidationCallbackOnPromise(t,g)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a Date: Thu, 17 Aug 2017 00:42:38 -0400 Subject: [PATCH 18/34] update changelog --- changelog.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 91ea023..568afa4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,7 @@ Angular-Validation change logs -1.5.22 (2017-06-07) Merged #157 to add Simplified Chinese locale. +1.5.23 (2017-08-17) Merged PR #162 and #163 +1.5.22 (2017-06-07) Merged PR #157 to add Simplified Chinese locale. 1.5.21 (2017-05-14) Fix #151 validation rule "different" disables rule "required". 1.5.20 (2017-04-20) Add an unminified version and Fix #153 bug in validation service. 1.5.19 (2017-04-17) Fix #150 angularValidation.revalidate problems From 2da692349ffaffca5b66ef7708659f281aa47741 Mon Sep 17 00:00:00 2001 From: Ghislain Beaulac Date: Fri, 1 Sep 2017 23:47:18 -0400 Subject: [PATCH 19/34] fix #160 validate on empty validation-service --- bower.json | 2 +- changelog.txt | 1 + dist/angular-validation.js | 20 ++++++++++---------- dist/angular-validation.min.js | 6 +++--- package.json | 2 +- readme.md | 2 +- src/validation-service.js | 16 ++++++++-------- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/bower.json b/bower.json index e98e793..63c6b85 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.23", + "version": "1.5.24", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 568afa4..18e80be 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.24 (2017-09-01) Fix #160, validate on empty not working in angular-service 1.5.23 (2017-08-17) Merged PR #162 and #163 1.5.22 (2017-06-07) Merged PR #157 to add Simplified Chinese locale. 1.5.21 (2017-05-14) Fix #151 validation rule "different" disables rule "required". diff --git a/dist/angular-validation.js b/dist/angular-validation.js index 870a1ae..f449853 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -2,9 +2,9 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.23 + * @version: 1.5.24 * @license: MIT - * @build: Thu Aug 17 2017 00:34:56 GMT-0400 (Eastern Daylight Time) + * @build: Fri Sep 01 2017 23:43:13 GMT-0400 (Eastern Daylight Time) */ /** * Angular-Validation Directive (ghiscoding) @@ -2842,18 +2842,14 @@ angular attrs.name = attrs.elmName; // user could pass his own scope, useful in a case of an isolate scope - if (!!self.validationAttrs.isolatedScope) { - var tempValidationOptions = scope.$validationOptions || null; // keep global validationOptions - scope = self.validationAttrs.isolatedScope; // rewrite original scope + if (!!self.validationAttrs.isolatedScope || attrs.isolatedScope) { + var tempValidationOptions = scope.$validationOptions || null; // keep global validationOptions + scope = self.validationAttrs.isolatedScope || attrs.isolatedScope; // rewrite original scope if(!!tempValidationOptions) { - scope.$validationOptions = tempValidationOptions; // reuse the validationOption from original scope + scope.$validationOptions = tempValidationOptions; // reuse the validationOption from original scope } } - // Possible element attributes - _validationCallback = (self.validationAttrs.hasOwnProperty('validationCallback')) ? self.validationAttrs.validationCallback : null; - _validateOnEmpty = (self.validationAttrs.hasOwnProperty('validateOnEmpty')) ? self.commonObj.parseBool(self.validationAttrs.validateOnEmpty) : !!_globalOptions.validateOnEmpty; - // onBlur make validation without waiting attrs.elm.bind('blur', _blurHandler = function(event) { // get the form element custom object and use it after @@ -2875,6 +2871,10 @@ angular // so the position inside the mergeObject call is very important attrs = self.commonObj.mergeObjects(self.validationAttrs, attrs); + // Possible element attributes + _validationCallback = (attrs.hasOwnProperty('validationCallback')) ? attrs.validationCallback : null; + _validateOnEmpty = (attrs.hasOwnProperty('validateOnEmpty')) ? self.commonObj.parseBool(attrs.validateOnEmpty) : !!_globalOptions.validateOnEmpty; + // watch the `disabled` attribute for changes // if it become disabled then skip validation else it becomes enable then we need to revalidate it watchNgDisabled(self, scope, attrs); diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index fae0d3d..a314179 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.23 + * @version: 1.5.24 * @license: MIT - * @build: Thu Aug 17 2017 00:34:56 GMT-0400 (Eastern Daylight Time) + * @build: Fri Sep 01 2017 23:43:13 GMT-0400 (Eastern Daylight Time) */ angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=E(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?Q[o]=s:Q.push(s)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation||"";if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function l(e){return e?A(z,"formName",e):z}function s(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=E(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=E(n,"field",e);if(i>=0&&n.splice(i,1),i=E(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=E(z,"fieldName",e.attr("name"));return u>=0?z[u]=s:z.push(s),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a];if(r)return"undefined"==typeof r.$name&&(r.$name=a),r}return null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function F(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:q(e,o).getTime();if(2==t.params.length){var s=q(t.params[0],o).getTime(),u=q(t.params[1],o).getTime(),p=M(t.condition[0],l,s),d=M(t.condition[1],l,u);r=p&&d}else{var m=q(t.params[0],o).getTime();r=M(t.condition,l,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function H(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function I(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){F(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){F(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=l,X.prototype.getGlobalOptions=s,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; -angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope,m&&(l.$validationOptions=m)}return g=n.validationAttrs.hasOwnProperty("validationCallback")?n.validationAttrs.validationCallback:null,$=n.validationAttrs.hasOwnProperty("validateOnEmpty")?n.commonObj.parseBool(n.validationAttrs.validateOnEmpty):!!V.validateOnEmpty,i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);g&&n.commonObj.runValidationCallbackOnPromise(t,g)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a Date: Mon, 29 Oct 2018 12:30:22 -0400 Subject: [PATCH 20/34] add Chinese locale translation "cn.json" --- bower.json | 2 +- changelog.txt | 1 + locales/validation/cn.json | 104 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 locales/validation/cn.json diff --git a/bower.json b/bower.json index 63c6b85..cca1cbd 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.24", + "version": "1.5.25", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 18e80be..fddec95 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.25 (2018-10-29) Add Chinese locale "cn.json" in the locales folder. 1.5.24 (2017-09-01) Fix #160, validate on empty not working in angular-service 1.5.23 (2017-08-17) Merged PR #162 and #163 1.5.22 (2017-06-07) Merged PR #157 to add Simplified Chinese locale. diff --git a/locales/validation/cn.json b/locales/validation/cn.json new file mode 100644 index 0000000..0833f9d --- /dev/null +++ b/locales/validation/cn.json @@ -0,0 +1,104 @@ +{ + "INVALID_ACCEPTED": "必须接受", + "INVALID_ALPHA":"只能带字母", + "INVALID_ALPHA_SPACE":"只能帶字母或空格", + "INVALID_ALPHA_NUM":"只能帶字母或数字", + "INVALID_ALPHA_NUM_SPACE":"只能带字母或数字或空格", + "INVALID_ALPHA_DASH":"只能带字母或数字或破折号", + "INVALID_ALPHA_DASH_SPACE":"只能带字母或数字或空格或破折号", + "INVALID_BETWEEN_CHAR":"文本必须介于{0}和{1}之间", + "INVALID_BETWEEN_NUM":"需要一个数值在{0}和{1}之间", + "INVALID_BOOLEAN":"只能带真值或假值", + "INVALID_CREDIT_CARD":"必须是有效的信用卡号码", + "INVALID_DATE_EURO":"必须是一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy)", + "INVALID_DATE_EURO_BETWEEN":"需要一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy)在{0}和{1}之间", + "INVALID_DATE_EURO_MAX":"需要一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy),等于或低于{0}", + "INVALID_DATE_EURO_MIN":"需要一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy),等于或高于{0}", + "INVALID_DATE_EURO_LONG":"必须是一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy)", + "INVALID_DATE_EURO_LONG_BETWEEN":"需要一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy)在{0}和{1}之间", + "INVALID_DATE_EURO_LONG_MAX":"需要一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy),等于或低于{0}", + "INVALID_DATE_EURO_LONG_MIN":"需要一个有效的日期格式(dd-mm-yyyy)或(dd/mm/yyyy),等于或高于{0}", + "INVALID_DATE_EURO_SHORT":"必须是一个有效的日期格式(dd-mm-yy)或(dd/mm/yy)", + "INVALID_DATE_EURO_SHORT_BETWEEN":"需要一个有效的日期格式(dd-mm-yy)或(dd/mm/yy)在{0}和{1}之间", + "INVALID_DATE_EURO_SHORT_MAX":"需要一个有效的日期格式(dd-mm-yy)或(dd/mm/yy),等于或低于{0}", + "INVALID_DATE_EURO_SHORT_MIN":"需要一个有效的日期格式(dd-mm-yy)或(dd/mm/yy),等于或高于{0}", + "INVALID_DATE_ISO":"必须是一个有效的日期格式(yyyy-mm-dd)", + "INVALID_DATE_ISO_BETWEEN":"需要一个有效的日期格式(yyyy-mm-dd)在{0}和{1}之间", + "INVALID_DATE_ISO_MAX":"需要一个有效的日期格式(yyyy-mm-dd),等于或低于{0}", + "INVALID_DATE_ISO_MIN":"需要一个有效的日期格式(yyyy-mm-dd),等于或高于{0}", + "INVALID_DATE_US":"必须是一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy)", + "INVALID_DATE_US_BETWEEN":"需要一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy)在{0}和{1}之间", + "INVALID_DATE_US_MAX":"需要一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy),等于或低于{0}", + "INVALID_DATE_US_MIN":"需要一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy),等于或高于{0}", + "INVALID_DATE_US_LONG":"必须是一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy)", + "INVALID_DATE_US_LONG_BETWEEN":"需要一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy)在{0}和{1}之间", + "INVALID_DATE_US_LONG_MAX":"需要一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy),等于或低于{0}", + "INVALID_DATE_US_LONG_MIN":"需要一个有效的日期格式(mm/dd/yyyy)或(mm-dd-yyyy),等于或高于{0}", + "INVALID_DATE_US_SHORT":"必须是一个有效的日期格式(mm/dd/yy)或(mm-dd-yy)", + "INVALID_DATE_US_SHORT_BETWEEN":"需要一个有效的日期格式(mm/dd/yy)或(mm-dd-yy)在{0}和{1}之间", + "INVALID_DATE_US_SHORT_MAX":"需要一个有效的日期格式(mm/dd/yy)或(mm-dd-yy),等于或低于{0}", + "INVALID_DATE_US_SHORT_MIN":"需要一个有效的日期格式(mm/dd/yy)或(mm-dd-yy),等于或高于{0}", + "INVALID_DIGITS":"数字必须是{0}", + "INVALID_DIGITS_BETWEEN":"数字必须介于{0}和{1}之间", + "INVALID_EMAIL":"必须是有效的电子邮件地址", + "INVALID_EXACT_LEN":"必须具有确切的字符{0}", + "INVALID_EXACT_NUM":"必须是{0}", + "INVALID_FLOAT":"只能带正浮点值(integer excluded)", + "INVALID_FLOAT_SIGNED":"只能带正或负浮点值(integer excluded)", + "INVALID_IBAN":"必须是一个有效的日期", + "INVALID_IN_LIST":"必须是此列表内的选择:({0})", + "INVALID_INPUT_DIFFERENT":"字段必须与指定字段不同[{1}]", + "INVALID_INPUT_MATCH":"确认字段与指定字段不匹配[{1}]", + "INVALID_INTEGER":"必须是正整数", + "INVALID_INTEGER_SIGNED":"必须是正整数或负整数", + "INVALID_IPV4":"必须是一个有效的IP (IPV4)", + "INVALID_IPV6":"必须是一个有效的IP (IPV6)", + "INVALID_IPV6_HEX":"必须是一个有效的IP (IPV6 Hex)", + "INVALID_KEY_CHAR":"“数字”字段上的键盘输入无效", + "INVALID_MAX_CHAR":"字符可能不大于{0}", + "INVALID_MAX_NUM":"数值需要等于或低于{0}", + "INVALID_MIN_CHAR":"字符必须至少{0}", + "INVALID_MIN_NUM":"数值需要等于或高于{0}", + "INVALID_NOT_IN_LIST":"必须是此列表之外的选择:({0})", + "INVALID_NUMERIC":"必须是正数", + "INVALID_NUMERIC_SIGNED":"必须是正数或负数", + "INVALID_PATTERN":"必须遵循以下格式:{0}", + "INVALID_PATTERN_DATA":"必须遵循此格式{{data}}", + "INVALID_PHONE_US":"必须是有效的电话号码,包括区号", + "INVALID_PHONE_INTERNATIONAL":"必须是有效的国际电话号码", + "INVALID_REQUIRED":"字段是必需的", + "INVALID_URL":"必须是有效网址", + "INVALID_TIME":"必须是一个有效的时间格式 (hh:mm) 或 (hh:mm:ss)", + "INVALID_CHECKBOX_SELECTED":"复选框必须选择", + "AREA1":"文本:数字+最小(15)+要求", + "ERRORS":"错误", + "CHANGE_LANGUAGE":"改变语言", + "FORM_PREVALIDATED":"表单预验证", + "INPUT1":"远程验证-键入一个有效答案的ABC", + "INPUT2":"数正的或负的输入类型=’数字’—非数字字符上的错误", + "INPUT3":"Floating number range (integer excluded) -- between_num:x,y OR min_num:x|max_num:y ", + "INPUT4":"多重验证+自定义正则表达式日期代码(yyww)", + "INPUT5":"电子邮件", + "INPUT6":"统一资源定位地址", + "INPUT7":"IP (IPV4)", + "INPUT8":"信用卡", + "INPUT9":"在(2,6)之间", + "INPUT10":"日期等 (yyyy-mm-dd)", + "INPUT11":"请用详细美式日期 (mm/dd/yyyy)", + "INPUT12":"时间(hh:mm OR hh:mm:ss)--不需要", + "INPUT13":"AlphaDashSpaces + Required + Minimum(5) Characters -- MUST USE: validation-error-to=' '", + "INPUT14":"Alphanumeric + Required -- NG-DISABLED", + "INPUT15":"密码", + "INPUT16":"密码确认", + "INPUT17":"不同的密码", + "INPUT18":"(3)+数字+完全需要消抖(3sec)", + "INPUT19":"日期等(yyyy-mm-dd)--最小条件> = 2001-01-01", + "INPUT20":"请用简短美式日期 (mm/dd/yy) --日期12/01/99和12/31/15之间", + "INPUT21":"在这个列表中选择(banana,orange,ice cream,sweet & sour)", + "FIRST_NAME":"名字", + "LAST_NAME":"姓", + "RESET_FORM":"复位形式", + "SAVE":"保存", + "SELECT1":"要求(select)-验证与(blur)事件", + "SHOW_VALIDATION_SUMMARY":"显示验证总结" +} \ No newline at end of file diff --git a/package.json b/package.json index 43f424b..23ca587 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.24", + "version": "1.5.25", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": "dist/angular-validation.min", From 35e30417d0e51a8fda319865bff27560e360a9bc Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 30 Oct 2018 19:33:39 -0400 Subject: [PATCH 21/34] add life-support comment in readme --- readme.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cea1a9a..20e39ef 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,21 @@ # Angular Validation (Directive / Service) -`Version: 1.5.24` +`Version: 1.5.25` + +## Project in Life Support +##### still accepting PR for any bug fix + +This project is now in Life Support since most of us already moved to newer version of Angular. However I do want to point out that if you still use the lib and find a Bug, I certainly still welcome PR (Pull Request) to address bug fixes. So I'm not totally gone but I won't personally invest more time in the lib. Also note that the lib will not be rewritten to support Angular 2+ + +On a totally different note, I'm still very active in the Angular 4+ world (even Aurelia world) and you might be interested in looking at some of my other libraries. +- [Angular-Slickgrid](https://github.com/ghiscoding/Angular-Slickgrid) +- [Angular Markdown Preview Editor](https://github.com/ghiscoding/angular-markdown-editor) + +In the Aurelia world +- [Aurelia-Slickgrid](https://github.com/ghiscoding/aurelia-slickgrid) +- [Aurelia Bootstrap Plugin](https://github.com/ghiscoding/Aurelia-Bootstrap-Plugins) + +--- + ### Forms Validation with Angular made easy! ##### (Concept comes from the amazing Laravel) From 7291142cd0d079b28658e3d6e87ef7332dc4a253 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 30 Oct 2018 19:34:21 -0400 Subject: [PATCH 22/34] update life-support comment --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 20e39ef..125932c 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ `Version: 1.5.25` ## Project in Life Support -##### still accepting PR for any bug fix +### still accepting PR for any bug fix This project is now in Life Support since most of us already moved to newer version of Angular. However I do want to point out that if you still use the lib and find a Bug, I certainly still welcome PR (Pull Request) to address bug fixes. So I'm not totally gone but I won't personally invest more time in the lib. Also note that the lib will not be rewritten to support Angular 2+ From 1f455c81dfaf1594b0e57ce8191a0da416319f65 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 30 Oct 2018 19:35:14 -0400 Subject: [PATCH 23/34] update life-support comment --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 125932c..b0c0846 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ `Version: 1.5.25` ## Project in Life Support -### still accepting PR for any bug fix +#### still accepting PR for any bug fix This project is now in Life Support since most of us already moved to newer version of Angular. However I do want to point out that if you still use the lib and find a Bug, I certainly still welcome PR (Pull Request) to address bug fixes. So I'm not totally gone but I won't personally invest more time in the lib. Also note that the lib will not be rewritten to support Angular 2+ From b20b8f2f213e6f39f0f3eafe3e22df902f3db70a Mon Sep 17 00:00:00 2001 From: mgm09a Date: Fri, 9 Nov 2018 11:09:54 -0600 Subject: [PATCH 24/34] Fix for incorrect validation on "required" with a value of 0 Fixes issue #177 --- src/validation-directive.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/validation-directive.js b/src/validation-directive.js index 3bd2dcc..e471632 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -179,7 +179,7 @@ } // invalidate field before doing any validation - if(!!value || commonObj.isFieldRequired() || _validateOnEmpty) { + if((value === "" || value === null || typeof value === "undefined") || commonObj.isFieldRequired() || _validateOnEmpty) { ctrl.$setValidity('validation', false); } @@ -403,7 +403,9 @@ /** Re-evaluate the element and revalidate it, also re-attach the onBlur event on the element */ function revalidateAndAttachOnBlur() { // Revalidate the input when enabled (without displaying the error) - var value = ctrl.$modelValue || ''; + var value = ctrl.$modelValue !== null && typeof ctrl.$modelValue !== 'undefined' + ? ctrl.$modelValue + : ''; if(!Array.isArray(value)) { ctrl.$setValidity('validation', commonObj.validate(value, false)); } From b249f4ae4b9bb91b3231f9a07a4aad5642100fdb Mon Sep 17 00:00:00 2001 From: mgm09a Date: Fri, 9 Nov 2018 11:13:42 -0600 Subject: [PATCH 25/34] Update src/validation-directive.js --- src/validation-directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-directive.js b/src/validation-directive.js index e471632..a6f6799 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -179,7 +179,7 @@ } // invalidate field before doing any validation - if((value === "" || value === null || typeof value === "undefined") || commonObj.isFieldRequired() || _validateOnEmpty) { + if((value !== "" || value !== null || typeof value !== "undefined") || commonObj.isFieldRequired() || _validateOnEmpty) { ctrl.$setValidity('validation', false); } From 134acccf6891a5e37d019bcced3b8a31f2432be9 Mon Sep 17 00:00:00 2001 From: mgm09a Date: Mon, 12 Nov 2018 08:56:35 -0600 Subject: [PATCH 26/34] Update src/validation-directive.js Fix to properly negate expression. --- src/validation-directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-directive.js b/src/validation-directive.js index a6f6799..49fe9b4 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -179,7 +179,7 @@ } // invalidate field before doing any validation - if((value !== "" || value !== null || typeof value !== "undefined") || commonObj.isFieldRequired() || _validateOnEmpty) { + if((value !== "" && value !== null && typeof value !== "undefined") || commonObj.isFieldRequired() || _validateOnEmpty) { ctrl.$setValidity('validation', false); } From cc44b278bf1baba42ff88813c6230bd65d51b2ab Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Tue, 13 Nov 2018 23:26:19 -0500 Subject: [PATCH 27/34] bump version after merge of PR #178 --- .gitignore | 3 +++ .npmignore | 1 + bower.json | 2 +- changelog.txt | 1 + package.json | 2 +- readme.md | 4 ++-- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 06ab436..3ecc873 100644 --- a/.gitignore +++ b/.gitignore @@ -222,5 +222,8 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +# Lock files +package-lock.json yarn-error.log yarn.lock \ No newline at end of file diff --git a/.npmignore b/.npmignore index 9a1941d..124e1e6 100644 --- a/.npmignore +++ b/.npmignore @@ -7,5 +7,6 @@ templates/ app.js gulpfile.js index.html +package-lock.json yarn-error.log yarn.lock \ No newline at end of file diff --git a/bower.json b/bower.json index cca1cbd..c2fb16c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.25", + "version": "1.5.26", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index fddec95..428a65a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.26 (2018-11-13) Merged PR #178 to fix revalidateAndAttachOnBlur method to handle zeroes appropriately 1.5.25 (2018-10-29) Add Chinese locale "cn.json" in the locales folder. 1.5.24 (2017-09-01) Fix #160, validate on empty not working in angular-service 1.5.23 (2017-08-17) Merged PR #162 and #163 diff --git a/package.json b/package.json index 23ca587..7d629e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.25", + "version": "1.5.26", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": "dist/angular-validation.min", diff --git a/readme.md b/readme.md index b0c0846..b5ae5a9 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ # Angular Validation (Directive / Service) -`Version: 1.5.25` +`Version: 1.5.26` ## Project in Life Support #### still accepting PR for any bug fix @@ -7,7 +7,7 @@ This project is now in Life Support since most of us already moved to newer version of Angular. However I do want to point out that if you still use the lib and find a Bug, I certainly still welcome PR (Pull Request) to address bug fixes. So I'm not totally gone but I won't personally invest more time in the lib. Also note that the lib will not be rewritten to support Angular 2+ On a totally different note, I'm still very active in the Angular 4+ world (even Aurelia world) and you might be interested in looking at some of my other libraries. -- [Angular-Slickgrid](https://github.com/ghiscoding/Angular-Slickgrid) +- [Angular-Slickgrid](https://github.com/ghiscoding/Angular-Slickgrid) - [Angular Markdown Preview Editor](https://github.com/ghiscoding/angular-markdown-editor) In the Aurelia world From 5f629e16c1f988d566348ff80b4725f083a0bca6 Mon Sep 17 00:00:00 2001 From: PrashantP25 <49611236+PrashantP25@users.noreply.github.com> Date: Sun, 14 Apr 2019 18:38:52 +0530 Subject: [PATCH 28/34] Update validation-service.js file resolved radio button required field validation when validation are added via addValidator method --- src/validation-service.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/validation-service.js b/src/validation-service.js index d4cb8f0..fa1464f 100644 --- a/src/validation-service.js +++ b/src/validation-service.js @@ -106,7 +106,7 @@ angular self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(self, event.target.value, 0); + var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 0); if(!!_validationCallback) { self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); } @@ -574,7 +574,7 @@ angular attrs.elm.bind('blur', _blurHandler = function(event) { if (!!formElmObj && !formElmObj.isValidationCancelled) { // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(self, event.target.value, 10); + var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 10); if(!!_validationCallback) { self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); } @@ -596,4 +596,4 @@ angular }); } -}]); // ValidationService \ No newline at end of file +}]); // ValidationService From f8143cbb6186454eae254a1a435438165954bd8c Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Sun, 14 Apr 2019 21:24:46 -0400 Subject: [PATCH 29/34] fix indentation from last PR --- src/validation-service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validation-service.js b/src/validation-service.js index fa1464f..5769eb5 100644 --- a/src/validation-service.js +++ b/src/validation-service.js @@ -106,7 +106,7 @@ angular self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 0); + var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 0); if(!!_validationCallback) { self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); } @@ -574,7 +574,7 @@ angular attrs.elm.bind('blur', _blurHandler = function(event) { if (!!formElmObj && !formElmObj.isValidationCancelled) { // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 10); + var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 10); if(!!_validationCallback) { self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); } From 3ca263b3d05c2d62e3ed53c2d2c1ee12c0442d6e Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Sun, 14 Apr 2019 21:27:23 -0400 Subject: [PATCH 30/34] prepare release 1.5.27 --- bower.json | 2 +- changelog.txt | 1 + package.json | 2 +- readme.md | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index c2fb16c..5e3519a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.26", + "version": "1.5.27", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 428a65a..399cecd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.27 (2019-04-14) Merged PR #182 to fix Radio button required field validation not working, closes #181 1.5.26 (2018-11-13) Merged PR #178 to fix revalidateAndAttachOnBlur method to handle zeroes appropriately 1.5.25 (2018-10-29) Add Chinese locale "cn.json" in the locales folder. 1.5.24 (2017-09-01) Fix #160, validate on empty not working in angular-service diff --git a/package.json b/package.json index 7d629e9..785536f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.26", + "version": "1.5.27", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": "dist/angular-validation.min", diff --git a/readme.md b/readme.md index b5ae5a9..83be87e 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ # Angular Validation (Directive / Service) -`Version: 1.5.26` +`Version: 1.5.27` ## Project in Life Support #### still accepting PR for any bug fix From 07fa6bf8c4128e52ccaa4337749c5da412e14424 Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Sun, 14 Apr 2019 21:33:32 -0400 Subject: [PATCH 31/34] update readme --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 83be87e..990e932 100644 --- a/readme.md +++ b/readme.md @@ -3,6 +3,7 @@ ## Project in Life Support #### still accepting PR for any bug fix +**Also note that only NPM will updated with new releases when PR get merged** This project is now in Life Support since most of us already moved to newer version of Angular. However I do want to point out that if you still use the lib and find a Bug, I certainly still welcome PR (Pull Request) to address bug fixes. So I'm not totally gone but I won't personally invest more time in the lib. Also note that the lib will not be rewritten to support Angular 2+ From c884bc4030cd923aca60bc42bbfdbd863b9920a8 Mon Sep 17 00:00:00 2001 From: PrashantP25 <49611236+PrashantP25@users.noreply.github.com> Date: Sat, 8 Jun 2019 14:47:24 +0530 Subject: [PATCH 32/34] Update validation-common.js file Update validation-common.js file to add method to remove item from array when values of and object matches --- src/validation-common.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/validation-common.js b/src/validation-common.js index f82ba84..ef55de0 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -66,6 +66,7 @@ angular // list of available published public functions of this object validationCommon.prototype.addToValidationSummary = addToValidationSummary; // add an element to the $validationSummary validationCommon.prototype.arrayFindObject = arrayFindObject; // search an object inside an array of objects + validationCommon.prototype.arrayRemoveObject = arrayRemoveObject; // search an object inside an array of objects and remove it from array validationCommon.prototype.defineValidation = defineValidation; // define our validation object validationCommon.prototype.getFormElementByName = getFormElementByName; // get the form element custom object by it's name validationCommon.prototype.getFormElements = getFormElements; // get the array of form elements (custom objects) @@ -771,6 +772,25 @@ angular return null; } + /** Quick function to remove an object inside an array by it's given field name and value, return and remove the object found or null + * @param Array sourceArray + * @param string searchId: search property id + * @param string searchValue: value to search + * @return object found from source array or null + */ + function arrayRemoveObject(sourceArray, searchId, searchValue) { + if (!!sourceArray) { + for (var i = 0; i < sourceArray.length; i++) { + if (sourceArray[i][searchId] === searchValue) { + var itemToRemove = sourceArray[i]; + sourceArray.splice(i,1); + return itemToRemove; + } + } + } + return null; + } + /** Quick function to find all object(s) inside an array of objects by it's given field name and value, return array of object found(s) or empty array * @param Array sourceArray * @param string searchId: search property id From 8380c0efb3cbfb264ed9e163b846df335649b2e2 Mon Sep 17 00:00:00 2001 From: PrashantP25 <49611236+PrashantP25@users.noreply.github.com> Date: Sat, 8 Jun 2019 14:52:52 +0530 Subject: [PATCH 33/34] Changes done in 2 methods in validation-service.js changes done in attemptToValidate (line number 339) method and removeWatcherAndErrorMessage (line number 494) method --- src/validation-service.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/validation-service.js b/src/validation-service.js index 5769eb5..7ce53a8 100644 --- a/src/validation-service.js +++ b/src/validation-service.js @@ -334,9 +334,12 @@ angular // pre-validate without any events just to pre-fill our validationSummary with all field errors // passing false as 2nd argument for not showing any errors on screen self.commonObj.validate(value, false); - + + // check field level setting for validateOnEmpty + var isFieldValidateOnEmpty = (self.commonObj.validatorAttrs && self.commonObj.validatorAttrs.validateOnEmpty); + // if field is not required and his value is empty, cancel validation and exit out - if(!self.commonObj.isFieldRequired() && !_validateOnEmpty && (value === "" || value === null || typeof value === "undefined")) { + if(!self.commonObj.isFieldRequired() && !(_validateOnEmpty || isFieldValidateOnEmpty) && (value === "" || value === null || typeof value === "undefined")) { cancelValidation(self, formElmObj); deferred.resolve({ isFieldValid: true, formElmObj: formElmObj, value: value }); return deferred.promise; @@ -491,7 +494,7 @@ angular var foundWatcher = self.commonObj.arrayFindObject(_watchers, 'elmName', formElmObj.fieldName); if(!!foundWatcher) { foundWatcher.watcherHandler(); // deregister the watch by calling his handler - _watchers.shift(); + self.commonObj.arrayRemoveObject(_watchers, 'elmName', formElmObj.fieldName); } // make the validation cancelled so it won't get called anymore in the blur eventHandler From 3a1c83aac30ccb2f3631c9bf131c63223a82443d Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Thu, 20 Jun 2019 21:20:36 -0400 Subject: [PATCH 34/34] prepare release 1.5.28 --- bower.json | 2 +- changelog.txt | 1 + dist/angular-validation.js | 45 ++++++++++++++++++++++++++-------- dist/angular-validation.min.js | 10 ++++---- package.json | 2 +- readme.md | 2 +- 6 files changed, 44 insertions(+), 18 deletions(-) diff --git a/bower.json b/bower.json index 5e3519a..2a95ccc 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-validation-ghiscoding", - "version": "1.5.27", + "version": "1.5.28", "author": "Ghislain B.", "description": "Angular-Validation Directive and Service (ghiscoding)", "main": [ diff --git a/changelog.txt b/changelog.txt index 399cecd..4bc5352 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ Angular-Validation change logs +1.5.28 (2019-06-20) Merged PR #183, #184 fixes #185 Issue while de-registering a watcher and field level validateOnEmpty 1.5.27 (2019-04-14) Merged PR #182 to fix Radio button required field validation not working, closes #181 1.5.26 (2018-11-13) Merged PR #178 to fix revalidateAndAttachOnBlur method to handle zeroes appropriately 1.5.25 (2018-10-29) Add Chinese locale "cn.json" in the locales folder. diff --git a/dist/angular-validation.js b/dist/angular-validation.js index f449853..b9139bc 100644 --- a/dist/angular-validation.js +++ b/dist/angular-validation.js @@ -2,9 +2,9 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.24 + * @version: 1.5.28 * @license: MIT - * @build: Fri Sep 01 2017 23:43:13 GMT-0400 (Eastern Daylight Time) + * @build: Thu Jun 20 2019 21:18:15 GMT-0400 (Eastern Daylight Time) */ /** * Angular-Validation Directive (ghiscoding) @@ -187,7 +187,7 @@ } // invalidate field before doing any validation - if(!!value || commonObj.isFieldRequired() || _validateOnEmpty) { + if((value !== "" && value !== null && typeof value !== "undefined") || commonObj.isFieldRequired() || _validateOnEmpty) { ctrl.$setValidity('validation', false); } @@ -411,7 +411,9 @@ /** Re-evaluate the element and revalidate it, also re-attach the onBlur event on the element */ function revalidateAndAttachOnBlur() { // Revalidate the input when enabled (without displaying the error) - var value = ctrl.$modelValue || ''; + var value = ctrl.$modelValue !== null && typeof ctrl.$modelValue !== 'undefined' + ? ctrl.$modelValue + : ''; if(!Array.isArray(value)) { ctrl.$setValidity('validation', commonObj.validate(value, false)); } @@ -505,6 +507,7 @@ angular // list of available published public functions of this object validationCommon.prototype.addToValidationSummary = addToValidationSummary; // add an element to the $validationSummary validationCommon.prototype.arrayFindObject = arrayFindObject; // search an object inside an array of objects + validationCommon.prototype.arrayRemoveObject = arrayRemoveObject; // search an object inside an array of objects and remove it from array validationCommon.prototype.defineValidation = defineValidation; // define our validation object validationCommon.prototype.getFormElementByName = getFormElementByName; // get the form element custom object by it's name validationCommon.prototype.getFormElements = getFormElements; // get the array of form elements (custom objects) @@ -1210,6 +1213,25 @@ angular return null; } + /** Quick function to remove an object inside an array by it's given field name and value, return and remove the object found or null + * @param Array sourceArray + * @param string searchId: search property id + * @param string searchValue: value to search + * @return object found from source array or null + */ + function arrayRemoveObject(sourceArray, searchId, searchValue) { + if (!!sourceArray) { + for (var i = 0; i < sourceArray.length; i++) { + if (sourceArray[i][searchId] === searchValue) { + var itemToRemove = sourceArray[i]; + sourceArray.splice(i,1); + return itemToRemove; + } + } + } + return null; + } + /** Quick function to find all object(s) inside an array of objects by it's given field name and value, return array of object found(s) or empty array * @param Array sourceArray * @param string searchId: search property id @@ -2860,7 +2882,7 @@ angular self.commonObj.initialize(scope, attrs.elm, attrs, attrs.ctrl); // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(self, event.target.value, 0); + var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 0); if(!!_validationCallback) { self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); } @@ -3088,9 +3110,12 @@ angular // pre-validate without any events just to pre-fill our validationSummary with all field errors // passing false as 2nd argument for not showing any errors on screen self.commonObj.validate(value, false); - + + // check field level setting for validateOnEmpty + var isFieldValidateOnEmpty = (self.commonObj.validatorAttrs && self.commonObj.validatorAttrs.validateOnEmpty); + // if field is not required and his value is empty, cancel validation and exit out - if(!self.commonObj.isFieldRequired() && !_validateOnEmpty && (value === "" || value === null || typeof value === "undefined")) { + if(!self.commonObj.isFieldRequired() && !(_validateOnEmpty || isFieldValidateOnEmpty) && (value === "" || value === null || typeof value === "undefined")) { cancelValidation(self, formElmObj); deferred.resolve({ isFieldValid: true, formElmObj: formElmObj, value: value }); return deferred.promise; @@ -3245,7 +3270,7 @@ angular var foundWatcher = self.commonObj.arrayFindObject(_watchers, 'elmName', formElmObj.fieldName); if(!!foundWatcher) { foundWatcher.watcherHandler(); // deregister the watch by calling his handler - _watchers.shift(); + self.commonObj.arrayRemoveObject(_watchers, 'elmName', formElmObj.fieldName); } // make the validation cancelled so it won't get called anymore in the blur eventHandler @@ -3328,7 +3353,7 @@ angular attrs.elm.bind('blur', _blurHandler = function(event) { if (!!formElmObj && !formElmObj.isValidationCancelled) { // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(self, event.target.value, 10); + var validationPromise = attemptToValidate(self, (attrs.ctrl.$modelValue == undefined ? '' : attrs.ctrl.$modelValue), 10); if(!!_validationCallback) { self.commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); } @@ -3350,4 +3375,4 @@ angular }); } -}]); // ValidationService \ No newline at end of file +}]); // ValidationService diff --git a/dist/angular-validation.min.js b/dist/angular-validation.min.js index a314179..7d230ae 100644 --- a/dist/angular-validation.min.js +++ b/dist/angular-validation.min.js @@ -2,11 +2,11 @@ * Angular-Validation Directive and Service (ghiscoding) * http://github.com/ghiscoding/angular-validation * @author: Ghislain B. - * @version: 1.5.24 + * @version: 1.5.28 * @license: MIT - * @build: Fri Sep 01 2017 23:43:13 GMT-0400 (Eastern Daylight Time) + * @build: Thu Jun 20 2019 21:18:15 GMT-0400 (Eastern Daylight Time) */ -angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=l.$modelValue||"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); -angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=R(n,e),o=E(Q,"field",n);if(o>=0&&""===t)Q.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?Q[o]=s:Q.push(s)}if(e.scope.$validationSummary=Q,i&&(i.$validationSummary=A(Q,"formName",i.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=K.controllerAs&&K.controllerAs[u]?K.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=A(Q,"formName",i.$name))}return Q}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation||"";if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(z,"fieldName",e)}function l(e){return e?A(z,"formName",e):z}function s(){return K}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=E(z,"fieldName",e);t>=0&&z.splice(t,1)}function c(e,t){var a=this,r=R(e,a),n=t||Q,i=E(n,"field",e);if(i>=0&&n.splice(i,1),i=E(Q,"field",e),i>=0&&Q.splice(i,1),a.scope.$validationSummary=Q,r&&(r.$validationSummary=A(Q,"formName",r.$name)),K&&K.controllerAs&&(K.controllerAs.$validationSummary=Q,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;K.controllerAs[o]&&(K.controllerAs[o].$validationSummary=A(Q,"formName",r.$name))}return Q}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=N(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){K.displayOnlyLastErrorMsg=e}function y(e){var t=this;return K=d(K,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!K.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&K.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=R(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=E(z,"fieldName",e.attr("name"));return u>=0?z[u]=s:z.push(s),z}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(K.preValidateValidationSummary||"undefined"==typeof K.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||K.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=J,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):K&&K.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(K.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:K.validRequireHowMany,W=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?T(e.validatorAttrs.validateOnEmpty):K.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?N(t.scope,a,"."):t.scope[a];if(r)return"undefined"==typeof r.$name&&(r.$name=a),r}return null}function R(e,t){if(K&&K.formName){var a=document.querySelector('[name="'+K.formName+'"]');if(a)return a.$name=K.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function x(e){return!isNaN(parseFloat(e))&&isFinite(e)}function N(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=k(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=k(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function F(e){e&&(K={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},z=[],Q=[])}function k(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function M(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function C(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function L(){return this.replace(/^\s+|\s+$/g,"")}function U(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function j(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:q(e,o).getTime();if(2==t.params.length){var s=q(t.params[0],o).getTime(),u=q(t.params[1],o).getTime(),p=M(t.condition[0],l,s),d=M(t.condition[1],l,u);r=p&&d}else{var m=q(t.params[0],o).getTime();r=M(t.condition,l,m)}}return r}function G(e,t){var a=!0;if(2==t.params.length){var r=M(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=M(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=M(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function D(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||W){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function H(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(M(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=K.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function I(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||W){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Y.length>1)for(;Y.length>0;){var d=Y.pop();d&&"function"==typeof d.abort&&d.abort()}if(Y.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Y.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function B(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function _(e,t){return x(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var J=1e3,z=[],K={resetGlobalOptionsOnRouteChange:!0},Y=[],Q=[],W=!1;e.$on("$routeChangeStart",function(e,t,a){F(K.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){F(K.resetGlobalOptionsOnRouteChange)});var X=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=J,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(K=e.$validationOptions),e&&(K.isolatedScope||K.scope)&&(this.scope=K.isolatedScope||K.scope,K=d(e.$validationOptions,K)),"undefined"==typeof K.resetGlobalOptionsOnRouteChange&&(K.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return X.prototype.addToValidationSummary=n,X.prototype.arrayFindObject=w,X.prototype.defineValidation=i,X.prototype.getFormElementByName=o,X.prototype.getFormElements=l,X.prototype.getGlobalOptions=s,X.prototype.isFieldRequired=p,X.prototype.initialize=u,X.prototype.mergeObjects=d,X.prototype.parseBool=T,X.prototype.removeFromValidationSummary=c,X.prototype.removeFromFormElementObjectList=m,X.prototype.runValidationCallbackOnPromise=g,X.prototype.setDisplayOnlyLastErrorMsg=v,X.prototype.setGlobalOptions=y,X.prototype.updateErrorMsg=h,X.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=C),String.prototype.trim=L,String.prototype.format=U,String.format=P,X}]); +angular.module("ghiscoding.validation",["pascalprecht.translate"]).directive("validation",["$q","$timeout","ValidationCommon",function(a,e,i){return{restrict:"A",require:"ngModel",link:function(n,t,r,l){function o(i,r){var o=a.defer(),d=!1,m="undefined"!=typeof r?r:$.typingLimit,s=$.getFormElementByName(l.$name);if(Array.isArray(i)){if(O=[],h="",m=0,i.length>0)return"function"==typeof s.ctrl.$setTouched&&s.ctrl.$setTouched(),u(i,typeof i);m=0}return i&&i.badInput?c():($.validate(i,!1),$.isFieldRequired()||F||""!==i&&null!==i&&"undefined"!=typeof i?(s&&(s.isValidationCancelled=!1),(""!==i&&null!==i&&"undefined"!=typeof i||$.isFieldRequired()||F)&&l.$setValidity("validation",!1),"SELECT"===t.prop("tagName").toUpperCase()?(d=$.validate(i,!0),l.$setValidity("validation",d),o.resolve({isFieldValid:d,formElmObj:s,value:i}),o.promise):("undefined"!=typeof i&&(0===r?(d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i}),e.cancel(b)):($.updateErrorMsg(""),e.cancel(b),b=e(function(){d=$.validate(i,!0),n.$evalAsync(l.$setValidity("validation",d)),o.resolve({isFieldValid:d,formElmObj:s,value:i})},m))),o.promise)):(f(),o.resolve({isFieldValid:!0,formElmObj:s,value:i}),o.promise))}function d(a,e,i){var n=o(a,0);n&&"function"==typeof n.then&&(O.push(n),parseInt(e)===i-1&&O.forEach(function(a){a.then(function(a){switch(A){case"all":a.isFieldValid===!1&&a.formElmObj.translatePromise.then(function(e){h.length>0&&g.displayOnlyLastErrorMsg?h="["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e):h+=" ["+a.value+"] :: "+(a.formElmObj.validator&&a.formElmObj.validator.params?String.format(e,a.formElmObj.validator.params):e),$.updateErrorMsg(h,{isValid:!1}),$.addToValidationSummary(a.formElmObj,h)});break;case"one":default:a.isFieldValid===!0&&(l.$setValidity("validation",!0),f())}})}))}function m(a){var e=$.getFormElementByName(l.$name),i="undefined"!=typeof l.$modelValue?l.$modelValue:a.target.value;if(e&&e.hasOwnProperty("isValidationCancelled")){var n=o(i,0);w&&$.runValidationCallbackOnPromise(n,w)}else l.$setValidity("validation",!0)}function u(a,e){var i=a.length;if("string"===e)for(var n in a)d(a[n],n,i);else if("object"===e)for(var n in a)if(a.hasOwnProperty(n)){var t=a[n];for(var r in t)if(t.hasOwnProperty(r)){if(C&&r!==C)continue;d(t[r],n,i)}}}function s(){f(),$.removeFromValidationSummary(j);var a=$.arrayFindObject(E,"elmName",l.$name);if(a&&"function"==typeof a.watcherHandler){a.watcherHandler();E.shift()}}function f(){var a=$.getFormElementByName(l.$name);a&&(a.isValidationCancelled=!0),e.cancel(b),$.updateErrorMsg(""),l.$setValidity("validation",!0),V()}function v(){return n.$watch(function(){var a=l.$modelValue;if(y())return{badInput:!0};if(C&&Array.isArray(a)&&0===a.length&&Object.keys(a).length>0){var e=[],i={};return i[C]=a[C],e.push(i),e}return a},function(a,e){if(a&&a.badInput)return V(),c();var i=o(a);w&&$.runValidationCallbackOnPromise(i,w)},!0)}function c(){e.cancel(b);var a=$.getFormElementByName(l.$name);$.updateErrorMsg("INVALID_KEY_CHAR",{isValid:!1,translate:!0}),$.addToValidationSummary(a,"INVALID_KEY_CHAR",!0)}function y(){return!!t.prop("validity")&&t.prop("validity").badInput===!0}function p(){var a=null!==l.$modelValue&&"undefined"!=typeof l.$modelValue?l.$modelValue:"";Array.isArray(a)||l.$setValidity("validation",$.validate(a,!1));var e=$.getFormElementByName(l.$name);e&&(e.isValidationCancelled=!1),V(),t.bind("blur",m)}function V(){"function"==typeof m&&t.unbind("blur",m)}var b,$=new i(n,t,r,l),h="",O=[],E=[],g=$.getGlobalOptions(),j=r.name,w=r.hasOwnProperty("validationCallback")?r.validationCallback:null,F=r.hasOwnProperty("validateOnEmpty")?$.parseBool(r.validateOnEmpty):!!g.validateOnEmpty,A=r.hasOwnProperty("validArrayRequireHowMany")?r.validArrayRequireHowMany:"one",C=r.hasOwnProperty("validationArrayObjprop")?r.validationArrayObjprop:null;E.push({elmName:j,watcherHandler:v()}),r.$observe("disabled",function(a){var e=""===a||("boolean"==typeof a?a:"undefined"!=typeof a&&n.$eval(a));e===!0?(f(),$.removeFromValidationSummary(j)):p()}),t.on("$destroy",function(){s()}),n.$watch(function(){return t.attr("validation")},function(a){if("undefined"==typeof a||""===a)s();else{$.defineValidation(),p();var e=$.arrayFindObject(E,"elmName",l.$name);e||E.push({elmName:j,watcherHandler:v()})}}),t.bind("blur",m),n.$on("angularValidation.revalidate",function(a,e){if(e==l.$name){l.revalidateCalled=!0;var i=l.$modelValue,n=$.getFormElementByName(l.$name);if(n&&n.hasOwnProperty("isValidationCancelled")){var t=o(i);w&&$.runValidationCallbackOnPromise(t,w)}else l.$setValidity("validation",!0)}})}}}]); +angular.module("ghiscoding.validation").factory("ValidationCommon",["$rootScope","$timeout","$translate","ValidationRules",function(e,t,a,r){function n(e,t,r){if("undefined"!=typeof e&&null!=e){var n=e.ctrl&&e.ctrl.$name?e.ctrl.$name:e.attrs&&e.attrs.name?e.attrs.name:e.elm.attr("name"),i=x(n,e),o=V(W,"field",n);if(o>=0&&""===t)W.splice(o,1);else if(""!==t){r&&(t=a.instant(t));var l=e.attrs&&e.friendlyName?a.instant(e.friendlyName):"",s={field:n,friendlyName:l,message:t,formName:i?i.$name:null};o>=0?W[o]=s:W.push(s)}if(e.scope.$validationSummary=W,i&&(i.$validationSummary=E(W,"formName",i.$name)),Y&&Y.controllerAs&&(Y.controllerAs.$validationSummary=W,i&&i.$name)){var u=i.$name.indexOf(".")>=0?i.$name.split(".")[1]:i.$name,p=Y.controllerAs&&Y.controllerAs[u]?Y.controllerAs[u]:"undefined"!=typeof e.elm.controller()?e.elm.controller()[u]:null;p&&(p.$validationSummary=E(W,"formName",i.$name))}return W}}function i(){var e=this,t={};e.validators=[],e=S(e);var a=e.validatorAttrs.rules||e.validatorAttrs.validation||"";if(a.indexOf("pattern=/")>=0){var n=a.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);if(!n||n.length<3)throw'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';var i=n[1],o=n[2]?n[2].replace(/\|(.*)/,""):"",l=i.match(new RegExp("^/(.*?)/([gimy]*)$")),s=new RegExp(l[1],l[2]);t={altMsg:o,message:o.replace(/:alt=/,""),pattern:s},a=a.replace("pattern="+i,"pattern")}else if(a.indexOf("regex:")>=0){var n=a.match("regex:(.*?):regex");if(n.length<2)throw'Regex validator within the validation needs to be define with an opening "regex:" and a closing ":regex", please review your validator.';var u=n[1].split(":=");t={message:u[0],pattern:u[1]},a=a.replace(n[0],"regex:")}var p=a.split("|");if(p){e.bFieldRequired=a.indexOf("required")>=0;for(var d=0,m=p.length;d=0,g=[];f?(g=p[d].substring(0,c-1).split(":"),g.push(p[d].substring(c))):g=p[d].split(":"),e.validators[d]=r.getElementValidators({altText:f===!0?2===g.length?g[1]:g[2]:"",customRegEx:t,rule:g[0],ruleParams:f&&2===g.length?null:g[1]})}}return e}function o(e){return w(K,"fieldName",e)}function l(e){return e?E(K,"formName",e):K}function s(){return Y}function u(e,t,a,r){this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,$(t,a,r,e),this.defineValidation()}function p(){var e=this;return e.bFieldRequired}function d(e,t){var a={};for(var r in e)a[r]=e[r];for(var r in t)a[r]=t[r];return a}function m(e){var t=V(K,"fieldName",e);t>=0&&K.splice(t,1)}function c(e,t){var a=this,r=x(e,a),n=t||W,i=V(n,"field",e);if(i>=0&&n.splice(i,1),i=V(W,"field",e),i>=0&&W.splice(i,1),a.scope.$validationSummary=W,r&&(r.$validationSummary=E(W,"formName",r.$name)),Y&&Y.controllerAs&&(Y.controllerAs.$validationSummary=W,r)){var o=r.$name.indexOf(".")>=0?r.$name.split(".")[1]:r.$name;Y.controllerAs[o]&&(Y.controllerAs[o].$validationSummary=E(W,"formName",r.$name))}return W}function f(e,t){var a;if(/\({1}.*\){1}/gi.test(t))a=e.scope.$eval(t);else{var r=T(e.scope,t,".");"function"==typeof r&&(a=r())}return a}function g(e,t){var a=this;"function"==typeof e.then&&e.then(function(){f(a,t)})}function v(e){Y.displayOnlyLastErrorMsg=e}function y(e){var t=this;return Y=d(Y,e),t}function h(e,t){var r=this;t&&t.obj&&(r=t.obj,r.validatorAttrs=t.obj.attrs);var n=t&&t.elm?t.elm:r.elm,i=n&&n.attr("name")?n.attr("name"):null;if("undefined"==typeof i||null===i){var o=n?n.attr("ng-model"):"unknown";throw'Angular-Validation Service requires you to have a (name="") attribute on the element to validate... Your element is: ng-model="'+o+'"'}var l=t&&t.translate?a.instant(e):e;l=l.trim();var s=i.replace(/[|&;$%@"<>()+,\[\]\{\}]/g,"").replace(/\./g,"-"),u=null;if(r.validatorAttrs&&r.validatorAttrs.hasOwnProperty("validationErrorTo")){var p=r.validatorAttrs.validationErrorTo.charAt(0),d="."===p||"#"===p?r.validatorAttrs.validationErrorTo:"#"+r.validatorAttrs.validationErrorTo;u=angular.element(document.querySelector(d))}u&&0!==u.length||(u=angular.element(document.querySelector(".validation-"+s)));var m=!(!t||!t.isSubmitted)&&t.isSubmitted;!Y.hideErrorUnderInputs&&t&&!t.isValid&&(m||r.ctrl.$dirty||r.ctrl.$touched||r.ctrl.revalidateCalled)?(u.length>0?u.html(l):n.after('
'+l+"
"),r.ctrl.isErrorMessageVisible=!0):(u.html(""),r.ctrl.isErrorMessageVisible=void 0)}function b(e,t){var r,i=this,l=!0,s=!0,u=0,p={message:""};"undefined"==typeof e&&(e="");for(var d=i.ctrl&&i.ctrl.$name?i.ctrl.$name:i.attrs&&i.attrs.name?i.attrs.name:i.elm.attr("name"),m=o(d),c=i.validatorAttrs.rules||i.validatorAttrs.validation,f=0,g=i.validators.length;f0&&(o=n.altText.replace("alt=",""));var u=a(o);e.translatePromise=u,e.validator=n,u.then(function(a){p.message.length>0&&Y.displayOnlyLastErrorMsg?p.message=l+(n&&n.params?String.format(a,n.params):a):p.message+=l+(n&&n.params?String.format(a,n.params):a),O(i,e,p.message,s,t)})["catch"](function(a){if(!(n.altText&&n.altText.length>0))throw String.format("Could not translate: '{0}'. Please check your Angular-Translate $translateProvider configuration.",a);p.message.length>0&&Y.displayOnlyLastErrorMsg?p.message=l+o:p.message+=l+o,O(i,e,p.message,s,t)})}(m,l,r)),l&&u++,i.validRequireHowMany==u&&l){s=!0;break}}return l&&(n(i,""),i.updateErrorMsg("",{isValid:l})),m&&(m.isValid=s,s&&(m.message="")),s}function $(e,t,r,n){var i=t.name?t.name:e.attr("name"),o=x(i,{scope:n}),l=t&&t.friendlyName?a.instant(t.friendlyName):"",s={fieldName:i,friendlyName:l,elm:e,attrs:t,ctrl:r,scope:n,isValid:!1,message:"",formName:o?o.$name:null},u=V(K,"fieldName",e.attr("name"));return u>=0?K[u]=s:K.push(s),K}function O(e,t,a,r,i){a=a.trim(),t&&t.isValidationCancelled===!0&&(a=""),(Y.preValidateValidationSummary||"undefined"==typeof Y.preValidateValidationSummary||i)&&n(t,a),(e.validatorAttrs.preValidateFormElements||Y.preValidateFormElements)&&(t&&"function"==typeof e.ctrl.$setTouched&&t.ctrl.$setTouched(),e.ctrl.$dirty===!1&&h(a,{isSubmitted:!0,isValid:r,obj:t})),i&&t&&!t.isValid?e.updateErrorMsg(a,{isValid:r,obj:t}):t&&t.isValid&&n(t,"")}function S(e){return e.typingLimit=z,e.validatorAttrs.hasOwnProperty("debounce")?e.typingLimit=parseInt(e.validatorAttrs.debounce,10):e.validatorAttrs.hasOwnProperty("typingLimit")?e.typingLimit=parseInt(e.validatorAttrs.typingLimit,10):Y&&Y.hasOwnProperty("debounce")&&(e.typingLimit=parseInt(Y.debounce,10)),e.validRequireHowMany=e.validatorAttrs.hasOwnProperty("validRequireHowMany")?e.validatorAttrs.validRequireHowMany:Y.validRequireHowMany,X=e.validatorAttrs.hasOwnProperty("validateOnEmpty")?q(e.validatorAttrs.validateOnEmpty):Y.validateOnEmpty,e}function w(e,t,a){if(e)for(var r=0;r=0?T(t.scope,a,"."):t.scope[a];if(r)return"undefined"==typeof r.$name&&(r.$name=a),r}return null}function x(e,t){if(Y&&Y.formName){var a=document.querySelector('[name="'+Y.formName+'"]');if(a)return a.$name=Y.formName,a}for(var r=document.getElementsByName(e),a=null,n=0;n=0){var p=s.split(".");return t.scope[p[0]][p[1]]=u}return t.scope[s]=u}}return null}function N(e){return!isNaN(parseFloat(e))&&isFinite(e)}function T(e,t,a){for(var r=a?t.split(a):t,n=0,i=r.length;n8?e.substring(9).split(":"):null;break;case"UK":case"EURO":case"EURO_SHORT":case"EURO-SHORT":case"EUROPE":a=e.substring(0,8),r=e.substring(2,3),n=M(a,r),s=n[0],l=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US_LONG":case"US-LONG":a=e.substring(0,10),r=e.substring(2,3),n=M(a,r),l=n[0],s=n[1],o=n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"US":case"US_SHORT":case"US-SHORT":a=e.substring(0,8),r=e.substring(2,3),n=M(a,r),l=n[0],s=n[1],o=parseInt(n[2])<50?"20"+n[2]:"19"+n[2],i=e.length>8?e.substring(9).split(":"):null;break;case"ISO":default:a=e.substring(0,10),r=e.substring(4,5),n=M(a,r),o=n[0],l=n[1],s=n[2],i=e.length>10?e.substring(11).split(":"):null}var u=i&&3===i.length?i[0]:0,p=i&&3===i.length?i[1]:0,d=i&&3===i.length?i[2]:0;return new Date(o,l-1,s,u,p,d)}function k(e){e&&(Y={displayOnlyLastErrorMsg:!1,errorMessageSeparator:" ",hideErrorUnderInputs:!1,preValidateFormElements:!1,preValidateValidationSummary:!0,isolatedScope:null,scope:null,validateOnEmpty:!1,validRequireHowMany:"all",resetGlobalOptionsOnRouteChange:!0},K=[],W=[])}function M(e,t){var a=[];switch(t){case"/":a=e.split("/");break;case".":a=e.split(".");break;case"-":default:a=e.split("-")}return a}function C(e,t,a){var r=!1;switch(e){case"<":r=t":r=t>a;break;case">=":r=t>=a;break;case"!=":case"<>":r=t!=a;break;case"!==":r=t!==a;break;case"=":case"==":r=t==a;break;case"===":r=t===a;break;default:r=!1}return r}function L(){Element.prototype.closest=function(e){var t,a=(this.document||this.ownerDocument).querySelectorAll(e),r=this;do for(t=a.length;--t>=0&&a.item(t)!==r;);while(t<0&&(r=r.parentElement));return r}}function U(){return this.replace(/^\s+|\s+$/g,"")}function j(){var e=Array.isArray(arguments[0])?arguments[0]:arguments;return this.replace(/{(\d+)}/g,function(t,a){return"undefined"!=typeof e[a]?e[a]:t})}function P(e){var t=Array.isArray(arguments[1])?arguments[1]:Array.prototype.slice.call(arguments,1);return e.replace(/{(\d+)}/g,function(e,a){return"undefined"!=typeof t[a]?t[a]:e})}function G(e,t,a){var r=!0,n=r=!1;if(e instanceof Date)n=!0;else{var i=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&i.test(e)}if(n){var o=t.dateType,l=e instanceof Date?e:F(e,o).getTime();if(2==t.params.length){var s=F(t.params[0],o).getTime(),u=F(t.params[1],o).getTime(),p=C(t.condition[0],l,s),d=C(t.condition[1],l,u);r=p&&d}else{var m=F(t.params[0],o).getTime();r=C(t.condition,l,m)}}return r}function D(e,t){var a=!0;if(2==t.params.length){var r=C(t.condition[0],parseFloat(e),parseFloat(t.params[0])),n=C(t.condition[1],parseFloat(e),parseFloat(t.params[1]));a=r&&n}else a=C(t.condition,parseFloat(e),parseFloat(t.params[0]));return a}function H(e,a,r,n,i,o){var l=!0,s="Custom Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom javascript function as { isValid: bool, message: 'your error' }",u="Custom Javascript Validation requires a declared function (in your Controller), please review your code.";if(e||X){var p=a.params[0],d=f(r,p);if("boolean"==typeof d)l=!!d;else{if("object"!=typeof d)throw u;l=!!d.isValid}if(l===!1?(n.isValid=!1,t(function(){var e=o.message+" ";if(d.message&&(e+=d.message||a.altText)," "===e&&a.altText&&(e+=a.altText)," "===e)throw s;O(r,n,e,!1,i)})):l===!0&&(n.isValid=!0,O(r,n,"",!0,i)),"undefined"==typeof d)throw u}return l}function I(e,t,r,n){var i=!0,l=t.params[0],s=r.scope.$eval(l),u=angular.element(document.querySelector('[name="'+l+'"]')),p=t,d=r.ctrl,m=o(r.ctrl.$name);return i=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(C(t.condition,e,s)&&!!e),u&&u.attr("friendly-name")?t.params[1]=u.attr("friendly-name"):t.params.length>1&&(t.params[1]=t.params[1]),r.scope.$watch(l,function(i,o){var l=!((!t.pattern||"/\\S+/"===t.pattern.toString()||rules&&"required"===t.pattern)&&null===e)&&(C(t.condition,e,s)&&!!e);if(i!==o){if(l)O(r,m,"",!0,!0);else{m.isValid=!1;var u=p.message;p.altText&&p.altText.length>0&&(u=p.altText.replace("alt=","")),a(u).then(function(e){var t=Y.errorMessageSeparator||" ";n.message=t+(p&&p.params?String.format(e,p.params):e),O(r,m,n.message,l,!0)})}d.$setValidity("validation",l)}},!0),i}function B(e,t,a,r,n,i){var o=!0,l="Remote Javascript Validation requires an error message defined as 'alt=' in your validator or defined in your custom remote function as { isValid: bool, message: 'your error' }",s="Remote Validation requires a declared function (in your Controller) which also needs to return a Promise, please review your code.";if(e&&n||X){a.ctrl.$processing=!0;var u=t.params[0],p=f(a,u);if(Q.length>1)for(;Q.length>0;){var d=Q.pop();d&&"function"==typeof d.abort&&d.abort()}if(Q.push(p),!p||"function"!=typeof p.then)throw s;a.ctrl.$setValidity("remote",!1),function(e){p.then(function(t){t=t.data||t,Q.pop(),a.ctrl.$processing=!1;var u=i.message+" ";if("boolean"==typeof t)o=!!t;else{if("object"!=typeof t)throw s;o=!!t.isValid}if(o===!1){if(r.isValid=!1,u+=t.message||e," "===u)throw l;O(a,r,u,!1,n)}else o===!0&&(r.isValid=!0,a.ctrl.$setValidity("remote",!0),O(a,r,"",!0,n))})}(t.altText)}return o}function _(e,t,a,r){var n=!0,i=r.attrs?r.attrs.ngDisabled:r.validatorAttrs.ngDisabled,o=r.elm.prop("disabled"),l=""===o||("boolean"==typeof o?o:"undefined"!=typeof o&&r.scope.$eval(o)),s=""===i||("boolean"==typeof i?i:"undefined"!=typeof i&&r.scope.$eval(i));if(l||s)n=!0;else if("string"==typeof e&&""===e&&r.elm.prop("type")&&"NUMBER"===r.elm.prop("type").toUpperCase())n=!1;else{var u=new RegExp(t.pattern,t.patternFlag);n=!((!t.pattern||"/\\S+/"===t.pattern.toString()||a&&"required"===t.pattern)&&null===e)&&u.test(e)}return n}function J(e,t){return N(t)?{condition:e.conditionNum,message:e.messageNum,params:e.params,type:"conditionalNumber"}:{pattern:e.patternLength,message:e.messageLength,params:e.params,type:"regex"}}var z=1e3,K=[],Y={resetGlobalOptionsOnRouteChange:!0},Q=[],W=[],X=!1;e.$on("$routeChangeStart",function(e,t,a){k(Y.resetGlobalOptionsOnRouteChange)}),e.$on("$stateChangeStart",function(e,t,a){k(Y.resetGlobalOptionsOnRouteChange)});var Z=function(e,t,a,r){this.bFieldRequired=!1,this.validators=[],this.typingLimit=z,this.scope=e,this.elm=t,this.ctrl=r,this.validatorAttrs=a,this.validateOnEmpty=!1,this.validRequireHowMany="all",e&&e.$validationOptions&&(Y=e.$validationOptions),e&&(Y.isolatedScope||Y.scope)&&(this.scope=Y.isolatedScope||Y.scope,Y=d(e.$validationOptions,Y)),"undefined"==typeof Y.resetGlobalOptionsOnRouteChange&&(Y.resetGlobalOptionsOnRouteChange=!0),this.elm&&this.validatorAttrs&&this.ctrl&&this.scope&&($(this.elm,this.validatorAttrs,this.ctrl,this.scope),this.defineValidation())};return Z.prototype.addToValidationSummary=n,Z.prototype.arrayFindObject=w,Z.prototype.arrayRemoveObject=A,Z.prototype.defineValidation=i,Z.prototype.getFormElementByName=o,Z.prototype.getFormElements=l,Z.prototype.getGlobalOptions=s,Z.prototype.isFieldRequired=p,Z.prototype.initialize=u,Z.prototype.mergeObjects=d,Z.prototype.parseBool=q,Z.prototype.removeFromValidationSummary=c,Z.prototype.removeFromFormElementObjectList=m,Z.prototype.runValidationCallbackOnPromise=g,Z.prototype.setDisplayOnlyLastErrorMsg=v,Z.prototype.setGlobalOptions=y,Z.prototype.updateErrorMsg=h,Z.prototype.validate=b,window.Element&&!Element.prototype.closest&&(Element.prototype.closest=L),String.prototype.trim=U,String.prototype.format=j,String.format=P,Z}]); angular.module("ghiscoding.validation").factory("ValidationRules",[function(){function e(e){var a="undefined"!=typeof e.altText?e.altText.replace("alt=",""):null,t=e.hasOwnProperty("customRegEx")?e.customRegEx:null,s=e.hasOwnProperty("rule")?e.rule:null,n=e.hasOwnProperty("ruleParams")?e.ruleParams:null,d={};switch(s){case"accepted":d={pattern:/^(yes|on|1|true)$/i,message:"INVALID_ACCEPTED",type:"regex"};break;case"alpha":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,message:"INVALID_ALPHA",type:"regex"};break;case"alphaSpaces":case"alpha_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,message:"INVALID_ALPHA_SPACE",type:"regex"};break;case"alphaNum":case"alpha_num":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9])+$/i,message:"INVALID_ALPHA_NUM",type:"regex"};break;case"alphaNumSpaces":case"alpha_num_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s])+$/i,message:"INVALID_ALPHA_NUM_SPACE",type:"regex"};break;case"alphaDash":case"alpha_dash":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_-])+$/i,message:"INVALID_ALPHA_DASH",type:"regex"};break;case"alphaDashSpaces":case"alpha_dash_spaces":d={pattern:/^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,message:"INVALID_ALPHA_DASH_SPACE",type:"regex"};break;case"between":case"range":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";d={patternLength:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",messageLength:"INVALID_BETWEEN_CHAR",conditionNum:[">=","<="],messageNum:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"autoDetect"};break;case"betweenLen":case"between_len":case"stringLen":case"string_len":case"stringLength":case"string_length":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";d={pattern:"^(.|[\\r\\n]){"+r[0]+","+r[1]+"}$",message:"INVALID_BETWEEN_CHAR",params:[r[0],r[1]],type:"regex"};break;case"betweenNum":case"between_num":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_num:1,5";d={condition:[">=","<="],message:"INVALID_BETWEEN_NUM",params:[r[0],r[1]],type:"conditionalNumber"};break;case"boolean":d={pattern:/^(true|false|0|1)$/i,message:"INVALID_BOOLEAN",type:"regex"};break;case"checked":d={pattern:/^true$/i,message:"INVALID_CHECKBOX_SELECTED",type:"regex"};break;case"creditCard":case"credit_card":d={pattern:/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/,message:"INVALID_CREDIT_CARD",type:"regex"};break;case"custom":case"javascript":d={message:"",params:[n],type:"javascript"};break;case"dateEuro":case"date_euro":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO",type:"regex"};break;case"dateEuroBetween":case"date_euro_between":case"betweenDateEuro":case"between_date_euro":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_BETWEEN",type:"conditionalDate"};break;case"dateEuroMax":case"date_euro_max":case"maxDateEuro":case"max_date_euro":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MAX",type:"conditionalDate"};break;case"dateEuroMin":case"date_euro_min":case"minDateEuro":case"min_date_euro":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_EURO_MIN",type:"conditionalDate"};break;case"dateEuroLong":case"date_euro_long":d={pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG",type:"regex"};break;case"dateEuroLongBetween":case"date_euro_long_between":case"betweenDateEuroLong":case"between_date_euro_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_long:01-01-1990,31-12-2015";d={condition:[">=","<="],dateType:"EURO_LONG",params:[r[0],r[1]],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_BETWEEN",type:"conditionalDate"};break;case"dateEuroLongMax":case"date_euro_long_max":case"maxDateEuroLong":case"max_date_euro_long":d={condition:"<=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MAX",type:"conditionalDate"};break;case"dateEuroLongMin":case"date_euro_long_min":case"minDateEuroLong":case"min_date_euro_long":d={condition:">=",dateType:"EURO_LONG",params:[n],pattern:/^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{4})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_EURO_LONG_MIN",type:"conditionalDate"};break;case"dateEuroShort":case"date_euro_short":d={pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT",type:"regex"};break;case"dateEuroShortBetween":case"date_euro_short_between":case"betweenDateEuroShort":case"between_date_euro_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_euro_short:01-01-90,31-12-15";d={condition:[">=","<="],dateType:"EURO_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateEuroShortMax":case"date_euro_short_max":case"maxDateEuroShort":case"max_date_euro_short":d={condition:"<=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MAX",type:"conditionalDate"};break;case"dateEuroShortMin":case"date_euro_short_min":case"minDateEuroShort":case"min_date_euro_short":d={condition:">=",dateType:"EURO_SHORT",params:[n],pattern:/^(0[1-9]|[12][0-9]|3[01])[-\/\.](0[1-9]|1[012])[-\/\.]\d\d$/,message:"INVALID_DATE_EURO_SHORT_MIN",type:"conditionalDate"};break;case"dateIso":case"date_iso":d={pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO",type:"regex"};break;case"dateIsoBetween":case"date_iso_between":case"betweenDateIso":case"between_date_iso":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_iso:1990-01-01,2000-12-31";d={condition:[">=","<="],dateType:"ISO",params:[r[0],r[1]],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_BETWEEN",type:"conditionalDate"};break;case"dateIsoMax":case"date_iso_max":case"maxDateIso":case"max_date_iso":d={condition:"<=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MAX",type:"conditionalDate"};break;case"dateIsoMin":case"date_iso_min":case"minDateIso":case"min_date_iso":d={condition:">=",dateType:"ISO",params:[n],pattern:/^(?=\d)(?:(?!(?:1582(?:\-)10(?:\-)(?:0?[5-9]|1[0-4]))|(?:1752(?:\-)0?9(?:\-)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\-)(?:29|30))))(\d{4})(\-)(0{1}\d|1[012])\2((?!00)[012]{1}\d|3[01])(?:$|(?=\d)))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2})|(?:[01]\d|2[0-3])(?::[0-5]\d){2})?$/,message:"INVALID_DATE_ISO_MIN",type:"conditionalDate"};break;case"dateUs":case"date_us":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US",type:"regex"};break;case"dateUsBetween":case"date_us_between":case"betweenDateUs":case"between_date_us":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_BETWEEN",type:"conditionalDate"};break;case"dateUsMax":case"date_us_max":case"maxDateUs":case"max_date_us":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MAX",type:"conditionalDate"};break;case"dateUsMin":case"date_us_min":case"minDateUs":case"min_date_us":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])?00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,message:"INVALID_DATE_US_MIN",type:"conditionalDate"};break;case"dateUsLong":case"date_us_long":d={pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG",type:"regex"};break;case"dateUsLongBetween":case"date_us_long_between":case"betweenDateUsLong":case"between_date_us_long":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_long:01/01/1990,12/31/2015";d={condition:[">=","<="],dateType:"US_LONG",params:[r[0],r[1]],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_BETWEEN",type:"conditionalDate"};break;case"dateUsLongMax":case"date_us_long_max":case"maxDateUsLong":case"max_date_us_long":d={condition:"<=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MAX",type:"conditionalDate"};break;case"dateUsLongMin":case"date_us_long_min":case"minDateUsLong":case"min_date_us_long":d={condition:">=",dateType:"US_LONG",params:[n],pattern:/^(?:(?:(?:0[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:02(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0[1-9])|(?:1[0-2]))(\/|-|\.)(?:0[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/,message:"INVALID_DATE_US_LONG_MIN",type:"conditionalDate"};break;case"dateUsShort":case"date_us_short":d={pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT",type:"regex"};break;case"dateUsShortBetween":case"date_us_short_between":case"betweenDateUsShort":case"between_date_us_short":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: between_date_us_short:01/01/90,12/31/15";d={condition:[">=","<="],dateType:"US_SHORT",params:[r[0],r[1]],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_BETWEEN",type:"conditionalDate"};break;case"dateUsShortMax":case"date_us_short_max":case"maxDateUsShort":case"max_date_us_short":d={condition:"<=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MAX",type:"conditionalDate"};break;case"dateUsShortMin":case"date_us_short_min":case"minDateUsShort":case"min_date_us_short":d={condition:">=",dateType:"US_SHORT",params:[n],pattern:/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]\d\d$/,message:"INVALID_DATE_US_SHORT_MIN",type:"conditionalDate"};break;case"different":case"differentInput":case"different_input":var e=n.split(",");d={condition:"!=",message:"INVALID_INPUT_DIFFERENT",params:e,type:"matching"};break;case"digits":d={pattern:"^\\d{"+n+"}$",message:"INVALID_DIGITS",params:[n],type:"regex"};break;case"digitsBetween":case"digits_between":var r=n.split(",");if(2!==r.length)throw"This validation must include exactly 2 params separated by a comma (,) ex.: digits_between:1,5";d={pattern:"^\\d{"+r[0]+","+r[1]+"}$",message:"INVALID_DIGITS_BETWEEN",params:[r[0],r[1]],type:"regex"};break;case"email":case"emailAddress":case"email_address":d={pattern:/^[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_][-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]*(\.[-\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9_]+)*([\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]+)|(\.[\wа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i,message:"INVALID_EMAIL",type:"regex"};break;case"exactLen":case"exact_len":d={pattern:"^(.|[\\r\\n]){"+n+"}$",message:"INVALID_EXACT_LEN",params:[n],type:"regex"};break;case"float":d={pattern:/^\d*\.{1}\d+$/,message:"INVALID_FLOAT",type:"regex"};break;case"floatSigned":case"float_signed":d={pattern:/^[-+]?\d*\.{1}\d+$/,message:"INVALID_FLOAT_SIGNED",type:"regex"};break;case"iban":d={pattern:/^[a-zA-Z]{2}\d{2}\s?([0-9a-zA-Z]{4}\s?){4}[0-9a-zA-Z]{2}$/i,message:"INVALID_IBAN",type:"regex"};break;case"enum":case"in":case"inList":case"in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^("+_+")$",patternFlag:"i",message:"INVALID_IN_LIST",params:[n],type:"regex"};break;case"int":case"integer":d={pattern:/^\d+$/,message:"INVALID_INTEGER",type:"regex"};break;case"intSigned":case"integerSigned":case"int_signed":case"integer_signed":d={pattern:/^[+-]?\d+$/,message:"INVALID_INTEGER_SIGNED",type:"regex"};break;case"ip":case"ipv4":d={pattern:/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/,message:"INVALID_IPV4",type:"regex"};break;case"ipv6":d={pattern:/^(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))$/i,message:"INVALID_IPV6",type:"regex"};break;case"compare":case"match":case"matchInput":case"match_input":case"same":var e=n.split(",");d={condition:"===",message:"INVALID_INPUT_MATCH",params:e,type:"matching"};break;case"max":d={patternLength:"^(.|[\\r\\n]){0,"+n+"}$",messageLength:"INVALID_MAX_CHAR",conditionNum:"<=",messageNum:"INVALID_MAX_NUM",params:[n],type:"autoDetect"};break;case"maxLen":case"max_len":case"maxLength":case"max_length":d={pattern:"^(.|[\\r\\n]){0,"+n+"}$",message:"INVALID_MAX_CHAR",params:[n],type:"regex"};break;case"maxNum":case"max_num":d={condition:"<=",message:"INVALID_MAX_NUM",params:[n],type:"conditionalNumber"};break;case"min":d={patternLength:"^(.|[\\r\\n]){"+n+",}$",messageLength:"INVALID_MIN_CHAR",conditionNum:">=",messageNum:"INVALID_MIN_NUM",params:[n],type:"autoDetect"};break;case"minLen":case"min_len":case"minLength":case"min_length":d={pattern:"^(.|[\\r\\n]){"+n+",}$",message:"INVALID_MIN_CHAR",params:[n],type:"regex"};break;case"minNum":case"min_num":d={condition:">=",message:"INVALID_MIN_NUM",params:[n],type:"conditionalNumber"};break;case"notIn":case"not_in":case"notInList":case"not_in_list":var _=RegExp().escape(n).replace(/,/g,"|");d={pattern:"^((?!("+_+")).)+$",patternFlag:"i",message:"INVALID_NOT_IN_LIST",params:[n],type:"regex"};break;case"numeric":d={pattern:/^\d*\.?\d+$/,message:"INVALID_NUMERIC",type:"regex"};break;case"numericSigned":case"numeric_signed":d={pattern:/^[-+]?\d*\.?\d+$/,message:"INVALID_NUMERIC_SIGNED",type:"regex"};break;case"phone":d={pattern:/^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,message:"INVALID_PHONE_US",type:"regex"};break;case"phoneInternational":case"phone_international":d={pattern:/^\+(?:[0-9]\x20?){6,14}[0-9]$/,message:"INVALID_PHONE_INTERNATIONAL",type:"regex"};break;case"pattern":case"regex":d={pattern:t.pattern,message:"INVALID_PATTERN",params:[t.message],type:"regex"};break;case"remote":d={message:"",params:[n],type:"remote"};break;case"required":d={pattern:/\S+/,message:"INVALID_REQUIRED",type:"regex"};break;case"size":d={patternLength:"^(.|[\\r\\n]){"+n+"}$",messageLength:"INVALID_EXACT_LEN",conditionNum:"==",messageNum:"INVALID_EXACT_NUM",params:[n],type:"autoDetect"};break;case"url":d={pattern:/^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i,message:"INVALID_URL",type:"regex"};break;case"time":d={pattern:/^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/,message:"INVALID_TIME",type:"regex"}}return d.altText=a,d}var a={getElementValidators:e};return a}]),RegExp.prototype.escape=function(e){if(!arguments.callee.sRE){var a=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+a.join("|\\")+")","g")}return e.replace(arguments.callee.sRE,"\\$1")}; -angular.module("ghiscoding.validation").service("ValidationService",["$interpolate","$q","$timeout","ValidationCommon",function(e,o,t,a){function n(o,t,a){var n=this,i={};if("string"==typeof o&&"string"==typeof t?(i.elmName=o,i.rules=t,i.friendlyName="string"==typeof a?a:""):i=o,"object"!=typeof i||!i.hasOwnProperty("elmName")||!i.hasOwnProperty("rules")||!i.hasOwnProperty("scope")&&"undefined"==typeof n.validationAttrs.scope)throw"Angular-Validation-Service requires at least the following 3 attributes: {elmName, rules, scope}";var l=i.scope?i.scope:n.validationAttrs.scope;if(i.elm=angular.element(document.querySelector('[name="'+i.elmName+'"]')),"object"!=typeof i.elm||0===i.elm.length)return n;if(new RegExp("{{(.*?)}}").test(i.elmName)&&(i.elmName=e(i.elmName)(l)),i.name=i.elmName,n.validationAttrs.isolatedScope||i.isolatedScope){var m=l.$validationOptions||null;l=n.validationAttrs.isolatedScope||i.isolatedScope,m&&(l.$validationOptions=m)}return i.elm.bind("blur",j=function(e){var o=n.commonObj.getFormElementByName(i.elmName);if(o&&!o.isValidationCancelled){n.commonObj.initialize(l,i.elm,i,i.ctrl);var t=s(n,e.target.value,0);g&&n.commonObj.runValidationCallbackOnPromise(t,g)}}),i=n.commonObj.mergeObjects(n.validationAttrs,i),g=i.hasOwnProperty("validationCallback")?i.validationCallback:null,$=i.hasOwnProperty("validateOnEmpty")?n.commonObj.parseBool(i.validateOnEmpty):!!V.validateOnEmpty,O(n,l,i),i.elm.on("$destroy",function(){var e=n.commonObj.getFormElementByName(n.commonObj.ctrl.$name);e&&(u(n,e),n.commonObj.removeFromValidationSummary(i.name))}),h.push({elmName:i.elmName,watcherHandler:f(l,i,n)}),n}function i(e,o){var t=this,a="",n=!0;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"checkFormValidity() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var i=0,l=e.$validationSummary.length;i0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a0&&("function"!=typeof m.ctrl.$setTouched||o||m.ctrl.$setTouched(),t.commonObj.updateErrorMsg(e.$validationSummary[i].message,{isSubmitted:!o,isValid:m.isValid,obj:m}))}return n}function l(e){var o=this;if("undefined"==typeof e||"undefined"==typeof e.$validationSummary)throw"clearInvalidValidatorsInSummary() requires a valid Angular Form or $scope/vm object passed as argument to work properly, for example:: fn($scope) OR fn($scope.form1) OR fn(vm) OR fn(vm.form1)";for(var t=[],a=0,n=e.$validationSummary.length;a