troubleshooting Question

email regex function not working

Avatar of peter_coop
peter_coopFlag for United Kingdom of Great Britain and Northern Ireland asked on
Web DevelopmentPHP
5 Comments1 Solution274 ViewsLast Modified:
I am trying to validate email address's in a form and cannot get the code to work. It prints the messages but when a valid email address is included, it still prints the message ' echo 'You must enter a valid email address format'; '. I am using the elseif after an if statement and have only posted the relevant part of the code. Can spmeone tell me where I am going wrong? Many thanks
elseif ($email == '') {
        echo 'You must select enter an email address';
        }
      elseif ($email !=eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($email))) {
        echo 'You must enter a valid email address format';
        }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros