php email validation using regular expression


<?php
if(isset($_POST["submit"]))
{
$email=$_POST["email"];
$pattern="/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/";
if(preg_match($pattern,$email))
{
$msg="valid email";
}
else
{
$msg="inavlid email";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<form method="post">
<label>email</label>
<input type="text" name="email"><?php if(isset($msg)){ echo $msg; } ?><br>
<input type="submit" name="submit">
</form>
</body>
</html>

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post