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

Commit 7389b4d

Browse files
committed
Added C# validation annotation
Add more aliases for a few validators to fit the ones in C# validation annotation.
1 parent f50b6f3 commit 7389b4d

File tree

8 files changed

+69
-36
lines changed

8 files changed

+69
-36
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.2",
3+
"version": "1.5.3",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": [

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Angular-Validation change logs
22

3+
1.5.3 (2016-07-20) Add C# validation annotation, (for example: maxLen => maxLength)
34
1.5.2 (2016-06-14) Fixed #121 Alternate text containing the char ":" was causing unexpected displayed message.
45
1.5.1 (2016-03-10) Fixed #111 Add US phone number & tweaked credit card rules.
56
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.

dist/angular-validation.min.js

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

more-examples/addon-3rdParty/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ myApp.controller('Ctrl', ['ValidationService', function (ValidationService) {
4444
{ name: "Safari", maker: "Apple", ticked: false, icon: "<img src='https://cdn1.iconfinder.com/data/icons/fatcow/32x32/safari_browser.png' />" },
4545
{ name: "Chrome", maker: "Google", ticked: false, icon: "<img src='https://cdn1.iconfinder.com/data/icons/google_jfk_icons_by_carlosjj/32/chrome.png' />" }
4646
];
47+
48+
// declare public functions
49+
vm.submit = submit;
50+
51+
return vm;
52+
53+
function submit() {
54+
if(new ValidationService().checkFormValidity(vm.test)) {
55+
alert('valid');
56+
}
57+
}
4758
}]);

more-examples/addon-3rdParty/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ <h4><strong>ERRORS!</strong></h4>
9191
</form>
9292
<hr/>
9393
<div class="form-actions">
94-
<button type="submit" name="save_btn" class="btn btn-primary" ng-disabled="vm.test.$invalid" ng-click="">{{ 'SAVE' | translate }}</button>
94+
<button type="submit" name="save_btn" class="btn btn-primary" ng-click="vm.submit()">{{ 'SAVE' | translate }}</button>
9595
</div>
9696
<hr/>
9797

9898
<div class="alert alert-warning alert-dismissable">
9999
<strong>We can validate an input array by 2 ways:</strong>
100100
<ol>
101-
<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>
101+
<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>
102102
<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>
103103
</ol>
104104
</div>

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.2",
3+
"version": "1.5.3",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "app.js",

readme.md

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Angular Validation (Directive / Service)
2-
`Version: 1.5.2`
2+
`Version: 1.5.3`
33
### Forms Validation with Angular made easy!
44
##### (Concept comes from the amazing Laravel)
55

@@ -144,16 +144,17 @@ All validators are written as `snake_case` but it's up to the user's taste and c
144144
* `alpha_num_spaces` Only alpha-numeric characters (with latin & spaces) are present (a-z, A-Z, 0-9)
145145
* `alpha_dash` Only alpha-numeric characters + dashes, underscores are present (a-z, A-Z, 0-9, _-)
146146
* `alpha_dash_spaces` Alpha-numeric chars + dashes, underscores and spaces (a-z, A-Z, 0-9, _-)
147-
* `between:min,max` will auto-detect value type then use proper validator.
147+
* `between:min,max` Will auto-detect value type then use proper validator.
148148
* Type Number uses `between_num`, String use `between_len`.
149-
* `between_date_iso:d1,d2` alias of `between_date_iso`.
150-
* `between_date_euro_long:d1,d2` alias of `date_euro_long_between`.
151-
* `between_date_euro_short:d1,d2` alias of `date_euro_short_between`.
152-
* `between_date_us_long:d1,d2` alias of `date_us_long_between`.
153-
* `between_date_us_short:d1,d2` alias of `date_us_short_between`.
149+
* `between_date_iso:d1,d2` Alias of `between_date_iso`.
150+
* `between_date_euro_long:d1,d2` Alias of `date_euro_long_between`.
151+
* `between_date_euro_short:d1,d2` Alias of `date_euro_short_between`.
152+
* `between_date_us_long:d1,d2` Alias of `date_us_long_between`.
153+
* `between_date_us_short:d1,d2` Alias of `date_us_short_between`.
154154
* `between_len:min,max` Ensures the length of a string is between a min,max length.
155155
* `between_num:min,max` Ensures the numeric value (int or float) is between a min,max number.
156156
* `boolean` Ensures the value is `true` or `false` (`0` or `1` is also valid).
157+
* `compare` Alias of `match`
157158
* `credit_card` Valid credit card number (AMEX, VISA, Mastercard, Diner's Club, Discover, JCB)
158159
* `date_iso` Ensure date follows the ISO format (yyyy-mm-dd)
159160
* `date_iso_between:d1,d2` Ensure date follows the ISO format and is between (d1) &amp; (d2)
@@ -175,55 +176,62 @@ All validators are written as `snake_case` but it's up to the user's taste and c
175176
* `date_us_short_between:d1,d2` Date must follow the US short format and is between (d1) &amp; (d2)
176177
* `date_us_short_max:d` Date must follow US short format and is lower or equal than date (d)
177178
* `date_us_short_min:d` Date must follow US short format and is higher or equal than date (d)
178-
* `different` alias of `different_input`
179+
* `different` Alias of `different_input`
179180
* `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"*.
180181
* `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))
181182
* `digits:n` Ensures that field only has integer numbers and length precisely matches the specified length (n).
182183
* `digits_between:min,max` Ensures that field only has integer numbers and is between a min,max length.
183184
* `email` Checks for a valid email address
185+
* `email_address` Alias of `email`
186+
* `enum` Alias of `in_list`
184187
* `exact_len:n` Ensures that field length precisely matches the specified length (n).
185188
* `float` as to be floating value (excluding integer)
186189
* `float_signed` Has to be floating value (excluding int), could be signed (-/+) positive/negative.
187190
* ~~`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)
188191

189-
* `in` alias of `in_list`
192+
* `in` Alias of `in_list`
190193
* `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".
191194
* `int` Only positive integer (alias to `integer`).
192195
* `integer` Only positive integer.
193196
* `int_signed` Only integer, could be signed (-/+) positive/negative (alias to `integer_signed`).
194197
* `integer_signed` Only integer, could be signed (-/+) positive/negative.
195-
* `ip` alias of `ipv4`
198+
* `ip` Alias of `ipv4`
196199
* `ipv4` Check for valid IP (IPv4)
197200
* `ipv6` Check for valid IP (IPv6)
198201
* `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"*.
199202
* `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))
200-
* `match_input` alias of `match`.
201-
* `max:n` will auto-detect value type then use proper validator.
203+
* `match_input` Alias of `match`.
204+
* `max:n` Will auto-detect value type then use proper validator.
202205
* Type Number uses `max_num`, String use `max_len`.
203-
* `max_date_iso` alias of `date_iso_max`.
204-
* `max_date_euro_long` alias of `date_euro_long_max`.
205-
* `max_date_euro_short` alias of `date_euro_short_max`.
206-
* `max_date_us_long` alias of `date_us_long_max`.
207-
* `max_date_us_short` alias of `date_us_short_max`.
206+
* `max_date_iso` Alias of `date_iso_max`.
207+
* `max_date_euro_long` Alias of `date_euro_long_max`.
208+
* `max_date_euro_short` Alias of `date_euro_short_max`.
209+
* `max_date_us_long` Alias of `date_us_long_max`.
210+
* `max_date_us_short` Alias of `date_us_short_max`.
208211
* `max_len:n` Checks field length, no longer than specified length where (n) is length parameter.
212+
* `max_length:n` Alias of `max_len`
209213
* `max_num:n` Checks numeric value to be lower or equal than the number (n).
210-
* `min:n` will auto-detect value type then use proper validator.
214+
* `min:n` Will auto-detect value type then use proper validator.
211215
* Type Number uses `min_num`, String use `min_len`.
212-
* `min_date_iso` alias of `date_iso_min`.
213-
* `min_date_euro_long` alias of `date_euro_long_min`.
214-
* `min_date_euro_short` alias of `date_euro_short_min`.
215-
* `min_date_us_long` alias of `date_us_long_min`.
216-
* `min_date_us_short` alias of `date_us_short_min`.
216+
* `min_date_iso` Alias of `date_iso_min`.
217+
* `min_date_euro_long` Alias of `date_euro_long_min`.
218+
* `min_date_euro_short` Alias of `date_euro_short_min`.
219+
* `min_date_us_long` Alias of `date_us_long_min`.
220+
* `min_date_us_short` Alias of `date_us_short_min`.
217221
* `min_len:n` Checks field length, no shorter than specified length where (n) is length parameter.
222+
* `min_length:n` Alias of `min_len`
218223
* `min_num:n` Checks numeric value to be higher or equal than the number (n).
219-
* `not_in` alias of `not_in_list`
224+
* `not_in` Alias of `not_in_list`
220225
* `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".
221226
* `numeric` Only positive numeric value (float, integer).
222227
* `numeric_signed` Only numeric value (float, integer) can also be signed (-/+).
223-
* `pattern` Ensure it follows a regular expression pattern... please see [Regular Expression Pattern](https://github.com/ghiscoding/angular-validation/wiki/Regular-Expression-Pattern)
228+
* `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.
229+
* `range` Alias of `between`
224230
* `required` Ensures the specified key value exists and is not empty
225-
* `same` alias of `match`.
226-
* `size` will auto-detect value type then use proper validator.
231+
* `same` Alias of `match`.
232+
* `size` Will auto-detect value type then use proper validator.
227233
* Type Number uses `exact_num`, String use `exact_len`.
234+
* `string_len` Alias of `between_len`
235+
* `string_length` Alias of `between_len`
228236
* `time` Ensure time follows the format of (hh:mm) or (hh:mm:ss)
229237
* `url` Check for valid URL or subdomain

src/validation-rules.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ angular
9292
};
9393
break;
9494
case "between" :
95+
case "range" :
9596
var ranges = ruleParams.split(',');
9697
if (ranges.length !== 2) {
9798
throw "This validation must include exactly 2 params separated by a comma (,) ex.: between:1,5";
@@ -107,6 +108,10 @@ angular
107108
break;
108109
case "betweenLen" :
109110
case "between_len" :
111+
case "stringLen" :
112+
case "string_len" :
113+
case "stringLength" :
114+
case "string_length" :
110115
var ranges = ruleParams.split(',');
111116
if (ranges.length !== 2) {
112117
throw "This validation must include exactly 2 params separated by a comma (,) ex.: between_len:1,5";
@@ -449,6 +454,8 @@ angular
449454
};
450455
break;
451456
case "email" :
457+
case "emailAddress" :
458+
case "email_address" :
452459
validator = {
453460
// Email RFC 5322, pattern pulled from http://www.regular-expressions.info/email.html
454461
// but removed necessity of a TLD (Top Level Domain) which makes this email valid: admin@mailserver1
@@ -488,6 +495,7 @@ angular
488495
type: "regex"
489496
};
490497
break;
498+
case "enum" :
491499
case "in" :
492500
case "inList" :
493501
case "in_list" :
@@ -533,6 +541,7 @@ angular
533541
type: "regex"
534542
};
535543
break;
544+
case "compare" :
536545
case "match" :
537546
case "matchInput" :
538547
case "match_input" :
@@ -557,6 +566,8 @@ angular
557566
break;
558567
case "maxLen" :
559568
case "max_len" :
569+
case "maxLength" :
570+
case "max_length" :
560571
validator = {
561572
pattern: "^(.|[\\r\\n]){0," + ruleParams + "}$",
562573
message: "INVALID_MAX_CHAR",
@@ -585,6 +596,8 @@ angular
585596
break;
586597
case "minLen" :
587598
case "min_len" :
599+
case "minLength" :
600+
case "min_length" :
588601
validator = {
589602
pattern: "^(.|[\\r\\n]){" + ruleParams + ",}$",
590603
message: "INVALID_MIN_CHAR",

0 commit comments

Comments
 (0)