Skip to content

Instantly share code, notes, and snippets.

@lricoy
Last active April 13, 2016 04:52
Show Gist options
  • Save lricoy/2579cb3edc470477280b4ca6ea44027d to your computer and use it in GitHub Desktop.
Save lricoy/2579cb3edc470477280b4ca6ea44027d to your computer and use it in GitHub Desktop.
Validations Angular2
export class ValidationService {
static getValidatorErrorMessage(code: string) {
let config = {
'required': 'Campo obrigatório',
'invalidEmailAddress': 'Email inválido'
};
return config[code];
}
static emailValidator(control) {
// RFC 2822 compliant regex
if (control.value.match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/)) {
return null;
} else {
return { 'invalidEmailAddress': true };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment