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

Commit

Permalink
Rewrote custom Regex Pattern and fixed issue #45
Browse files Browse the repository at this point in the history
- Deprecated old implentation of `regex:...:regex` (though it still
works) by a new and much better implementation of `pattern=` validator.
- Converted all the rules from string pattern to regex pattern (when
possible) defined in `angular-validation.js`.
- Also fixed issue #45 on email check.
  • Loading branch information
ghiscoding committed Jul 16, 2015
1 parent 9c943c6 commit b58fbc1
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 75 deletions.
9 changes: 7 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ myApp.controller('Ctrl', ['$location', '$route', '$scope', '$translate', functio
// -- Controller to use Angular-Validation Directive
// -----------------------------------------------
myApp.controller('CtrlValidationDirective', ['$q', '$scope', 'validationService', function ($q, $scope, validationService) {
$scope.$validationOptions = { debounce: 1500, preValidateFormElements: false }; // you can change default debounce globally
// you can change default debounce globally
$scope.$validationOptions = { debounce: 1500, preValidateFormElements: false };

// if we want to use the invalid_pattern_data locale translation as an alternateText (:alt=)
// then we need to supply an extra 'data' variable (as defined in the JSON locale) of what we expect the search pattern on our input4
$scope.translationData = { data: 'YYWW' };

// remove a single element ($scope.form1, string)
// OR you can also remove multiple elements through an array type .removeValidator($scope.form1, ['input2','input3'])
Expand Down Expand Up @@ -122,7 +127,7 @@ myApp.controller('CtrlValidationService', ['$q', '$scope', '$translate', 'valida
.setGlobalOptions({ debounce: 1500, scope: $scope, isolatedScope: $scope, preValidateFormElements: false, displayOnlyLastErrorMsg: false })
.addValidator({ elmName: 'input2', debounce: 3000, rules: 'numeric_signed|required'})
.addValidator('input3', 'float_signed|between_num:-0.6,99.5|required')
.addValidator('input4', 'exact_len:4|regex:YYWW:=^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$:regex|required|integer')
.addValidator('input4', 'exact_len:4|pattern=/^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$/:alt=' + $translate.instant('INVALID_PATTERN_DATA', { data: 'YYWW' }) + '|required|integer')
.addValidator('input5', 'email|required|min_len:6', $translate.instant('INPUT5')) // 3rd argument being the Friendly name
.addValidator('input6', 'url|required')
.addValidator('input7', 'ipv4|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.3.34",
"version": "1.3.35",
"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.3.35 (2015-07-15) Deprecated old implentation of `regex:...:regex` (though it still works) by a new and much better implementation of `pattern=` validator. Converted all the rules from string pattern to regex pattern (when possible) defined in `angular-validation.js`. Also fixed issue #45 on email check.
1.3.34 (2015-07-08) Merge pull request #44 - Adding support to brazilian portuguese language.
1.3.33 (2015-07-02) Reset isolatedScope on route change
1.3.32 (2015-06-24) Merged pull request #41 and fixed errors inside it, updated Protractor test as well.
Expand Down
8 changes: 4 additions & 4 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions locales/validation/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"INVALID_NUMERIC": "Must be a positive number. ",
"INVALID_NUMERIC_SIGNED": "Must be a positive or negative number. ",
"INVALID_PATTERN": "Must be following this format: {0}. ",
"INVALID_PATTERN_DATA": "Must be following this format \"{{data}}\". ",
"INVALID_REQUIRED": "Field is required. ",
"INVALID_URL": "Must be a valid URL. ",
"INVALID_TIME": "Must be a valid time format (hh:mm) OR (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"INVALID_NUMERIC": "Doit être un nombre positif. ",
"INVALID_NUMERIC_SIGNED": "Doit être un nombre positif ou négatif. ",
"INVALID_PATTERN": "Doit suivre le format: {0}. ",
"INVALID_PATTERN_DATA": "Doit suivre le format \"{{data}}\". ",
"INVALID_REQUIRED": "Le champ est requis. ",
"INVALID_URL": "Doit être un URL valide. ",
"INVALID_TIME": "Doit être un format de temps valide (hh:mm) OU (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"INVALID_NUMERIC": "Må være et positivt tall. ",
"INVALID_NUMERIC_SIGNED": "Må være et positivt eller negativt tall. ",
"INVALID_PATTERN": "Må være på følgende format: {0}. ",
"INVALID_PATTERN_DATA": "Må være på følgende format \"{{data}}\". ",
"INVALID_REQUIRED": "Feltet er påkrevd. ",
"INVALID_URL": "Må være en gyldig URL. ",
"INVALID_TIME": "Må være et gyldig tidsformat (tt:mm) OR (tt:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"INVALID_NUMERIC": "Musi być liczbą dodatnią. ",
"INVALID_NUMERIC_SIGNED": "Musi być liczbą dodatnią lub ujemną. ",
"INVALID_PATTERN": "Musi być zgodne z formatem: {0}. ",
"INVALID_PATTERN_DATA": "Musi być zgodne z formatem \"{{data}}\". ",
"INVALID_REQUIRED": "Pole jest wymagane. ",
"INVALID_URL": "Musi być poprawnym adresem URL. ",
"INVALID_TIME": "Musi być poprawną godziną w formacie (gg:mm) OR (gg:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"INVALID_NUMERIC": "Deve ser um número positivo. ",
"INVALID_NUMERIC_SIGNED": "Deve ser um número positivo ou negativo. ",
"INVALID_PATTERN": "Deve seguir o seguinte formato: {0}. ",
"INVALID_PATTERN_DATA": "Deve seguir o seguinte formato \"{{data}}\". ",
"INVALID_REQUIRED": "Campo obrigatório. ",
"INVALID_URL": "Deve ser uma URL válida. ",
"INVALID_TIME": "Deve ser um formato de hora válido (hh:mm) ou (hh:mm:ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"INVALID_NUMERIC": "Должно быть положительным числом. ",
"INVALID_NUMERIC_SIGNED": "Должно быть положительным или отрицательным числом. ",
"INVALID_PATTERN": "Должно соответствовать этому формату: {0}. ",
"INVALID_PATTERN_DATA": "Должно соответствовать этому формату \"{{data}}\". ",
"INVALID_REQUIRED": "Поле обязательно для заполнения. ",
"INVALID_URL": "Должно быть действительным URL адресом. ",
"INVALID_TIME": "Должно быть допустимым форматом времени (hh:mm) или (hh:mm:ss). ",
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.3.34",
"version": "1.3.35",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
4 changes: 2 additions & 2 deletions protractor/full_tests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ function loadData() {
},
{
'validator': 'email',
'invalid_data': ['g$g.com', 'g@g,com', 'g@g.'],
'valid_data': ['[email protected]', 'nickname@zone', '[email protected]', 'кокер@спаниель.рф'],
'invalid_data': ['g$g.com', 'g@g,com', '[email protected].', 'some [email protected]'],
'valid_data': ['nickname@domain', '[email protected]', 'кокер@спаниель.рф', 'hola.àáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿ@español.com'],
'error_message': {
'en': "Must be a valid email address.",
'es': "Debe contener una dirección de correo electronico valida.",
Expand Down
2 changes: 1 addition & 1 deletion protractor/mixed_validation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
var errorMessages = [
'Must be a positive or negative number. Field is required.',
'May only contain a positive or negative float value (integer excluded). Needs to be a numeric value, between -0.6 and 99.5. Field is required.',
'Must have a length of exactly 4 characters. Must be following this format: YYWW. Field is required. Must be a positive integer.',
'Must have a length of exactly 4 characters. Field is required. Must be a positive integer. Must be following this format "YYWW".',
'Must be a valid email address. Field is required. Must be at least 6 characters.',
'Must be a valid URL. Field is required.',
'Must be a valid IP (IPV4). Field is required.',
Expand Down
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.3.34`
`Version: 1.3.35`
### Form validation after user inactivity of default 1sec. (customizable timeout)

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 All @@ -13,18 +13,18 @@ Supporting AngularJS 1.3.x *(current code should work with 1.2.x just the same,
Now support <b>Service</b> using the same functionalities as the <b>Directive</b>.
Huge rewrite to have a better code separation and also adding support to Service functionalities. Specifically the `validation-rules` was separated to add rules without affecting the core while `validation-common` is for shared functions (shared by Directive/Service).

[Validation Summary](/ghiscoding/angular-validation/wiki/Validation-Summary) was also recently added to easily show all validation errors that are still active on the form and you can also use 2 ways of dealing with the [Submit and Validation](/ghiscoding/angular-validation/wiki/Form-Submit-and-Validation) button.
[Validation Summary](https://github.com/ghiscoding/angular-validation/wiki/Validation-Summary) was also recently added to easily show all validation errors that are still active on the form and you can also use 2 ways of dealing with the [Submit and Validation](https://github.com/ghiscoding/angular-validation/wiki/Form-Submit-and-Validation) button.

For more reasons to use it, see the answered question of: [Why Use It?](#whyuseit)

If you like the Angular-Validation project and you use it, please click on the **Star** and add it as a favourite. The more star ratings there is, the more chances it could be found by other users inside the popular trend section. That is the only support I ask you... thanks ;)
If you like the Angular-Validation project and you use it, please click on the **Star** and add it as a favorite. The more star ratings there is, the more chances it could be found by other users inside the popular trend section. That is the only support I ask you... thanks and enjoy it ;)

<a name="plunker"></a>
## Live Demo
[Plunker](http://plnkr.co/jADq7H)

## Tested with Protractor
Angular-validation now has a full set of End-to-End tests with Protractor, there is over 1600+ assertions, it starts by testing the original live demo page and then goes on with a complete test suite of All Validators in both the Angular-Validation Directive and Service.
Angular-validation now has a full set of **End-to-End tests** with **Protractor**, there is over 1600+ assertions, it starts by testing the original live demo page and then goes on with a complete test suite of All Validators in both the Angular-Validation Directive and Service.

<a name="whyuseit"></a>
Why use angular-validation?
Expand Down Expand Up @@ -56,7 +56,7 @@ into the following (errors will automatically be displayed in your chosen locale
```
The Angular-Validation will create, by itself, the necessary error message. Now imagine your form having 10 inputs, using the documented Angular way will end up being 30 lines of code, while on the other hand `Angular-Validation` will stay with 10 lines of code, no more... so what are you waiting for? Use Angular-Validation!!! Don't forget to add it to your favorite, click on the **Star** on top :)

Let's not forget the [Validation Summary](/ghiscoding/angular-validation/wiki/Validation-Summary) which is also a great and useful way of displaying your errors to the user.
Let's not forget the [Validation Summary](https://github.com/ghiscoding/angular-validation/wiki/Validation-Summary) which is also a great and useful way of displaying your errors to the user.

Another awesome feature recently added is the [Remote Validation (AJAX)](https://github.com/ghiscoding/angular-validation/wiki/Remote-Validation-(AJAX)) which is so convenient.

Expand Down Expand Up @@ -87,7 +87,7 @@ All the documentation has been moved to the Wiki section, see the [github wiki](
* [Global Options](https://github.com/ghiscoding/angular-validation/wiki/Global-Options)
* Validators
* [Available Validator Rules](https://github.com/ghiscoding/angular-validation/wiki/Available-Validators-(rules))
* [Regular Expression](https://github.com/ghiscoding/angular-validation/wiki/Regular-Expressions-(Regex))
* [Regular Expression Pattern](https://github.com/ghiscoding/angular-validation/wiki/Regular-Expression-Pattern)
* Misc
* [Changelog](https://github.com/ghiscoding/angular-validation/wiki/CHANGELOG)
* [License](https://github.com/ghiscoding/angular-validation/wiki/License)
Expand Down Expand Up @@ -170,7 +170,7 @@ All validators are written as `snake_case` but it's up to the user's taste and c
* `ipv4` Check for valid IP (IPv4)
* `ipv6` Check for valid IP (IPv6)
* `match:n` Match another input field(n), where (n) must be the exact ngModel attribute of input field to compare to.
* `match:n,t` Match another input field(n), same as (match:n) but also include (t) for alternate input name to be displayed in the error message (it still uses default translated text, if you really wish to replace the complete text error, then use [:alt](#alternate))
* `match:n,t` Match another input field(n), same as (match:n) but also include (t) for alternate input name to be displayed in the error message (it still uses default translated text, if you really wish to replace the complete text error, then use [:alt](https://github.com/ghiscoding/angular-validation/wiki/Alternate-Text-on-Validators))
* `max_date_iso` alias of `date_iso_max`.
* `max_date_euro_long` alias of `date_euro_long_max`.
* `max_date_euro_short` alias of `date_euro_short_max`.
Expand All @@ -187,7 +187,7 @@ All validators are written as `snake_case` but it's up to the user's taste and c
* `min_num:n` Checks numeric value to be higher or equal than the number (n).
* `numeric` Only positive numeric value (float, integer).
* `numeric_signed` Only numeric value (float, integer) can also be signed (-/+).
* `regex` Ensure it follows a regular expression pattern... please see [Regex](#regex) section
* `pattern` Ensure it follows a regular expression pattern... please see [Regular Expression Pattern](https://github.com/ghiscoding/angular-validation/wiki/Regular-Expression-Pattern)
* `required` Ensures the specified key value exists and is not empty
* `time` Ensure time follows the format of (hh:mm) or (hh:mm:ss)
* `url` Check for valid URL or subdomain
Loading

0 comments on commit b58fbc1

Please sign in to comment.