Better Validations

This commit is contained in:
2023-08-02 00:08:58 -03:00
parent c60215d7d2
commit fea0b063b6
7 changed files with 44 additions and 6 deletions

View File

@@ -0,0 +1,11 @@
import {AbstractControl} from "@angular/forms";
export function ValidateEmailValidator(control: AbstractControl) {
const email = control.value;
const emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g;
const emailValid = emailRegex.test(email);
if (!emailValid) {
return { invalidEmail: true };
}
return null;
}

View File

@@ -0,0 +1,9 @@
import {AbstractControl} from "@angular/forms";
export function ValidateNotEmptyValidator(control: AbstractControl) {
const value = control.value;
if (!value || value.length === 0) {
return { invalidNotEmpty: true };
}
return null;
}

View File

@@ -0,0 +1,11 @@
import {AbstractControl} from "@angular/forms";
export function ValidatePasswordValidator(control: AbstractControl) {
var password = control.value;
var passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/g;
var passwordValid = passwordRegex.test(password);
if (!passwordValid) {
return { invalidPassword: true };
}
return null;
}