Last active
July 16, 2017 08:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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