如何将正确的验证字符串附加到此验证器。模式数组
password: ['',
Validators.compose([
Validators.minLength(8),
Validators.maxLength(20),
Validators.pattern('/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/')
])],
为了使用验证器,你应该先使用FormControl,所以请遵循这段代码,不要忘记你应该将pattern作为字符串传递,而不是/:
import { FormControl, Validators } from '@angular/forms';
password: new FormControl(null, [
Validators.required,
Validators.minLength(8),
Validators.maxLength(20),
Validators.pattern("(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])")
]),