openaire-library/utils/email/validator.ts

28 lines
664 B
TypeScript
Raw Normal View History

import {Email} from "./email";
export class Validator {
private static regex = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
public static hasValidEmails(data: any): boolean {
for(let i = 0; i < data.length; i++) {
if (!this.emailValidator(data[i])) {
// TODO remove console message after final testing
console.log("INVALID EMAIL");
return false;
}
}
// TODO remove console message after final testing
console.log("ALL EMAILS ARE VALID");
return true;
}
public static emailValidator(email: any): boolean {
if (email.match(this.regex))
return true;
else
return false;
}
}