Skip to content

Instantly share code, notes, and snippets.

@JonathanDn
Last active July 16, 2017 08:42
Show Gist options
  • Save JonathanDn/6d9d51d97b6dd9a1d583dbe4f89d4d13 to your computer and use it in GitHub Desktop.
Save JonathanDn/6d9d51d97b6dd9a1d583dbe4f89d4d13 to your computer and use it in GitHub Desktop.
Angular - email validation service, provide it and call with the email to check, return true /false according.
import {Injectable} from "@angular/core";
@Injectable()
export class EmailValidationService {
private regex: any = /^[a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+((?:\.){1}[a-zA-Z0-9-]+)$/;
private isEmailValid = false;
constructor() {}
getEmailValidity(email) {
if (email && email.match(this.regex)) {
return this.isEmailValid = true;
} else {
return this.isEmailValid = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment