Project

General

Profile

1 54439 sofia.balt
import {Email} from "./email";
2
3
export class Validator {
4
5 54672 konstantin
  //private static regex = "^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$";
6 59225 k.triantaf
  private static regex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
7 54672 konstantin
  /*
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 54439 sofia.balt
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 59225 k.triantaf
    return !!email.match(this.regex);
24 54439 sofia.balt
  }
25
26
}