Better Validations
This commit is contained in:
11
src/app/shared/validators/validate-email.validator.ts
Normal file
11
src/app/shared/validators/validate-email.validator.ts
Normal 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
11
src/app/shared/validators/validate-password.validator.ts
Normal file
11
src/app/shared/validators/validate-password.validator.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user