private createGroupForm() {
this.medicalProfileForm = this.formBuilder.group(
{
email: new FormControl('', [Validators.required, Validators.email]),
sex: new FormControl('', [Validators.required]),
name: new FormControl('', [Validators.required]),
country: new FormControl('', [Validators.required]),
surname: new FormControl('', [Validators.required]),
hospital: new FormControl('', [Validators.required]),
telephone: new FormControl('', [Validators.required]),
cellPhone: new FormControl('', [Validators.required]),
password: new FormControl('', [
Validators.required,
Validators.minLength(8),
Validators.maxLength(12),
PasswordValidator()
]),
speciality: new FormControl('', [Validators.required]),
confirmPassword: ['', Validators.required],
birth: new FormControl('', [Validators.required]),
}
);
}
PasswordValidator
import { AbstractControl, ValidatorFn } from '@angular/forms';
export function PasswordValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
const ucase = new RegExp("[A-Z]+");
const lcase = new RegExp("[a-z]+");
const num = new RegExp("[0-9]+");
const esp = new RegExp("(?=.*[}{,.^?~=+\\-_\\/*\\-+.\\|])");
const a = ucase.test(control.value);
console.log("Senha: " + control.value + " - Tem maiusculo: " + a);
const b = lcase.test(control.value);
console.log("Senha: " + control.value + " - Tem minusculo: " + b);
const c = num.test(control.value);
console.log("Senha: " + control.value + " - Tem número: " + c);
const d = esp.test(control.value);
console.log("Senha: " + control.value + " - Tem esp: " + d);
const forbidden = ucase.test(control.value) || lcase.test(control.value) || num.test(control.value);
console.log("Senha: " + control.value + " - válido: " + forbidden);
return forbidden ?
{ 'password':
{ value: control.value }
} : null;
}
}
Mas o mesmo o campo password, ficando em vermelho, eu consigo dar o submit.
O que pode ser ?