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

Commit

Permalink
Added C# validation annotation
Browse files Browse the repository at this point in the history
Add more aliases for a few validators to fit the ones in C# validation
annotation.
  • Loading branch information
ghiscoding committed Jul 21, 2016
1 parent f50b6f3 commit 7389b4d
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 36 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.2",
"version": "1.5.3",
"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.5.3 (2016-07-20) Add C# validation annotation, (for example: maxLen => maxLength)
1.5.2 (2016-06-14) Fixed #121 Alternate text containing the char ":" was causing unexpected displayed message.
1.5.1 (2016-03-10) Fixed #111 Add US phone number & tweaked credit card rules.
1.5.0 (2016-03-10) BREAKING CHANGE when fixing casing issue #107, ValidationService should start with uppercase. Changed to branch 1.5.x to announce major change.
Expand Down
10 changes: 5 additions & 5 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions more-examples/addon-3rdParty/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,15 @@ myApp.controller('Ctrl', ['ValidationService', function (ValidationService) {
{ name: "Safari", maker: "Apple", ticked: false, icon: "<img src='https://cdn1.iconfinder.com/data/icons/fatcow/32x32/safari_browser.png' />" },
{ name: "Chrome", maker: "Google", ticked: false, icon: "<img src='https://cdn1.iconfinder.com/data/icons/google_jfk_icons_by_carlosjj/32/chrome.png' />" }
];

// declare public functions
vm.submit = submit;

return vm;

function submit() {
if(new ValidationService().checkFormValidity(vm.test)) {
alert('valid');
}
}
}]);
4 changes: 2 additions & 2 deletions more-examples/addon-3rdParty/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ <h4><strong>ERRORS!</strong></h4>
</form>
<hr/>
<div class="form-actions">
<button type="submit" name="save_btn" class="btn btn-primary" ng-disabled="vm.test.$invalid" ng-click="">{{ 'SAVE' | translate }}</button>
<button type="submit" name="save_btn" class="btn btn-primary" ng-click="vm.submit()">{{ 'SAVE' | translate }}</button>
</div>
<hr/>

<div class="alert alert-warning alert-dismissable">
<strong>We can validate an input array by 2 ways:</strong>
<ol>
<li>&lt;valid-array-require-how-many="<b>one</b>"&gt; (default), if 1 value is found good, the complete input set is Valid.</li>
<li>&lt;valid-array-require-how-many="<b>one</b>"&gt; (default), if 1 value is found as valid, the complete input set is Valid.</li>
<li>&lt;valid-array-require-how-many="<b>all</b>"&gt;. For the input to be Valid, we need "all" array values to be valid.</li>
</ol>
</div>
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.2",
"version": "1.5.3",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
62 changes: 35 additions & 27 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.5.2`
`Version: 1.5.3`
### Forms Validation with Angular made easy!
##### (Concept comes from the amazing Laravel)

Expand Down Expand Up @@ -144,16 +144,17 @@ All validators are written as `snake_case` but it's up to the user's taste and c
* `alpha_num_spaces` Only alpha-numeric characters (with latin & spaces) are present (a-z, A-Z, 0-9)
* `alpha_dash` Only alpha-numeric characters + dashes, underscores are present (a-z, A-Z, 0-9, _-)
* `alpha_dash_spaces` Alpha-numeric chars + dashes, underscores and spaces (a-z, A-Z, 0-9, _-)
* `between:min,max` will auto-detect value type then use proper validator.
* `between:min,max` Will auto-detect value type then use proper validator.
* Type Number uses `between_num`, String use `between_len`.
* `between_date_iso:d1,d2` alias of `between_date_iso`.
* `between_date_euro_long:d1,d2` alias of `date_euro_long_between`.
* `between_date_euro_short:d1,d2` alias of `date_euro_short_between`.
* `between_date_us_long:d1,d2` alias of `date_us_long_between`.
* `between_date_us_short:d1,d2` alias of `date_us_short_between`.
* `between_date_iso:d1,d2` Alias of `between_date_iso`.
* `between_date_euro_long:d1,d2` Alias of `date_euro_long_between`.
* `between_date_euro_short:d1,d2` Alias of `date_euro_short_between`.
* `between_date_us_long:d1,d2` Alias of `date_us_long_between`.
* `between_date_us_short:d1,d2` Alias of `date_us_short_between`.
* `between_len:min,max` Ensures the length of a string is between a min,max length.
* `between_num:min,max` Ensures the numeric value (int or float) is between a min,max number.
* `boolean` Ensures the value is `true` or `false` (`0` or `1` is also valid).
* `compare` Alias of `match`
* `credit_card` Valid credit card number (AMEX, VISA, Mastercard, Diner's Club, Discover, JCB)
* `date_iso` Ensure date follows the ISO format (yyyy-mm-dd)
* `date_iso_between:d1,d2` Ensure date follows the ISO format and is between (d1) &amp; (d2)
Expand All @@ -175,55 +176,62 @@ All validators are written as `snake_case` but it's up to the user's taste and c
* `date_us_short_between:d1,d2` Date must follow the US short format and is between (d1) &amp; (d2)
* `date_us_short_max:d` Date must follow US short format and is lower or equal than date (d)
* `date_us_short_min:d` Date must follow US short format and is higher or equal than date (d)
* `different` alias of `different_input`
* `different` Alias of `different_input`
* `different_input:f` Must be different from another input field(f), where (f) must be the exact ngModel attribute of input field to compare to. The error message will use the input name or the `friendly-name` if it was provided on first input, ex.: `<input friendly-name="First Name".../>` will display :: *Field must be different from specified field "First Name"*.
* `different_input:f,t` Must be different from another input field(f), same as (different:f) but also include (t) for alternate input name to be displayed in the error message (it still uses a generic error message, if you really wish to replace the full error message then you should use `match:n:alt` see [:alt](https://github.com/ghiscoding/angular-validation/wiki/Alternate-Text-on-Validators))
* `digits:n` Ensures that field only has integer numbers and length precisely matches the specified length (n).
* `digits_between:min,max` Ensures that field only has integer numbers and is between a min,max length.
* `email` Checks for a valid email address
* `email_address` Alias of `email`
* `enum` Alias of `in_list`
* `exact_len:n` Ensures that field length precisely matches the specified length (n).
* `float` as to be floating value (excluding integer)
* `float_signed` Has to be floating value (excluding int), could be signed (-/+) positive/negative.
* ~~`iban`~~ To properly validate an IBAN please use [Wiki - Custom Validation](https://github.com/ghiscoding/angular-validation/wiki/Custom-Validation-functions) with an external library like [Github arhs/iban.js](https://github.com/arhs/iban.js)

* `in` alias of `in_list`
* `in` Alias of `in_list`
* `in_list:foo,bar,..` Ensures the value is included inside the given list of values. The list must be separated by ',' and also accept words with spaces for example "ice cream".
* `int` Only positive integer (alias to `integer`).
* `integer` Only positive integer.
* `int_signed` Only integer, could be signed (-/+) positive/negative (alias to `integer_signed`).
* `integer_signed` Only integer, could be signed (-/+) positive/negative.
* `ip` alias of `ipv4`
* `ip` Alias of `ipv4`
* `ipv4` Check for valid IP (IPv4)
* `ipv6` Check for valid IP (IPv6)
* `match:f` Match another input field(f), where (f) must be the exact ngModel attribute of input field to compare to. The error message will use the `friendly-name` if it was provided on first input, ex.: `<input friendly-name="Password".../>` will display :: *Confirmation field does not match specified field "Password"*.
* `match:f,t` Match another input field(f), same as (match:f) but also include (t) for alternate input name to be displayed in the error message (it still uses a generic error message, if you really wish to replace the full error message then you should use `match:n:alt` see [:alt](https://github.com/ghiscoding/angular-validation/wiki/Alternate-Text-on-Validators))
* `match_input` alias of `match`.
* `max:n` will auto-detect value type then use proper validator.
* `match_input` Alias of `match`.
* `max:n` Will auto-detect value type then use proper validator.
* Type Number uses `max_num`, String use `max_len`.
* `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`.
* `max_date_us_long` alias of `date_us_long_max`.
* `max_date_us_short` alias of `date_us_short_max`.
* `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`.
* `max_date_us_long` Alias of `date_us_long_max`.
* `max_date_us_short` Alias of `date_us_short_max`.
* `max_len:n` Checks field length, no longer than specified length where (n) is length parameter.
* `max_length:n` Alias of `max_len`
* `max_num:n` Checks numeric value to be lower or equal than the number (n).
* `min:n` will auto-detect value type then use proper validator.
* `min:n` Will auto-detect value type then use proper validator.
* Type Number uses `min_num`, String use `min_len`.
* `min_date_iso` alias of `date_iso_min`.
* `min_date_euro_long` alias of `date_euro_long_min`.
* `min_date_euro_short` alias of `date_euro_short_min`.
* `min_date_us_long` alias of `date_us_long_min`.
* `min_date_us_short` alias of `date_us_short_min`.
* `min_date_iso` Alias of `date_iso_min`.
* `min_date_euro_long` Alias of `date_euro_long_min`.
* `min_date_euro_short` Alias of `date_euro_short_min`.
* `min_date_us_long` Alias of `date_us_long_min`.
* `min_date_us_short` Alias of `date_us_short_min`.
* `min_len:n` Checks field length, no shorter than specified length where (n) is length parameter.
* `min_length:n` Alias of `min_len`
* `min_num:n` Checks numeric value to be higher or equal than the number (n).
* `not_in` alias of `not_in_list`
* `not_in` Alias of `not_in_list`
* `not_in_list:foo,bar,..` Ensures the value is included inside the given list of values. The list must be separated by ',' and also accept words with spaces for example "ice cream".
* `numeric` Only positive numeric value (float, integer).
* `numeric_signed` Only numeric value (float, integer) can also be signed (-/+).
* `pattern` Ensure it follows a regular expression pattern... please see [Regular Expression Pattern](https://github.com/ghiscoding/angular-validation/wiki/Regular-Expression-Pattern)
* `pattern` Ensure it follows a regular expression pattern... Refer to [Wiki - Regular Expression Pattern](https://github.com/ghiscoding/angular-validation/wiki/Regular-Expression-Pattern) on how to use it.
* `range` Alias of `between`
* `required` Ensures the specified key value exists and is not empty
* `same` alias of `match`.
* `size` will auto-detect value type then use proper validator.
* `same` Alias of `match`.
* `size` Will auto-detect value type then use proper validator.
* Type Number uses `exact_num`, String use `exact_len`.
* `string_len` Alias of `between_len`
* `string_length` Alias of `between_len`
* `time` Ensure time follows the format of (hh:mm) or (hh:mm:ss)
* `url` Check for valid URL or subdomain
13 changes: 13 additions & 0 deletions src/validation-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ angular
};
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";
Expand All @@ -107,6 +108,10 @@ angular
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";
Expand Down Expand Up @@ -449,6 +454,8 @@ angular
};
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
Expand Down Expand Up @@ -488,6 +495,7 @@ angular
type: "regex"
};
break;
case "enum" :
case "in" :
case "inList" :
case "in_list" :
Expand Down Expand Up @@ -533,6 +541,7 @@ angular
type: "regex"
};
break;
case "compare" :
case "match" :
case "matchInput" :
case "match_input" :
Expand All @@ -557,6 +566,8 @@ angular
break;
case "maxLen" :
case "max_len" :
case "maxLength" :
case "max_length" :
validator = {
pattern: "^(.|[\\r\\n]){0," + ruleParams + "}$",
message: "INVALID_MAX_CHAR",
Expand Down Expand Up @@ -585,6 +596,8 @@ angular
break;
case "minLen" :
case "min_len" :
case "minLength" :
case "min_length" :
validator = {
pattern: "^(.|[\\r\\n]){" + ruleParams + ",}$",
message: "INVALID_MIN_CHAR",
Expand Down

0 comments on commit 7389b4d

Please sign in to comment.