Skip to content

Instantly share code, notes, and snippets.

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