@@ -19,7 +19,74 @@ var requiredDirective = function() {
19
19
} ;
20
20
} ;
21
21
22
+ /**
23
+ * @ngdoc directive
24
+ * @name ngPattern
25
+ *
26
+ * @description
27
+ *
28
+ * ngPattern adds the pattern {@link ngModel.NgModelController#$validators `validator`} to {@link ngModel `ngModel`}.
29
+ * It is most often used for text-based [@link input `input`} controls, but can also be applied to custom text-based controls.
30
+ *
31
+ * The validator sets the `pattern` error key if the {@link ngModel.NgModelController#$viewValue `ngModel.$viewValue`}
32
+ * does not match a RegExp which is obtained by evaluating the Angular expression given in the
33
+ * `ngPattern` attribute value:
34
+ * * If the expression evaluates to a RegExp object, then this is used directly.
35
+ * * If the expression evaluates to a string, then it will be converted to a RegExp after wrapping it
36
+ * in `^` and `$` characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`.
37
+ *
38
+ * <div class="alert alert-info">
39
+ * **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
40
+ * start at the index of the last search's match, thus not taking the whole input value into
41
+ * account.
42
+ * </div>
43
+ *
44
+ * <div class="alert alert-info">
45
+ * **Note:** This directive is also added when the plain `pattern` attribute is used, with two
46
+ * differences:
47
+ * 1. `ngPattern` does not set the `pattern` attribute and therefore not HTML5 constraint validation
48
+ * is available.
49
+ * 2. The `ngPattern` attribute must be an expression, while the `pattern` value must be interpolated
50
+ * </div>
51
+ *
52
+ * @example
53
+ * <example name="ngPatternDirective" module="ngPatternExample">
54
+ * <file name="index.html">
55
+ * <script>
56
+ * angular.module('ngPatternExample', [])
57
+ * .controller('ExampleController', ['$scope', function($scope) {
58
+ * $scope.regex = '\\d+';
59
+ * }]);
60
+ * </script>
61
+ * <div ng-controller="ExampleController">
62
+ * <form name="form">
63
+ * <label for="regex">Set a pattern (regex string): </label>
64
+ * <input type="text" ng-model="regex" id="regex" />
65
+ * <br>
66
+ * <label for="input">This input is restricted by the current pattern: </label>
67
+ * <input type="text" ng-model="model" id="input" name="input" ng-pattern="regex" /><br>
68
+ * <hr>
69
+ * input valid? = <code>{{form.input.$valid}}</code><br>
70
+ * model = <code>{{model}}</code>
71
+ * </form>
72
+ * </div>
73
+ * </file>
74
+ * <file name="protractor.js" type="protractor">
75
+ var model = element(by.binding('model'));
76
+ var input = element(by.id('input'));
22
77
78
+ it('should validate the input with the default pattern', function() {
79
+ input.sendKeys('aaa');
80
+ expect(model.getText()).not.toContain('aaa');
81
+
82
+ input.clear().then(function() {
83
+ input.sendKeys('123');
84
+ expect(model.getText()).toContain('123');
85
+ });
86
+ });
87
+ * </file>
88
+ * </example>
89
+ */
23
90
var patternDirective = function ( ) {
24
91
return {
25
92
restrict : 'A' ,
@@ -51,7 +118,62 @@ var patternDirective = function() {
51
118
} ;
52
119
} ;
53
120
54
-
121
+ /**
122
+ * @ngdoc directive
123
+ * @name ngMaxlength
124
+ *
125
+ * @description
126
+ *
127
+ * ngMaxlength adds the maxlength {@link ngModel.NgModelController#$validators `validator`} to {@link ngModel `ngModel`}.
128
+ * It is most often used for text-based [@link input `input`} controls, but can also be applied to custom text-based controls.
129
+ *
130
+ * The validator sets the `maxlength` error key if the {@link ngModel.NgModelController#$viewValue `ngModel.$viewValue`}
131
+ * is longer than the integer obtained by evaluating the Angular expression given in the
132
+ * `ngMaxlength` attribute value.
133
+ *
134
+ * <div class="alert alert-info">
135
+ * **Note:** This directive is also added when the plain `maxlength` attribute is used, with two
136
+ * differences:
137
+ * 1. `ngMaxlength` does not set the `maxlength` attribute and therefore not HTML5 constraint validation
138
+ * is available.
139
+ * 2. The `ngMaxlength` attribute must be an expression, while the `maxlength` value must be interpolated
140
+ * </div>
141
+ *
142
+ * @example
143
+ * <example name="ngMaxlengthDirective" module="ngMaxlengthExample">
144
+ * <file name="index.html">
145
+ * <script>
146
+ * angular.module('ngMaxlengthExample', [])
147
+ * .controller('ExampleController', ['$scope', function($scope) {
148
+ * $scope.maxlength = 5;
149
+ * }]);
150
+ * </script>
151
+ * <div ng-controller="ExampleController">
152
+ * <form name="form">
153
+ * <label for="maxlength">Set a maxlength: </label>
154
+ * <input type="number" ng-model="maxlength" id="maxlength" />
155
+ * <br>
156
+ * <label for="input">This input is restricted by the current maxlength: </label>
157
+ * <input type="text" ng-model="model" id="input" name="input" ng-maxlength="maxlength" /><br>
158
+ * <hr>
159
+ * input valid? = <code>{{form.input.$valid}}</code><br>
160
+ * model = <code>{{model}}</code>
161
+ * </form>
162
+ * </div>
163
+ * </file>
164
+ * <file name="protractor.js" type="protractor">
165
+ * var model = element(by.binding('model'));
166
+ *
167
+ * it('should validate the input with the default maxlength', function() {
168
+ * element(by.id('input')).sendKeys('abcdef');
169
+ * expect(model.getText()).not.toContain('abcdef');
170
+ *
171
+ * element(by.id('input')).sendKeys('abcde');
172
+ * expect(model.getText()).toContain('abcde');
173
+ * });
174
+ * </file>
175
+ * </example>
176
+ */
55
177
var maxlengthDirective = function ( ) {
56
178
return {
57
179
restrict : 'A' ,
@@ -72,6 +194,65 @@ var maxlengthDirective = function() {
72
194
} ;
73
195
} ;
74
196
197
+ /**
198
+ * @ngdoc directive
199
+ * @name ngMinlength
200
+ *
201
+ * @description
202
+ *
203
+ * ngMinlength adds the minlength {@link ngModel.NgModelController#$validators `validator`} to {@link ngModel `ngModel`}.
204
+ * It is most often used for text-based [@link input `input`} controls, but can also be applied to custom text-based controls.
205
+ *
206
+ * The validator sets the `minlength` error key if the {@link ngModel.NgModelController#$viewValue `ngModel.$viewValue`}
207
+ * is shorter than the integer obtained by evaluating the Angular expression given in the
208
+ * `ngMinlength` attribute value.
209
+ *
210
+ * <div class="alert alert-info">
211
+ * **Note:** This directive is also added when the plain `minlength` attribute is used, with two
212
+ * differences:
213
+ * 1. `ngMinlength` does not set the `minlength` attribute and therefore not HTML5 constraint validation
214
+ * is available.
215
+ * 2. The `ngMinlength` value must be an expression, while the `minlength` value must be interpolated
216
+ * </div>
217
+ *
218
+ * @example
219
+ * <example name="ngMinlengthDirective" module="ngMinlengthExample">
220
+ * <file name="index.html">
221
+ * <script>
222
+ * angular.module('ngMinlengthExample', [])
223
+ * .controller('ExampleController', ['$scope', function($scope) {
224
+ * $scope.minlength = 3;
225
+ * }]);
226
+ * </script>
227
+ * <div ng-controller="ExampleController">
228
+ * <form name="form">
229
+ * <label for="minlength">Set a minlength: </label>
230
+ * <input type="number" ng-model="minlength" id="minlength" />
231
+ * <br>
232
+ * <label for="input">This input is restricted by the current minlength: </label>
233
+ * <input type="text" ng-model="model" id="input" name="input" ng-minlength="minlength" /><br>
234
+ * <hr>
235
+ * input valid? = <code>{{form.input.$valid}}</code><br>
236
+ * model = <code>{{model}}</code>
237
+ * </form>
238
+ * </div>
239
+ * </file>
240
+ * <file name="protractor.js" type="protractor">
241
+ * var model = element(by.binding('model'));
242
+ var input = element(by.id('input'));
243
+
244
+ it('should validate the input with the default maxlength', function() {
245
+ input.sendKeys('abcdef');
246
+ expect(model.getText()).not.toContain('abcdef');
247
+
248
+ input.clear().then(function() {
249
+ input.sendKeys('abcde');
250
+ expect(model.getText()).toContain('abcde');
251
+ });
252
+ });
253
+ * </file>
254
+ * </example>
255
+ */
75
256
var minlengthDirective = function ( ) {
76
257
return {
77
258
restrict : 'A' ,
0 commit comments