<form method=post action=''>Enter any email address
<input type=text name=email value=$email>
<input type=submit value=Check>
<input type=hidden value=test name=todo>
</form>
$email=$_GET['email']; // GET method
$email=$_POST['email']; // POST method
Here is the code of this validation in PHP, using preg_match()
if(!preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^",$email))
{
echo "<center><font face='Verdana' size='2' color=red>Invalid email</font></center>";
}else{
echo "<center><font face='Verdana' size='2' color=green>Valid Email</font></center>";
}
Same validation is done by using eregi()
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
echo "<center>Invalid email</center>";
}else{
echo "<center>Valid Email</center>";
}
if (!stristr($em,"@") OR !stristr($em,".")) {
$msg="Your email address is not correct <BR>";
$status= "NOTOK";
} else {
echo " Your email address is OK ";
}
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
good | 22-05-2013 |
its interestiing..!! |
albusaidy | 16-11-2014 |
worked great for me.. I love the fact that the page I was working on stayed on screen, and script showed where change needed to be made. Awesome Is there a way to make sure people do not enter www. in front of their email, it happens often. |
John S | 17-04-2019 |
Hello, eregi() is deprecated as of PHP 5.3 Thanks. |