I'm working on a validation in react app That checks if the email address ends with (for ex: google.com
, || anything i pass to regex
)
So I need to pass a variable inside regex itself but i don't know how to do that
Here is what i did ---> this worked fine but it still static every time i want different domain i must change it here
export const emailAddress = (message = Strings.validationEmail) => new Validator({
key: 'EMAIL',
message,
validator: value => /^[a-z0-9](\.?[a-z0-9]){5,}@$gmail.com$/ig.test(`${value}`),
});
Now i want to replace google.com with any domain i provide to this function to be dynamic but the code below didn't work for me
export const emailAddressEndsWith = (domain = 'tvtc.com', message = Strings.validationEmailStartsWith) => new Validator({
key: 'EMAIL',
message: template(message)({ domain }),
validator: value => new RegExp(`/^[a-z0-9](\.?[a-z0-9]){5,}@${domain}$/ig`).test(`${value}`),
});