I am trying to have a clientside check, if an entered value:
- is a valid email address
- has the right domain name
I came up with following code, but it doesn’t work:
var userinput = 'dirk@something.com';
var domain = 'somethingelse.com';
domain.replace('.', '\.');
var pattern = new RegExp('/^[a-zA-Z0-9._-]+@' + domain + '$/');
if(!pattern.test(userinput))
{
alert('not a valid email address, or the wrong domain!');
}
Do it in two steps. First, use a regex like James recommends to test for a valid(ish) e-mail address. Second, make sure the domain matches the allowed domain as Siva suggests.
You can fiddle with it here.