I’m using the PHP preg_match function to validate our company’s emails, which can be of the form user@mycompany.com or use a subdomain such as user@marketing.mycompany.com or user@it.mycompany.com.
return (preg_match("/^[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+(\.?mycompany\.com)$/", $testEmail) > 0)
However, the validEmail function returns false for all of the above examples I mentioned. Why?
()?) which ruled out anything @mycompany.com and @onesubonly.mycompany.com.Fun thing on the topic of email regexes (seeing “..@mycompany.com” and the like would pass yours):
http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html