Skip to content

Instantly share code, notes, and snippets.

@buildmotion
Created August 28, 2021 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buildmotion/579cb905dce40a5eae1762143591ed0e to your computer and use it in GitHub Desktop.
Save buildmotion/579cb905dce40a5eae1762143591ed0e to your computer and use it in GitHub Desktop.
import { CompositeRule, StringIsNotNullEmptyRange, StringIsRegExMatch } from '@buildmotion/rules-engine';
import { RuleConstants } from './rule-constants';
/**
* Use to validate the format of an email address. Expects:
*
* 1. string is not null or undefined
* 2. string length is within specified value
* 3. string value matches RegEx
*
*
* Resource: https://emailregex.com/
*/
export class EmailAddressFormatIsValidRule extends CompositeRule {
constructor(name: string, message: string, private emailAddress: string, isDisplayable: boolean = true) {
super(name, message, isDisplayable);
this.configureRules();
}
configureRules() {
this.rules.push(
new StringIsNotNullEmptyRange(
'EmailAddressStringIsValid',
'The email address value is not valid. Must be within 5 and 100 characters.',
this.emailAddress,
5,
100,
true
)
);
this.rules.push(
new StringIsRegExMatch(
'EmailAddressContainsValidCharacters',
'The email address format is not valid.',
this.emailAddress,
RuleConstants.emailAddressFormatRegEx,
true
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment