2018-12-17 16:15:14 +01:00
|
|
|
import {Email} from "./email";
|
|
|
|
|
|
|
|
export class Validator {
|
|
|
|
|
2019-01-30 14:57:21 +01:00
|
|
|
//private static regex = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
|
2020-08-06 12:56:51 +02:00
|
|
|
private static regex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
|
2019-01-30 14:57:21 +01:00
|
|
|
/*
|
|
|
|
private static regex2= /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
|
|
// for expanation paste it in https://www.regextester.com/
|
|
|
|
// RFC5322 https://emailregex.com/
|
|
|
|
*/
|
2018-12-17 16:15:14 +01:00
|
|
|
|
|
|
|
public static hasValidEmails(data: any): boolean {
|
|
|
|
for(let i = 0; i < data.length; i++) {
|
|
|
|
if (!this.emailValidator(data[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static emailValidator(email: any): boolean {
|
2020-08-06 12:56:51 +02:00
|
|
|
return !!email.match(this.regex);
|
2018-12-17 16:15:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|