本文整理汇总了TypeScript中@angular/common.Validators.maxLength方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Validators.maxLength方法的具体用法?TypeScript Validators.maxLength怎么用?TypeScript Validators.maxLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common.Validators
的用法示例。
在下文中一共展示了Validators.maxLength方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(
private events: Events,
private nav: NavController,
private auth: AuthProvider,
private formBuilder: FormBuilder) {
this.name = new Control("", Validators.compose([
Validators.required,
Validators.minLength(6),
Validators.maxLength(64)
]));
this.email = new Control("", Validators.compose([
Validators.required,
Validators.pattern("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"),
Validators.minLength(6),
Validators.maxLength(64)
]));
this.password = new Control("", Validators.compose([
Validators.required,
Validators.minLength(6),
Validators.maxLength(24)
]));
this.registerForm = formBuilder.group({
"name": this.name,
"email": this.email,
"password": this.password
});
}
示例2: ngOnInit
ngOnInit() {
this.ctrlEmail = new Control('', Validators.compose([Validators.required, Validators.pattern("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")]));
this.ctrlPassword = new Control('', Validators.compose([
Validators.required, Validators.minLength(8), Validators.maxLength(255),
]));
this.ctrlRegPassword = new Control('', Validators.compose([
Validators.required,
Validators.minLength(8),
Validators.maxLength(255),
]));
this.ctrlRegPasswordConfirm = new Control('', (password:AbstractControl) => {
return password.value != this.ctrlRegPassword.value ? {passwordConfirmation: 'Password confirmation does not match'} : null;
});
this.loginForm = new ControlGroup({
password: this.ctrlPassword,
email: this.ctrlEmail
});
this.registerForm = new ControlGroup({
email: this.ctrlEmail,
password: this.ctrlRegPassword,
passwordConfirm: this.ctrlRegPasswordConfirm
});
this.isLogin = true;
this.wrongEmailPassword = false;
this.regEmailConflict = false;
this.otherErrorLogin = false;
// redirect to the previous page if user is logged in
this._authContext.observable().subscribe(
(authContext:AuthContext) => {
if (authContext.isLoggedIn()) {
this.goBack();
}
}
);
if (this._authContext.isLoggedIn()) {
this.goBack();
}
}
示例3: constructor
constructor(
public platform: Platform,
public nav: NavController,
public authData: AuthData,
public formBuilder: FormBuilder
) {
this.nav = nav;
this.authData = authData;
this.loginForm = formBuilder.group({
email: ['', Validators.required, Validators.minLength(6), Validators.maxLength(64)],
password: ['', Validators.required, Validators.minLength(6), Validators.maxLength(24)]
})
}
示例4: ngOnInit
ngOnInit() {
this.name = new Control('',
Validators.compose([
Validators.required
]));
this.price = new Control('',
Validators.compose([
Validators.required
]));
this.description = new Control('',
Validators.compose([
Validators.required,
Validators.minLength(3),
Validators.maxLength(50)
]));
this.insertForm = this._fb.group({
'name': this.name,
'price': this.price,
'description': this.description
});
}
示例5: initValidators
private initValidators():void {
console.log('Adding validators to control ',this.name);
let validators:Array<Function> = [];
if(this.required) {
validators.push(Validators.required);
}
if(this.isTypeText() && this.minLength) {
console.log('Adding minLength validator',this.minLength);
validators.push(Validators.minLength(this.minLength));
}
if(this.isTypeText() && this.maxLength) {
console.log('Adding maxLength validator',this.maxLength);
validators.push(Validators.maxLength(this.maxLength));
}
if(this.isTypeEmail()) {
validators.push(ValidatorService.emailValidator);
}
if(this.isTypeNumber()) {
validators.push(ValidatorService.numberValidator);
}
if(this.isInput() && this.pattern) {
validators.push(ValidatorService.regexValidator(this.pattern));
}
console.log(validators.length+' validators added to control',this.name);
this.validators = Validators.compose(validators);
}
示例6: constructor
constructor(fb: FormBuilder) {
this.projectForm = fb.group({
'clientName': ['', Validators.required],
'description': ['Nuclear Missile Defense System', Validators.compose([
Validators.required,
Validators.maxLength(30)
])],
'clientEmail': ['', Validators.compose([
MdPatternValidator.inline('^.+@.+\..+$'),
Validators.required,
Validators.minLength(10),
Validators.maxLength(100)
])],
'rate': [500, Validators.compose([
MdNumberRequiredValidator.inline(),
MdPatternValidator.inline('^1234$'),
MdMinValueValidator.inline(800),
MdMaxValueValidator.inline(4999)
])]
});
}
示例7: setValidator
function setValidator(item: Validation, original?) {
switch (item.type) {
case 'required': return Validators.required;
case 'minLength': return Validators.minLength(item.value);
case 'maxLength': return Validators.maxLength(item.value);
case 'pattern': return Validators.pattern(item.value);
case 'custom': return item.value;
case 'match':
matches.push({toMatch: item.value, model: original.key});
return CustomValidators.match(item.value);
}
}
示例8: ngOnInit
ngOnInit() {
this.myForm = new ControlGroup({
name: new Control('', Validators.required),
street: new Control('', Validators.minLength(3)),
email: new Control('',
Validators.pattern('^[A-Za-z0-9]+\@[A-Za-z0-9]+[.][A-Za-z0-9]{2,5}')),
city: new Control('', Validators.maxLength(10)),
zip: new Control('', Validators.compose([
Validators.pattern('[A-Za-z]{5}'),
Validators.required
]))
});
}
示例9: formValid
formValid(): void {
this.nameControl = new Control('', Validators.compose([Validators.required,
Validators.minLength(3),
Validators.maxLength(50)]));
this.editForm = this._fb.group({
'name': this.nameControl,
'price': ['', Validators.compose([
NumberValidator.isAValidateNumber(),
Validators.required
])],
'imageUrl': ['',
Validators.compose([Validators.required,
Validators.minLength(5),
Validators.maxLength(250)])],
'starRating': ['',
NumberValidator.range(1, 5)],
'desc': ['']
});
this.editForm.valueChanges
.subscribe(data => this.onValueChanged(data));
}
示例10: constructor
/**
* RoomDetail Constructor.
* @param _router
* @param _routeParams
* @param _roomService
* @param builder
*/
constructor(private _router:Router,
private _routeParams:RouteParams,
private _roomService:RoomService,
private builder: FormBuilder) {
// Add validators to input field
this.message = new Control('', Validators.compose([
Validators.required,
Validators.minLength(1),
Validators.maxLength(150)
]));
// Create a form from input field
this.messageForm = builder.group({
message: this.message
});
}