Project

General

Profile

1 61381 k.triantaf
import {Email} from "./email";
2
3
export class Validator {
4
5
  //private static regex = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
6
  private static regex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
7
  /*
8
  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,}))$/;
9
  // for expanation paste it in https://www.regextester.com/
10
  // RFC5322 https://emailregex.com/
11
  */
12
13
  public static hasValidEmails(data: any): boolean {
14
    for(let i = 0; i < data.length; i++) {
15
      if (!this.emailValidator(data[i])) {
16
        return false;
17
      }
18
    }
19
    return true;
20
  }
21
22
  public static emailValidator(email: any): boolean {
23
    return !!email.match(this.regex);
24
  }
25
26
}