I have followed this link but it doesn't work for me. I am looking for a way to do a custom email validation that excludes some domains.
const excludedDomains = ['gmail.com', 'yahoo.com', 'live.com', 'live.co'];
const excludedEmailDomains = excludedDomains.join('|');
const VALIDATE_EMAIL = `^w+[-.w]*@(?!(?:${excludedEmailDomains}).com$)w+[-.w]*?.w{2,4}$`;
export const REG_EXP = new RegExp(VALIDATE_EMAIL, 'gm');
This doesn't want to work for me. Tests:
describe('REG_EXP', () => {
test('should match', () => {
const value = 'mail@company.com';
expect(REG_EXP.test(value)).toBeTruthy(); // fails, it is false here
});
test('should not match', () => {
const value = 'mail@gmail.com';
expect(REG_EXP.test(value)).toBeFalsy();
});
});
Only second test passes, it looks like my regexp always doesn't pass so the test result is always false
.