1
Hi, I’m new to angular and would like to know how I use more than one sternal 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: 'Validanome' and the other 'Validacpf'!!
However I am only able to use one of the validations in this syntax ", { validator: VwPagePersonal.validaNome });
", that is in formGroup!!
I would like to know how I can use both functions together...
You want to have your functions available in Validator?
– Felipe
Yes. Basically I would like to create 2 new types of validations, like a customization. And it uses them as if they were native Formgroup validations. In this current syntax, the 'validaName' works, now I need the syntax that makes both methods work...
– Guilherme Nunes