Skip to content

Commit f04b04c

Browse files
committed
docs(README): Update readme
1 parent 7c9aa45 commit f04b04c

File tree

2 files changed

+109
-15
lines changed

2 files changed

+109
-15
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@ The rules are from https://github.com/vt-middleware/passay
1414
The password validators are:
1515

1616
* repeatCharacterRegexRule
17-
* whitespaceRule
17+
* whitespaceRule (moved to UniversalValidators)
1818
* allowedCharacterRule
1919
* alphabeticalCharacterRule
2020
* digitCharacterRule
2121
* lowercaseCharacterRule
2222
* uppercaseCharacterRule
2323
* more will come
2424

25-
## Email
25+
## Email validators
2626

2727
* simple (only checks if it looks like a mail)
2828
* normal (follows the [HTML5](https://www.w3.org/TR/html5/forms.html#valid-e-mail-address) rules)
2929

30+
## Universal validators
31+
32+
* noWhitespace
33+
* isNumber
34+
* isInRange
35+
* minLength
36+
* maxLength
37+
38+
3039
## Install
3140

3241
```
@@ -47,13 +56,18 @@ password: Control = new Control('', Validators.compose([
4756
email: Control = new Control('', EmailValidators.normal());
4857
```
4958

59+
```
60+
text: Control = new Control('', UniversalValidators.minLength(2));
61+
```
62+
63+
5064
##Todo
5165

5266
* Implement https://github.com/mailcheck/mailcheck
5367
* Add more password rules
54-
* Add general validators
68+
* Add credit card validators
69+
* Add phone validators
5570
* Add address validator
56-
* Add releases
5771

5872
Get the complete changelog here: https://github.com/Nightapes/ng2-validators/releases
5973

bundles/ng2-validators.js

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
System.registerDynamic("src/password-validators", [], true, function($__require, exports, module) {
1+
System.registerDynamic("src/password-validators", ["./util"], true, function($__require, exports, module) {
22
"use strict";
33
;
44
var define,
55
global = this,
66
GLOBAL = this;
7+
var util_1 = $__require('./util');
78
var PasswordValidators = (function() {
89
function PasswordValidators() {}
910
PasswordValidators.repeatCharacterRegexRule = function(repeatCount) {
1011
return function validate(control) {
12+
if (util_1.Util.isNotPresent(control))
13+
return undefined;
1114
var repeatDec = repeatCount - 1;
1215
var pattern = '([^\\x00-\\x1F])\\1{' + repeatDec + '}';
1316
if (control.value !== '' && new RegExp(pattern).test(control.value)) {
@@ -18,6 +21,8 @@ System.registerDynamic("src/password-validators", [], true, function($__require,
1821
};
1922
PasswordValidators.allowedCharacterRule = function(allowedChars) {
2023
return function validate(control) {
24+
if (util_1.Util.isNotPresent(control))
25+
return undefined;
2126
var value = control.value;
2227
var valid = true;
2328
var invalidChars = [];
@@ -39,6 +44,8 @@ System.registerDynamic("src/password-validators", [], true, function($__require,
3944
};
4045
PasswordValidators.alphabeticalCharacterRule = function(amount) {
4146
return function validate(control) {
47+
if (util_1.Util.isNotPresent(control))
48+
return undefined;
4249
var value = control.value;
4350
if (value.length === 0) {
4451
return undefined;
@@ -53,6 +60,8 @@ System.registerDynamic("src/password-validators", [], true, function($__require,
5360
};
5461
PasswordValidators.digitCharacterRule = function(amount) {
5562
return function validate(control) {
63+
if (util_1.Util.isNotPresent(control))
64+
return undefined;
5665
var value = control.value;
5766
if (value.length === 0) {
5867
return undefined;
@@ -67,6 +76,8 @@ System.registerDynamic("src/password-validators", [], true, function($__require,
6776
};
6877
PasswordValidators.lowercaseCharacterRule = function(amount) {
6978
return function validate(control) {
79+
if (util_1.Util.isNotPresent(control))
80+
return undefined;
7081
var value = control.value;
7182
if (value.length === 0) {
7283
return undefined;
@@ -81,6 +92,8 @@ System.registerDynamic("src/password-validators", [], true, function($__require,
8192
};
8293
PasswordValidators.uppercaseCharacterRule = function(amount) {
8394
return function validate(control) {
95+
if (util_1.Util.isNotPresent(control))
96+
return undefined;
8497
var value = control.value;
8598
if (value.length === 0) {
8699
return undefined;
@@ -99,30 +112,35 @@ System.registerDynamic("src/password-validators", [], true, function($__require,
99112
return module.exports;
100113
});
101114

102-
System.registerDynamic("src/email-validators", [], true, function($__require, exports, module) {
115+
System.registerDynamic("src/email-validators", ["./util"], true, function($__require, exports, module) {
103116
"use strict";
104117
;
105118
var define,
106119
global = this,
107120
GLOBAL = this;
121+
var util_1 = $__require('./util');
108122
var EmailValidators = (function() {
109123
function EmailValidators() {}
110124
EmailValidators.simple = function() {
111125
return function validate(control) {
126+
if (util_1.Util.isNotPresent(control))
127+
return undefined;
112128
var pattern = '^.+@.+\\..+$';
113-
if (control.value !== '' && !new RegExp(pattern).test(control.value)) {
114-
return {'simpleEmailRule': true};
129+
if (new RegExp(pattern).test(control.value)) {
130+
return undefined;
115131
}
116-
return undefined;
132+
return {'simpleEmailRule': true};
117133
};
118134
};
119135
EmailValidators.normal = function() {
120136
return function validate(control) {
137+
if (util_1.Util.isNotPresent(control))
138+
return undefined;
121139
var pattern = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
122-
if (control.value !== '' && !pattern.test(control.value)) {
123-
return {'normalEmailRule': true};
140+
if (pattern.test(control.value)) {
141+
return undefined;
124142
}
125-
return undefined;
143+
return {'normalEmailRule': true};
126144
};
127145
};
128146
return EmailValidators;
@@ -131,32 +149,94 @@ System.registerDynamic("src/email-validators", [], true, function($__require, ex
131149
return module.exports;
132150
});
133151

134-
System.registerDynamic("src/universal-validators", ["@angular/core/src/facade/lang"], true, function($__require, exports, module) {
152+
System.registerDynamic("src/util", [], true, function($__require, exports, module) {
153+
"use strict";
154+
;
155+
var define,
156+
global = this,
157+
GLOBAL = this;
158+
var Util = (function() {
159+
function Util() {}
160+
Util.isNotPresent = function(control) {
161+
return control.value !== '' ? false : true;
162+
};
163+
;
164+
return Util;
165+
}());
166+
exports.Util = Util;
167+
return module.exports;
168+
});
169+
170+
System.registerDynamic("src/universal-validators", ["@angular/core/src/facade/lang", "./util"], true, function($__require, exports, module) {
135171
"use strict";
136172
;
137173
var define,
138174
global = this,
139175
GLOBAL = this;
140176
var lang_1 = $__require('@angular/core/src/facade/lang');
177+
var util_1 = $__require('./util');
141178
var UniversalValidators = (function() {
142179
function UniversalValidators() {}
143180
UniversalValidators.noWhitespace = function() {
144181
return function validate(control) {
182+
if (util_1.Util.isNotPresent(control))
183+
return undefined;
145184
var pattern = '\\s';
146-
if (control.value !== '' && new RegExp(pattern).test(control.value)) {
185+
if (new RegExp(pattern).test(control.value)) {
147186
return {'noWhitespaceRequired': true};
148187
}
149188
return undefined;
150189
};
151190
};
152191
UniversalValidators.isNumber = function() {
153192
return function validate(control) {
154-
if (control.value !== '' && lang_1.NumberWrapper.isNaN(control.value)) {
193+
if (util_1.Util.isNotPresent(control))
194+
return undefined;
195+
if (lang_1.NumberWrapper.isNaN(control.value)) {
155196
return {'numberRequired': true};
156197
}
157198
return undefined;
158199
};
159200
};
201+
UniversalValidators.isInRange = function(minValue, maxValue) {
202+
return function validate(control) {
203+
if (util_1.Util.isNotPresent(control))
204+
return undefined;
205+
if (lang_1.NumberWrapper.isNaN(control.value)) {
206+
return {'numberRequired': true};
207+
}
208+
if (+control.value < minValue) {
209+
return {'rangeValueToSmall': true};
210+
}
211+
if (+control.value > maxValue) {
212+
return {'rangeValueToBig': true};
213+
} else {
214+
return undefined;
215+
}
216+
};
217+
};
218+
UniversalValidators.minLength = function(minLength) {
219+
return function validate(control) {
220+
if (util_1.Util.isNotPresent(control))
221+
return undefined;
222+
var value = control.value;
223+
if (value.length > minLength) {
224+
return undefined;
225+
}
226+
return {'minLength': true};
227+
};
228+
};
229+
UniversalValidators.maxLength = function(maxLength) {
230+
return function validate(control) {
231+
if (util_1.Util.isNotPresent(control))
232+
return undefined;
233+
var value = control.value;
234+
if (maxLength > value.length) {
235+
return undefined;
236+
}
237+
return {'maxLength': true};
238+
};
239+
};
160240
return UniversalValidators;
161241
}());
162242
exports.UniversalValidators = UniversalValidators;

0 commit comments

Comments
 (0)