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

Commit

Permalink
#111 Add US phone & tweaked credit card rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Mar 11, 2016
1 parent 7d64caf commit 30e5f75
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 20 deletions.
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.5.0",
"version": "1.5.1",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions full-tests/Service.html
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ <h4><strong>{{ 'ERRORS' | translate }}!</strong></h4>
<label for="input126">input126</label>
<input class="form-control" type="text" name="input126" ng-model="input126">
</div>
<div class="form-group row">
<label for="input127">input127</label>
<input class="form-control" type="text" name="input127" ng-model="input127">
</div>

</fieldset>

Expand Down
3 changes: 3 additions & 0 deletions full-tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ function loadData() {
'validator': 'numericSigned',
'aliases': ['numeric_signed']
},
{
'validator': 'phone'
},
{
'validator': 'url'
},
Expand Down
4 changes: 2 additions & 2 deletions full-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
<ng-view></ng-view>

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

<!-- angular-translate -->
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ <h1>Angular-Validation Directive|Service (ghiscoding)</h1>
<ng-view></ng-view>

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

<!-- angular-translate -->
<!-- Visit Angular-Translate https://github.com/PascalPrecht/angular-translate -->
Expand Down
1 change: 1 addition & 0 deletions locales/validation/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"INVALID_NUMERIC_SIGNED": "Ha de contenir un valor numèric positiu o negatiu. ",
"INVALID_PATTERN": "Ha de contenir un text amb el format: {0}. ",
"INVALID_PATTERN_DATA": "Ha de contenir un text amb el format {{data}}. ",
"INVALID_PHONE_US": "Ha de ser un número de telèfon vàlid i ha d'incloure el codi d'àrea. ",
"INVALID_REQUIRED": "Camp requerit. ",
"INVALID_URL": "Ha de contenir una adreça URL vàlida. ",
"INVALID_TIME": "Ha de tenir un format de temps vàlid (hh: mm) o (hh: mm: ss). ",
Expand Down
1 change: 1 addition & 0 deletions locales/validation/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"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_PHONE_US": "Must be a valid phone number and must include area code. ",
"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/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"INVALID_NUMERIC_SIGNED": "Debe contener un valor númerico positivo ó negativo. ",
"INVALID_PATTERN": "Debe contener un texto con el formato: {0}. ",
"INVALID_PATTERN_DATA": "Debe contener un texto con el formato {{data}}. ",
"INVALID_PHONE_US": "Debe ser un número de teléfono válido y debe incluir el código de área. ",
"INVALID_REQUIRED": "Campo requerido. ",
"INVALID_URL": "Debe contener una dirección URL válida. ",
"INVALID_TIME": "Debe contener un formato de tiempo válido (hh:mm) ó (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 @@ -56,6 +56,7 @@
"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_PHONE_US": "Doit être un numéro de téléphone valide et doit inclure le code régional. ",
"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 @@ -56,6 +56,7 @@
"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_PHONE_US": "Må være et gyldig telefonnummer og inkluderer retningsnummer. ",
"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 @@ -56,6 +56,7 @@
"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_PHONE_US": "Musi być prawidłowy numer telefonu i musi zawierać numer kierunkowy. ",
"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 @@ -56,6 +56,7 @@
"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_PHONE_US": "Deve ser um número de telefone válido e incluir o código de área. ",
"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 @@ -56,6 +56,7 @@
"INVALID_NUMERIC_SIGNED": "Должно быть положительным или отрицательным числом. ",
"INVALID_PATTERN": "Должно соответствовать этому формату: {0}. ",
"INVALID_PATTERN_DATA": "Должно соответствовать этому формату {{data}}. ",
"INVALID_PHONE_US": "Должно быть допустимым номером телефона и должен включать в себя код города. ",
"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.5.0",
"version": "1.5.1",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
4 changes: 2 additions & 2 deletions protractor/badInput_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Angular-Validation badInput Tests:', function () {
// make input3 invalid, remove text
var elmInput2 = $('[name=input2]');
elmInput2.click();
elmInput2.sendKeys('2.5.');
elmInput2.sendKeys('2.5..');

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

// error should appear on input2
Expand Down
16 changes: 14 additions & 2 deletions protractor/full_tests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ function loadData() {
{
'validator': 'creditCard',
'aliases': ['credit_card'],
'invalid_data': ['4538 1212 2020 3030', '4538-1212-2020-3030', '121233334444'],
'valid_data': ['4538121220203030', '4538123456789012'],
'invalid_data': ['30-5693-0902-5904', '31169309025904'],
'valid_data': ['4538 1212 2020 3030', '5431-1111-1111-1111', '30569309025904', '4538123456789012'],
'error_message': {
'en': "Must be a valid credit card number.",
'es': "Debe contener un número de tarjeta de crédito valido.",
Expand Down Expand Up @@ -809,6 +809,18 @@ function loadData() {
'ru': "Должно быть положительным или отрицательным числом."
}
},
{
'validator': 'phone',
'invalid_data': ['1-800-123-456', '123-456-789', '1234567890'],
'valid_data': ['1-800-123-4567', '123-456-7890', '(123) 456-7890'],
'error_message': {
'en': "Must be a valid phone number and must include area code.",
'es': "Debe ser un número de teléfono válido y debe incluir el código de área.",
'fr': "Doit être un numéro de téléphone valide et doit inclure le code régional.",
'no': "Må være et gyldig telefonnummer og inkluderer retningsnummer.",
'ru': "Должен быть действительный телефонный номер и включают в себя код города."
}
},
{
'validator': 'url',
'invalid_data': ['htp://www.future.com', 'fp://www.future.com', 'http:www.future.com'],
Expand Down
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#Angular Validation (Directive / Service)
`Version: 1.5.0`
### Form validation after user stop typing (default 1sec).
`Version: 1.5.1`
### Forms Validation with Angular made easy!
##### (Concept comes from the amazing Laravel)

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!
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!

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.
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.

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.

Supporting AngularJS 1.3/1.4 branch *(current code should work with 1.2.x just the same, but is no more verified)*
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)*

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).
Expand Down
9 changes: 8 additions & 1 deletion src/validation-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ angular
case "creditCard" :
case "credit_card" :
validator = {
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})$/,
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"
};
Expand Down Expand Up @@ -629,6 +629,13 @@ angular
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 "pattern" :
case "regex" :
// Custom User Regex is a special case, the properties (message, pattern) were created and dealt separately prior to the for loop
Expand Down

0 comments on commit 30e5f75

Please sign in to comment.