Hello, I'm new to angular and would like to know how I use more of an external validation with FormGroup. Currently my code is as follows ...
constructor(fb: FormBuilder, public router: Router){
//Grupo de formulario - Validações
this.myForm = fb.group({
nome: ['', Validators.required ],
email: ['', Validators.compose([Validators.required, Validators.pattern(this.emailPattern)])],
cpf: ['', Validators.required ],
telefone: ['', Validators.required],
cep: ['', Validators.required]
}, { validator: VwPagePersonal.validaNome });
}
//Validações customizadas
static validaNome(group: AbstractControl): {[Key: string]: boolean} {
const nome = group.get('nome');
if(!nome){
return undefined;
}
var regexp = /\b[^\d\s]+\b/g;
var count = 0;
while (regexp.exec(nome.value))++count;
if (count === 1) {
return { nomeInvalid:true }
}
return undefined;
}
static validaCpf(group: AbstractControl): {[Key: string]: boolean} {
const cpf = group.get('cpf').value;
if(cpf === 1){
return { nomeInvalid:true }
}
return undefined;
}
I have two external functions, one is: 'ValidaName' and the other 'ValidaCpf' !!
However I am only able to use one of the validations in this syntax, " { validator: VwPagePersonal.validaNome });
", which is in the formGroup !!
I would like to know how I can use both functions together ...