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

Commit 30e5f75

Browse files
committed
#111 Add US phone & tweaked credit card rules
1 parent 7d64caf commit 30e5f75

19 files changed

+55
-20
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": [

dist/angular-validation.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

full-tests/Service.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ <h4><strong>{{ 'ERRORS' | translate }}!</strong></h4>
527527
<label for="input126">input126</label>
528528
<input class="form-control" type="text" name="input126" ng-model="input126">
529529
</div>
530+
<div class="form-group row">
531+
<label for="input127">input127</label>
532+
<input class="form-control" type="text" name="input127" ng-model="input127">
533+
</div>
530534

531535
</fieldset>
532536

full-tests/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ function loadData() {
333333
'validator': 'numericSigned',
334334
'aliases': ['numeric_signed']
335335
},
336+
{
337+
'validator': 'phone'
338+
},
336339
{
337340
'validator': 'url'
338341
},

full-tests/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
3535
<ng-view></ng-view>
3636

3737
<!-- external librairies CDN -->
38-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
39-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
38+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
39+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.js"></script>
4040

4141
<!-- angular-translate -->
4242
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
4040
<ng-view></ng-view>
4141

4242
<!-- external librairies CDN -->
43-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
44-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
45-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-sanitize.js"></script>
43+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
44+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.js"></script>
45+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-sanitize.js"></script>
4646

4747
<!-- angular-translate -->
4848
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->

locales/validation/ca.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Ha de contenir un valor numèric positiu o negatiu. ",
5757
"INVALID_PATTERN": "Ha de contenir un text amb el format: {0}. ",
5858
"INVALID_PATTERN_DATA": "Ha de contenir un text amb el format {{data}}. ",
59+
"INVALID_PHONE_US": "Ha de ser un número de telèfon vàlid i ha d'incloure el codi d'àrea. ",
5960
"INVALID_REQUIRED": "Camp requerit. ",
6061
"INVALID_URL": "Ha de contenir una adreça URL vàlida. ",
6162
"INVALID_TIME": "Ha de tenir un format de temps vàlid (hh: mm) o (hh: mm: ss). ",

locales/validation/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Must be a positive or negative number. ",
5757
"INVALID_PATTERN": "Must be following this format: {0}. ",
5858
"INVALID_PATTERN_DATA": "Must be following this format {{data}}. ",
59+
"INVALID_PHONE_US": "Must be a valid phone number and must include area code. ",
5960
"INVALID_REQUIRED": "Field is required. ",
6061
"INVALID_URL": "Must be a valid URL. ",
6162
"INVALID_TIME": "Must be a valid time format (hh:mm) OR (hh:mm:ss). ",

locales/validation/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Debe contener un valor númerico positivo ó negativo. ",
5757
"INVALID_PATTERN": "Debe contener un texto con el formato: {0}. ",
5858
"INVALID_PATTERN_DATA": "Debe contener un texto con el formato {{data}}. ",
59+
"INVALID_PHONE_US": "Debe ser un número de teléfono válido y debe incluir el código de área. ",
5960
"INVALID_REQUIRED": "Campo requerido. ",
6061
"INVALID_URL": "Debe contener una dirección URL válida. ",
6162
"INVALID_TIME": "Debe contener un formato de tiempo válido (hh:mm) ó (hh:mm:ss). ",

locales/validation/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Doit être un nombre positif ou négatif. ",
5757
"INVALID_PATTERN": "Doit suivre le format: {0}. ",
5858
"INVALID_PATTERN_DATA": "Doit suivre le format {{data}}. ",
59+
"INVALID_PHONE_US": "Doit être un numéro de téléphone valide et doit inclure le code régional. ",
5960
"INVALID_REQUIRED": "Le champ est requis. ",
6061
"INVALID_URL": "Doit être un URL valide. ",
6162
"INVALID_TIME": "Doit être un format de temps valide (hh:mm) OU (hh:mm:ss). ",

locales/validation/no.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Må være et positivt eller negativt tall. ",
5757
"INVALID_PATTERN": "Må være på følgende format: {0}. ",
5858
"INVALID_PATTERN_DATA": "Må være på følgende format {{data}}. ",
59+
"INVALID_PHONE_US": "Må være et gyldig telefonnummer og inkluderer retningsnummer. ",
5960
"INVALID_REQUIRED": "Feltet er påkrevd. ",
6061
"INVALID_URL": "Må være en gyldig URL. ",
6162
"INVALID_TIME": "Må være et gyldig tidsformat (tt:mm) OR (tt:mm:ss). ",

locales/validation/pl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Musi być liczbą dodatnią lub ujemną. ",
5757
"INVALID_PATTERN": "Musi być zgodne z formatem: {0}. ",
5858
"INVALID_PATTERN_DATA": "Musi być zgodne z formatem {{data}}. ",
59+
"INVALID_PHONE_US": "Musi być prawidłowy numer telefonu i musi zawierać numer kierunkowy. ",
5960
"INVALID_REQUIRED": "Pole jest wymagane. ",
6061
"INVALID_URL": "Musi być poprawnym adresem URL. ",
6162
"INVALID_TIME": "Musi być poprawną godziną w formacie (gg:mm) OR (gg:mm:ss). ",

locales/validation/pt-br.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Deve ser um número positivo ou negativo. ",
5757
"INVALID_PATTERN": "Deve seguir o seguinte formato: {0}. ",
5858
"INVALID_PATTERN_DATA": "Deve seguir o seguinte formato {{data}}. ",
59+
"INVALID_PHONE_US": "Deve ser um número de telefone válido e incluir o código de área. ",
5960
"INVALID_REQUIRED": "Campo obrigatório. ",
6061
"INVALID_URL": "Deve ser uma URL válida. ",
6162
"INVALID_TIME": "Deve ser um formato de hora válido (hh:mm) ou (hh:mm:ss). ",

locales/validation/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"INVALID_NUMERIC_SIGNED": "Должно быть положительным или отрицательным числом. ",
5757
"INVALID_PATTERN": "Должно соответствовать этому формату: {0}. ",
5858
"INVALID_PATTERN_DATA": "Должно соответствовать этому формату {{data}}. ",
59+
"INVALID_PHONE_US": "Должно быть допустимым номером телефона и должен включать в себя код города. ",
5960
"INVALID_REQUIRED": "Поле обязательно для заполнения. ",
6061
"INVALID_URL": "Должно быть действительным URL адресом. ",
6162
"INVALID_TIME": "Должно быть допустимым форматом времени (hh:mm) или (hh:mm:ss). ",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "app.js",

protractor/badInput_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('Angular-Validation badInput Tests:', function () {
3434
// make input3 invalid, remove text
3535
var elmInput2 = $('[name=input2]');
3636
elmInput2.click();
37-
elmInput2.sendKeys('2.5.');
37+
elmInput2.sendKeys('2.5..');
3838

3939
// error should appear on input2
4040
var elmError2 = $('.validation-input2');
@@ -94,7 +94,7 @@ describe('Angular-Validation badInput Tests:', function () {
9494
// make input3 invalid, remove text
9595
var elmInput2 = $('[name=input2]');
9696
elmInput2.click();
97-
clearInput(elmInput2, 4);
97+
clearInput(elmInput2, 5);
9898
elmInput2.sendKeys(protractor.Key.TAB);
9999

100100
// error should appear on input2

protractor/full_tests_spec.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ function loadData() {
273273
{
274274
'validator': 'creditCard',
275275
'aliases': ['credit_card'],
276-
'invalid_data': ['4538 1212 2020 3030', '4538-1212-2020-3030', '121233334444'],
277-
'valid_data': ['4538121220203030', '4538123456789012'],
276+
'invalid_data': ['30-5693-0902-5904', '31169309025904'],
277+
'valid_data': ['4538 1212 2020 3030', '5431-1111-1111-1111', '30569309025904', '4538123456789012'],
278278
'error_message': {
279279
'en': "Must be a valid credit card number.",
280280
'es': "Debe contener un número de tarjeta de crédito valido.",
@@ -809,6 +809,18 @@ function loadData() {
809809
'ru': "Должно быть положительным или отрицательным числом."
810810
}
811811
},
812+
{
813+
'validator': 'phone',
814+
'invalid_data': ['1-800-123-456', '123-456-789', '1234567890'],
815+
'valid_data': ['1-800-123-4567', '123-456-7890', '(123) 456-7890'],
816+
'error_message': {
817+
'en': "Must be a valid phone number and must include area code.",
818+
'es': "Debe ser un número de teléfono válido y debe incluir el código de área.",
819+
'fr': "Doit être un numéro de téléphone valide et doit inclure le code régional.",
820+
'no': "Må være et gyldig telefonnummer og inkluderer retningsnummer.",
821+
'ru': "Должен быть действительный телефонный номер и включают в себя код города."
822+
}
823+
},
812824
{
813825
'validator': 'url',
814826
'invalid_data': ['htp://www.future.com', 'fp://www.future.com', 'http:www.future.com'],

readme.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#Angular Validation (Directive / Service)
2-
`Version: 1.5.0`
3-
### Form validation after user stop typing (default 1sec).
2+
`Version: 1.5.1`
3+
### Forms Validation with Angular made easy!
4+
##### (Concept comes from the amazing Laravel)
45

5-
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!
6+
Form validation after user stop typing (debounce default of 1sec). 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!
67

7-
The base concept is not new, it comes from the easy form input validation approach of Laravel Framework as well as PHP Gump Validation. They both are built in PHP and use a very simple approach, so why not use the same concept over Angular as well? Well now it is available with few more extras.
8+
The base concept is not new, it comes from the easy form input validation approach of Laravel Framework as well as PHP Gump Validation. They are both PHP frameworks and use a very simple approach, so why not re-use the same concept over Angular as well? Well it's now made available with a few more extras.
89

910
For a smoother user experience, I also added validation on inactivity (timer/debounce). So validation will not bother the user while he is still typing... though as soon as the user pauses for a certain amount of time, then validation comes into play. It's worth knowing that this inactivity timer is only available while typing, if user focuses away from his input (onBlur) it will then validate instantly.
1011

11-
Supporting AngularJS 1.3/1.4 branch *(current code should work with 1.2.x just the same, but is no more verified)*
12+
Supporting AngularJS 1.3.x-1.5.x branch *(current code should work with 1.2.x just the same, but is no more verified)*
1213

1314
Now support <b>Service</b> using the same functionalities as the <b>Directive</b>.
1415
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).

src/validation-rules.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ angular
148148
case "creditCard" :
149149
case "credit_card" :
150150
validator = {
151-
pattern: /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/,
151+
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}$/,
152152
message: "INVALID_CREDIT_CARD",
153153
type: "regex"
154154
};
@@ -629,6 +629,13 @@ angular
629629
type: "regex"
630630
};
631631
break;
632+
case "phone" :
633+
validator = {
634+
pattern: /^([0-9]( |[-.])?)?((\(\d{3}\) ?)|(\d{3}[-.]))?\d{3}[-.]\d{4}$/,
635+
message: "INVALID_PHONE_US",
636+
type: "regex"
637+
};
638+
break;
632639
case "pattern" :
633640
case "regex" :
634641
// Custom User Regex is a special case, the properties (message, pattern) were created and dealt separately prior to the for loop

0 commit comments

Comments
 (0)