I am using a regular expression to validate email addresses in an online form. A lot of emails are entered as such: www.test@example.com
How can I disallow the use of www. using regex? My current expression:
^[\+_a-z0-9-'&=]+(\.[\+_a-z0-9-']+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$
I know this expression checks for a gTLD - we require an email address to have one.
EDIT: This question is slightly different to others I have found as I wasn't sure how to add the www
exclusion in - that's all I needed.
Also, the target market we reach doesn't have the same experience using technology as most people do, so the amount of email addresses that we receive with www
in them is massive. www.john@gmail.com
is perfectly valid yes but it is 99% of the time not what the persons email address is. Our CRM system can't send emails to the correct people then.
you can use the regex
^(?!www\.)[\+_a-z0-9-'&=]+(\.[\+_a-z0-9-']+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$
see the regex demo