Project

General

Profile

« Previous | Next » 

Revision 59225

[Library | Trunk]: Email validator change regex

View differences:

modules/uoa-services-library/trunk/ng-openaire-library/src/app/utils/email/validator.ts
3 3
export class Validator {
4 4

  
5 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}$/;
6
  private static regex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
7 7
  /*
8 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 9
  // for expanation paste it in https://www.regextester.com/
......
13 13
  public static hasValidEmails(data: any): boolean {
14 14
    for(let i = 0; i < data.length; i++) {
15 15
      if (!this.emailValidator(data[i])) {
16
        // TODO remove console message after final testing
17
        //console.log("INVALID EMAIL: "+data[i]);
18 16
        return false;
19 17
      }
20 18
    }
21
    // TODO remove console message after final testing
22
    //console.log("ALL EMAILS ARE VALID");
23 19
    return true;
24 20
  }
25 21

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

  
33 26
}

Also available in: Unified diff