Project

General

Profile

1
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-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
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
        // TODO remove console message after final testing
17
        console.log("INVALID EMAIL: "+data[i]);
18
        return false;
19
      }
20
    }
21
    // TODO remove console message after final testing
22
    console.log("ALL EMAILS ARE VALID");
23
    return true;
24
  }
25

    
26
  public static emailValidator(email: any): boolean {
27
    if (email.match(this.regex))
28
        return true;
29
    else
30
        return false;
31
  }
32

    
33
}
(5-5/5)