siri Posted March 5, 2007 Share Posted March 5, 2007 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 More sharing options...
Xenon Design Posted March 5, 2007 Share Posted March 5, 2007 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 More sharing options...
siri Posted March 5, 2007 Author Share Posted March 5, 2007 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 More sharing options...
Xenon Design Posted March 5, 2007 Share Posted March 5, 2007 Try just using ereg instead of eregi. Encapsulation wont matter in an email input. Try outputting the answer in print so you see what your dealing with. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 5, 2007 Share Posted March 5, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now