Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Fixed #92 name with dot, #94 Polish, #96 in_list
Browse files Browse the repository at this point in the history
Fixed issue #92 input name with '.' was not working correctly on error
message
Issue #96 in_list was not accepting special characters.
Enhancement #94 added Polish characters, thanks @Waniusza
  • Loading branch information
ghiscoding committed Dec 15, 2015
1 parent ebdd789 commit fe72fc9
Show file tree
Hide file tree
Showing 20 changed files with 71 additions and 53 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ myApp.controller('CtrlValidationService', ['$q', '$scope', '$translate', 'valida
.addValidator({elmName: 'input18', rules: 'alpha_spaces|exact_len:3|required', debounce: 3000})
.addValidator('input19', 'date_iso_min:2001-01-01|required')
.addValidator('input20', 'date_us_short_between:11/28/99,12/31/15|required')
.addValidator('input21', 'in_list:banana,orange,ice cream|required')
.addValidator('input21', 'in_list:banana,orange,ice cream,sweet & sour|required')
.addValidator('area1', 'alpha_dash_spaces|min_len:15|required')
.addValidator('input22', 'alpha_dash|min_len:2|required');

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.4.16",
"version": "1.4.17",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Angular-Validation change logs

1.4.17 (2015-12-15) Fixed issue #92 input name with '.', enhancement #94 Polish characters, issue #96 in_list wasn't accepting special characters.
1.4.16 (2015-12-11) Fixed issue #90 blinking error messages.
1.4.15 (2015-12-02) Fixed issue #86 implicit global variable on regex.
1.4.14 (2015-11-15) Added validation-callback (#79), added #81, #82. Added new validation-callback attribute, runs after the debounce/blur and validaiton are completed. Added possibility passing arguments to Custom & Remote validators. Added new Global Options: hideErrorUnderInputs.
Expand Down
8 changes: 4 additions & 4 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions full-tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function loadData() {
{
'validator': 'in',
'aliases': ['inList', 'in_list'],
'params': 'chocolate,apple pie,ice cream'
'params': 'chocolate,apple pie,ice cream,sweet & sour,A+B'
},
{
'validator': 'int',
Expand Down Expand Up @@ -324,7 +324,7 @@ function loadData() {
{
'validator': 'notIn',
'aliases': ['not_in', 'notInList', 'not_in_list'],
'params': 'chocolate,apple pie,ice cream'
'params': 'chocolate,apple pie,ice cream,sweet & sour,A+B'
},
{
'validator': 'numeric'
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Alphanumeric + Exactly(3) + Required -- debounce(3sec)",
"INPUT19": "Date ISO (yyyy-mm-dd) -- minimum condition >= 2001-01-01 ",
"INPUT20": "Date US SHORT (mm/dd/yy) -- between the dates 12/01/99 and 12/31/15",
"INPUT21": "Choice IN this list (banana,orange,ice cream)",
"INPUT21": "Choice IN this list (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "First Name",
"LAST_NAME": "Last Name",
"RESET_FORM": "Reset Form",
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Alfanúmerico + Exactamente(3) + Requerido -- debounce(3sec)",
"INPUT19": "Fecha formato ISO (yyyy-mm-dd) -- Condición mínima >= 2001-01-01 ",
"INPUT20": "Fecha formato US corto (mm/dd/yy) -- entre las fechas 12/01/99 and 12/31/15",
"INPUT21": "Elección en esta lista (banana,orange,ice cream)",
"INPUT21": "Elección en esta lista (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "Nombre",
"LAST_NAME": "Apellido",
"RESET_FORM": "Cambiar la Forma",
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Alphanumérique + Exactement(3) + Requis -- debounce(3sec)",
"INPUT19": "Date ISO (aaaa-mm-jj ) -- condition minimal >= 2001-01-01 ",
"INPUT20": "Date US COURT (mm/jj/aa) -- entre les dates 12/01/99 et 12/31/15",
"INPUT21": "Choix dans cette liste (banana,orange,ice cream)",
"INPUT21": "Choix dans cette liste (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "Prénom",
"LAST_NAME": "Nom de Famille",
"RESET_FORM": "Réinitialisation le formulaire",
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Alfanumerisk + Nøyaktig(3) + Påkrevd -- debounce(3sec)",
"INPUT19": "ISO dato (yyyy-mm-dd) -- minimum >= 2001-01-01 ",
"INPUT20": "US SHORT dato (mm/dd/yy) -- mellom 12/01/99 og 12/31/15",
"INPUT21": "Valget i denne listen (banana,orange,ice cream)",
"INPUT21": "Valget i denne listen (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "Fornavn",
"LAST_NAME": "Etternavn",
"RESET_FORM": "Nullstill skjemaet",
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Alfanumeryczne + Dokładnie(3) + Wymaganae -- debounce(3sec)",
"INPUT19": "Data w formacie ISO (rrrr-mm-dd) -- warunek minimum >= 2001-01-01 ",
"INPUT20": "Data w formacie US SHORT (mm/dd/rr) -- pomiędzy datami 12/01/99 a 12/31/15",
"INPUT21": "Wybór w tej liście (banana,orange,ice cream)",
"INPUT21": "Wybór w tej liście (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "Imię",
"LAST_NAME": "Nazwisko",
"RESET_FORM": "Zresetować formularz",
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Alphanumeric + Exactly(3) + Required -- debounce(3sec)",
"INPUT19": "Date ISO (yyyy-mm-dd) -- minimum condition >= 2001-01-01 ",
"INPUT20": "Date US SHORT (mm/dd/yy) -- entre the dates 12/01/99 and 12/31/15",
"INPUT21": "Escolha nesta lista (banana,orange,ice cream)",
"INPUT21": "Escolha nesta lista (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "Primeiro nome",
"LAST_NAME": "Último nome",
"RESET_FORM": "Limpar formulário",
Expand Down
2 changes: 1 addition & 1 deletion locales/validation/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"INPUT18": "Буквенно-цифровой + Точно(3) + Обязательно -- debounce(3sec)",
"INPUT19": "Дата ISO (yyyy-mm-dd) -- минимальное условие >= 2001-01-01 ",
"INPUT20": "Дата US SHORT (mm/dd/yy) --между датами 12/01/99 и 12/31/15",
"INPUT21": "Выбор в этом списке (banana,orange,ice cream)",
"INPUT21": "Выбор в этом списке (banana,orange,ice cream,sweet & sour)",
"FIRST_NAME": "Имя",
"LAST_NAME": "Фамилия",
"RESET_FORM": "Сброс форму",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.4.16",
"version": "1.4.17",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
32 changes: 16 additions & 16 deletions protractor/full_tests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,15 +652,15 @@ function loadData() {
{
'validator': 'in',
'aliases': ['inList', 'in_list'],
'params': 'chocolate,apple pie,ice cream',
'params': 'chocolate,apple pie,ice cream,sweet & sour,A+B',
'invalid_data': ['choco', 'carrot', 'apple'],
'valid_data': ['chocolate', 'apple pie', 'ice cream'],
'valid_data': ['chocolate', 'ice cream','sweet & sour','A+B'],
'error_message': {
'en': "Must be a choice inside this list: (chocolate,apple pie,ice cream).",
'es': "Debe ser una opción dentro de esta lista: (chocolate,apple pie,ice cream).",
'fr': "Doit être un choix dans cette liste: (chocolate,apple pie,ice cream).",
'no': "Må være et valg inne i denne listen: (chocolate,apple pie,ice cream).",
'ru': "Должно бытьвыбор в этом списке: (chocolate,apple pie,ice cream)."
'en': "Must be a choice inside this list: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'es': "Debe ser una opción dentro de esta lista: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'fr': "Doit être un choix dans cette liste: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'no': "Må være et valg inne i denne listen: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'ru': "Должно бытьвыбор в этом списке: (chocolate,apple pie,ice cream,sweet & sour,A+B)."
}
},
{
Expand Down Expand Up @@ -773,15 +773,15 @@ function loadData() {
{
'validator': 'notIn',
'aliases': ['not_in', 'notInList', 'not_in_list'],
'params': 'chocolate,apple pie,ice cream',
'invalid_data': ['chocolate', 'apple pie', 'ice cream'],
'valid_data': ['choco', 'carrot', 'apple'],
'error_message': {
'en': "Must be a choice outside this list: (chocolate,apple pie,ice cream).",
'es': "Debe ser una elección fuera de esta lista: (chocolate,apple pie,ice cream).",
'fr': "Doit être un choix en dehors de cette liste: (chocolate,apple pie,ice cream).",
'no': "Må være et valg utenfor denne listen: (chocolate,apple pie,ice cream).",
'ru': "Должно бытьвыбор за этот список: (chocolate,apple pie,ice cream)."
'params': 'chocolate,apple pie,ice cream,sweet & sour,A+B',
'invalid_data': ['chocolate', 'apple pie', 'sweet & sour', 'A+B'],
'valid_data': ['apple', 'sweet & sou', 'A+', 'B+A'],
'error_message': {
'en': "Must be a choice outside this list: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'es': "Debe ser una elección fuera de esta lista: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'fr': "Doit être un choix en dehors de cette liste: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'no': "Må være et valg utenfor denne listen: (chocolate,apple pie,ice cream,sweet & sour,A+B).",
'ru': "Должно бытьвыбор за этот список: (chocolate,apple pie,ice cream,sweet & sour,A+B)."
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions protractor/mixed_validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"Alphanumeric + Exactly(3) + Required -- debounce(3sec)",
"Date ISO (yyyy-mm-dd) -- minimum condition >= 2001-01-01",
"Date US SHORT (mm/dd/yy) -- between the dates 12/01/99 and 12/31/15",
"Choice IN this list (banana,orange,ice cream)",
"Choice IN this list (banana,orange,ice cream,sweet & sour)",
"TextArea: Alphanumeric + Minimum(15) + Required",
"Input22 - ngDisabled =>"
];
Expand All @@ -48,7 +48,7 @@
"May only contain letters and spaces. Must have a length of exactly 3 characters. Field is required.",
"Needs to be a valid date format (yyyy-mm-dd), equal to, or higher than 2001-01-01. Field is required.",
"Needs to be a valid date format (mm/dd/yy) OR (mm-dd-yy) between 11/28/99 and 12/31/15. Field is required.",
"Must be a choice inside this list: (banana,orange,ice cream). Field is required.",
"Must be a choice inside this list: (banana,orange,ice cream,sweet & sour). Field is required.",
"May only contain letters, numbers, dashes and spaces. Must be at least 15 characters. Field is required."
];
var validInputTexts = [
Expand All @@ -72,7 +72,7 @@
"abc",
"2001-01-01",
"01/01/12",
"ice cream",
"sweet & sour",
"This is a great tool"
];
var types = ['Directive', 'Service'];
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.4.16`
`Version: 1.4.17`
### Form validation after user stop typing (default 1sec).

Forms Validation with Angular made easy! Angular-Validation is an angular directive/service with locales (languages) with a very simple approach of defining your `validation=""` directly within your element to validate (input, textarea, etc) and...that's it!!! The directive/service will take care of the rest!
Expand Down
10 changes: 5 additions & 5 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ angular
validationCommon.prototype.validate = validate; // validate current element

// override some default String functions
String.prototype.trim = stringPrototypeTrim;
String.prototype.format = stringPrototypeFormat;
String.format = stringFormat;

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;

Expand Down Expand Up @@ -457,7 +456,8 @@ angular
var errorMsg = (!!attrs && !!attrs.translate) ? $translate.instant(message) : message;

// get the name attribute of current element, make sure to strip dirty characters, for example remove a <input name="options[]"/>, we need to strip the "[]"
var elmInputName = elmName.replace(/[|&;$%@"<>()+,\[\]\{\}]/g, '');
// 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'
Expand Down
37 changes: 27 additions & 10 deletions src/validation-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,47 @@ angular
break;
case "alpha" :
validator = {
pattern: /^([a-zа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ])+$/i,
pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ])+$/i,
message: "INVALID_ALPHA",
type: "regex"
};
break;
case "alphaSpaces" :
case "alpha_spaces" :
validator = {
pattern: /^([a-zа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ\s])+$/i,
pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ\s])+$/i,
message: "INVALID_ALPHA_SPACE",
type: "regex"
};
break;
case "alphaNum" :
case "alpha_num" :
validator = {
pattern: /^([a-zа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ0-9])+$/i,
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,
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,
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,
pattern: /^([a-zа-яàáâãäåąæçćèéêëęœìíïîłńðòóôõöøśùúûñüýÿżźßÞďđ0-9\s_-])+$/i,
message: "INVALID_ALPHA_DASH_SPACE",
type: "regex"
};
Expand Down Expand Up @@ -491,9 +491,9 @@ angular
case "in" :
case "inList" :
case "in_list" :
var list = ruleParams.replace(/,/g, '|'); // replace comma (,) by pipe (|)
var list = RegExp().escape(ruleParams).replace(/,/g, '|'); // escape string & replace comma (,) by pipe (|)
validator = {
pattern: "^(\\b(" + list + ")\\b)$",
pattern: "^(" + list + ")$",
patternFlag: 'i',
message: "INVALID_IN_LIST",
params: [ruleParams],
Expand Down Expand Up @@ -605,9 +605,9 @@ angular
case "not_in" :
case "notInList" :
case "not_in_list" :
var list = ruleParams.replace(/,/g, '|'); // replace comma (,) by pipe (|)
var list = RegExp().escape(ruleParams).replace(/,/g, '|'); // escape string & replace comma (,) by pipe (|)
validator = {
pattern: "^((?!\\b(" + list + ")\\b).)+$",
pattern: "^((?!(" + list + ")).)+$",
patternFlag: 'i',
message: "INVALID_NOT_IN_LIST",
params: [ruleParams],
Expand Down Expand Up @@ -685,3 +685,20 @@ angular
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');
}
2 changes: 1 addition & 1 deletion templates/testingFormDirective.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h4><strong>{{ 'ERRORS' | translate }}!</strong></h4>
</div>
<div class="form-group">
<label for="input21">{{ 'INPUT21' | translate }}</label>
<input type="text" class="form-control" name="input21" placeholder="in_list:banana,orange,ice cream|required" ng-model="input21" validation="in_list:banana,orange,ice cream|required" />
<input type="text" class="form-control" name="input21" placeholder="in_list:banana,orange,ice cream,sweet &amp; sour|required" ng-model="input21" validation="in_list:banana,orange,ice cream,sweet &amp; sour|required" />
</div>
<div class="form-group">
<label for="area1">{{ 'AREA1' | translate }}</label>
Expand Down
2 changes: 1 addition & 1 deletion templates/testingFormService.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ <h4><strong>{{ 'ERRORS' | translate }}!</strong></h4>
</div>
<div class="form-group">
<label for="input21">{{ 'INPUT21' | translate }}</label>
<input type="text" class="form-control" name="input21" placeholder="in_list:banana,orange,berry|required" ng-model="input21" />
<input type="text" class="form-control" name="input21" placeholder="in_list:banana,orange,ice cream,sweet &amp; sour|required" ng-model="input21" />
</div>
<div class="form-group">
<label for="area1">{{ 'AREA1' | translate }}</label>
Expand Down

0 comments on commit fe72fc9

Please sign in to comment.