Foser Posted July 9, 2007 Share Posted July 9, 2007 Im trying to do something so if there is @ in the field. it will pass but if that fields !==/ does not include @ echo Your email is not valid. is there a way to do this? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 9, 2007 Share Posted July 9, 2007 www.php.net/ereg There are a bunch of email validation functions located in the user comments. irlkersten at gmail dot com 22-Jun-2005 11:54 On a small note to email checking: Recently it is possible to register domains like www.k�che.de This would also mean that the IsEMail() function from "php at easy2sync dot com" would report an email address like "contact@k�che.de" as false. To correct this, use the function below: function IsEMail($e) { if(eregi("^[a-zA-Z0-9]+[_a-zA-Z0-9-]* (\.[_a-z0-9-]+)*@[a-z������0-9]+ (-[a-z������0-9]+)*(\.[a-z������0-9-]+)* (\.[a-z]{2,4})$", $e)) { return TRUE; } return FALSE; } Or even from www.php.net/eregi <?php //Assuming emails should have any of these combinations //$str = "aa@a.com"; //$str = "a1@a.com"; //$str = "a.1@a.com"; //$str = "a.1a1@a.com"; //$str = "a1.a1@a.com"; //$str = "a1.a_1@a.com"; //$str = "a1.a-1@a.com"; //$str = "a1.a_1-a@a.com"; //$str = "a1.a_1-a@a-a.com"; $str = "a1.a_1-a@a-a.com.do"; //Anything out of these examples echos wrong if(eregi("^[a-z]+[a-z0-9_-]*(([.]{1})|([a-z0-9_-]*))[a-z0-9_-]+ [@]{1}[a-z0-9_-]+[.](([a-z]{2,3})|([a-z]{3}[.]{1}[a-z]{2}))$",$str)) { echo "Right<br>"; } else { echo "Wrong<br>"; }; //You can enhanced this email validation by adding a list of valid domain name extensions ie.: .com,.net.,.org, ect and country specific ones too ie.: .do,.us,.br,.ve,.es, etc. in this part of the code (([a-z]{2,3})|([a-z]{3}[.]{1}[a-z]{2})) ?> If thats what you are looking for, no need to re--invent the wheel. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 9, 2007 Share Posted July 9, 2007 To simply check for the presence of a character, use the strpos() function. However, to create proper validation for email addresses, look into using regular expressions. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 9, 2007 Share Posted July 9, 2007 if (preg_match('/^[a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,4}$/i',$email)==1) { //email valid } else { //email invalid } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.