1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. All Rights Reserved.
|
4
|
*
|
5
|
* Use of this source code is governed by an MIT-style license that can be
|
6
|
* found in the LICENSE file at https://angular.io/license
|
7
|
*/
|
8
|
import { OnChanges, Provider, SimpleChanges } from '@angular/core';
|
9
|
import { Observable } from 'rxjs/Observable';
|
10
|
import { AbstractControl } from '../model';
|
11
|
/** @experimental */
|
12
|
export declare type ValidationErrors = {
|
13
|
[key: string]: any;
|
14
|
};
|
15
|
/**
|
16
|
* An interface that can be implemented by classes that can act as validators.
|
17
|
*
|
18
|
* ## Usage
|
19
|
*
|
20
|
* ```typescript
|
21
|
* @Directive({
|
22
|
* selector: '[custom-validator]',
|
23
|
* providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
|
24
|
* })
|
25
|
* class CustomValidatorDirective implements Validator {
|
26
|
* validate(c: Control): {[key: string]: any} {
|
27
|
* return {"custom": true};
|
28
|
* }
|
29
|
* }
|
30
|
* ```
|
31
|
*
|
32
|
* @stable
|
33
|
*/
|
34
|
export interface Validator {
|
35
|
validate(c: AbstractControl): ValidationErrors | null;
|
36
|
registerOnValidatorChange?(fn: () => void): void;
|
37
|
}
|
38
|
/** @experimental */
|
39
|
export interface AsyncValidator extends Validator {
|
40
|
validate(c: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null>;
|
41
|
}
|
42
|
export declare const REQUIRED_VALIDATOR: Provider;
|
43
|
export declare const CHECKBOX_REQUIRED_VALIDATOR: Provider;
|
44
|
/**
|
45
|
* A Directive that adds the `required` validator to any controls marked with the
|
46
|
* `required` attribute, via the {@link NG_VALIDATORS} binding.
|
47
|
*
|
48
|
* ### Example
|
49
|
*
|
50
|
* ```
|
51
|
* <input name="fullName" ngModel required>
|
52
|
* ```
|
53
|
*
|
54
|
* @stable
|
55
|
*/
|
56
|
export declare class RequiredValidator implements Validator {
|
57
|
private _required;
|
58
|
private _onChange;
|
59
|
required: boolean | string;
|
60
|
validate(c: AbstractControl): ValidationErrors | null;
|
61
|
registerOnValidatorChange(fn: () => void): void;
|
62
|
}
|
63
|
/**
|
64
|
* A Directive that adds the `required` validator to checkbox controls marked with the
|
65
|
* `required` attribute, via the {@link NG_VALIDATORS} binding.
|
66
|
*
|
67
|
* ### Example
|
68
|
*
|
69
|
* ```
|
70
|
* <input type="checkbox" name="active" ngModel required>
|
71
|
* ```
|
72
|
*
|
73
|
* @experimental
|
74
|
*/
|
75
|
export declare class CheckboxRequiredValidator extends RequiredValidator {
|
76
|
validate(c: AbstractControl): ValidationErrors | null;
|
77
|
}
|
78
|
/**
|
79
|
* Provider which adds {@link EmailValidator} to {@link NG_VALIDATORS}.
|
80
|
*/
|
81
|
export declare const EMAIL_VALIDATOR: any;
|
82
|
/**
|
83
|
* A Directive that adds the `email` validator to controls marked with the
|
84
|
* `email` attribute, via the {@link NG_VALIDATORS} binding.
|
85
|
*
|
86
|
* ### Example
|
87
|
*
|
88
|
* ```
|
89
|
* <input type="email" name="email" ngModel email>
|
90
|
* <input type="email" name="email" ngModel email="true">
|
91
|
* <input type="email" name="email" ngModel [email]="true">
|
92
|
* ```
|
93
|
*
|
94
|
* @experimental
|
95
|
*/
|
96
|
export declare class EmailValidator implements Validator {
|
97
|
private _enabled;
|
98
|
private _onChange;
|
99
|
email: boolean | string;
|
100
|
validate(c: AbstractControl): ValidationErrors | null;
|
101
|
registerOnValidatorChange(fn: () => void): void;
|
102
|
}
|
103
|
/**
|
104
|
* @stable
|
105
|
*/
|
106
|
export interface ValidatorFn {
|
107
|
(c: AbstractControl): ValidationErrors | null;
|
108
|
}
|
109
|
/**
|
110
|
* @stable
|
111
|
*/
|
112
|
export interface AsyncValidatorFn {
|
113
|
(c: AbstractControl): Promise<ValidationErrors | null> | Observable<ValidationErrors | null>;
|
114
|
}
|
115
|
/**
|
116
|
* Provider which adds {@link MinLengthValidator} to {@link NG_VALIDATORS}.
|
117
|
*
|
118
|
* ## Example:
|
119
|
*
|
120
|
* {@example common/forms/ts/validators/validators.ts region='min'}
|
121
|
*/
|
122
|
export declare const MIN_LENGTH_VALIDATOR: any;
|
123
|
/**
|
124
|
* A directive which installs the {@link MinLengthValidator} for any `formControlName`,
|
125
|
* `formControl`, or control with `ngModel` that also has a `minlength` attribute.
|
126
|
*
|
127
|
* @stable
|
128
|
*/
|
129
|
export declare class MinLengthValidator implements Validator, OnChanges {
|
130
|
private _validator;
|
131
|
private _onChange;
|
132
|
minlength: string;
|
133
|
ngOnChanges(changes: SimpleChanges): void;
|
134
|
validate(c: AbstractControl): ValidationErrors | null;
|
135
|
registerOnValidatorChange(fn: () => void): void;
|
136
|
private _createValidator();
|
137
|
}
|
138
|
/**
|
139
|
* Provider which adds {@link MaxLengthValidator} to {@link NG_VALIDATORS}.
|
140
|
*
|
141
|
* ## Example:
|
142
|
*
|
143
|
* {@example common/forms/ts/validators/validators.ts region='max'}
|
144
|
*/
|
145
|
export declare const MAX_LENGTH_VALIDATOR: any;
|
146
|
/**
|
147
|
* A directive which installs the {@link MaxLengthValidator} for any `formControlName,
|
148
|
* `formControl`,
|
149
|
* or control with `ngModel` that also has a `maxlength` attribute.
|
150
|
*
|
151
|
* @stable
|
152
|
*/
|
153
|
export declare class MaxLengthValidator implements Validator, OnChanges {
|
154
|
private _validator;
|
155
|
private _onChange;
|
156
|
maxlength: string;
|
157
|
ngOnChanges(changes: SimpleChanges): void;
|
158
|
validate(c: AbstractControl): ValidationErrors | null;
|
159
|
registerOnValidatorChange(fn: () => void): void;
|
160
|
private _createValidator();
|
161
|
}
|
162
|
export declare const PATTERN_VALIDATOR: any;
|
163
|
/**
|
164
|
* A Directive that adds the `pattern` validator to any controls marked with the
|
165
|
* `pattern` attribute, via the {@link NG_VALIDATORS} binding. Uses attribute value
|
166
|
* as the regex to validate Control value against. Follows pattern attribute
|
167
|
* semantics; i.e. regex must match entire Control value.
|
168
|
*
|
169
|
* ### Example
|
170
|
*
|
171
|
* ```
|
172
|
* <input [name]="fullName" pattern="[a-zA-Z ]*" ngModel>
|
173
|
* ```
|
174
|
* @stable
|
175
|
*/
|
176
|
export declare class PatternValidator implements Validator, OnChanges {
|
177
|
private _validator;
|
178
|
private _onChange;
|
179
|
pattern: string | RegExp;
|
180
|
ngOnChanges(changes: SimpleChanges): void;
|
181
|
validate(c: AbstractControl): ValidationErrors | null;
|
182
|
registerOnValidatorChange(fn: () => void): void;
|
183
|
private _createValidator();
|
184
|
}
|