Jump to content

Email Validation


siri

Recommended Posts

he following code snippet always displays invalid.Here is the code snippet I used for email Validation:if(isset($_POST['submit'])){if(!eregi('^[a-zA-Z0-9-\_.]+@[a-zA-Z0-9-\_.]+\.[a-zA-Z0-9.]{2,5}$',$email)){$msg="Invalid";}else{$msg="Valid";}}Please let me know where exactly I am going wrong

Link to comment
Share on other sites

I just did some Googling and found a simpler Reg Ex syntax:

^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$

Matches: joe@aol.com|||joe@wrox.co.uk|||joe@domain.infoNon-Matches: a@b|||notanemail|||joe@@.Try that :)

Link to comment
Share on other sites

I just did some Googling and found a simpler Reg Ex syntax:
^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$

Matches: joe@aol.com|||joe@wrox.co.uk|||joe@domain.infoNon-Matches: a@b|||notanemail|||joe@@.Try that :)

It's not working .Can anyone tell me what's the mistake in my code
Link to comment
Share on other sites

The pattern Xenon posted is not completely accurate, for example it incorrectly matches this:.......@........--Here is a discussion about validating email addresses in PHP4:http://www.zend.com/zend/spotlight/ev12apr.phpThis is the pattern they use:

^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...