23 lines
756 B
TypeScript
23 lines
756 B
TypeScript
export class Validator {
|
|
static isEmail = (value: any) => {
|
|
if (typeof value !== 'string') return false;
|
|
const email = value.trim();
|
|
return /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(email);
|
|
};
|
|
|
|
static validatePasswordFormat = (password: string): boolean => {
|
|
if (password.length < 8) return false;
|
|
if (password.includes(' ')) return false;
|
|
|
|
const alphabets = 'abcdefghijklmnopqrstuvwxyz';
|
|
const numbers = '0123456789';
|
|
const specials = '!@#$%^';
|
|
|
|
if (!alphabets.includes(password[0])) return false;
|
|
|
|
const hasNumber = [...numbers].some((char) => password.includes(char));
|
|
const hasSpecial = [...specials].some((char) => password.includes(char));
|
|
|
|
return hasNumber && hasSpecial;
|
|
}
|
|
} |