Last active
April 13, 2016 04:52
-
-
Save lricoy/2579cb3edc470477280b4ca6ea44027d to your computer and use it in GitHub Desktop.
Validations Angular2
This file contains hidden or 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
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