php validate email - Web Development and Web Design Codes

Latest

Thursday, March 1, 2018

php validate email

PHP Email Validation 

PHP filter_var() function are used to check given email is well formed or not..
ex..
email: abc@@gmail.com -->result= not valid
email: abc@gmail.com -->result= valid
below php codes are used check email address is valid or not..
php validate email
php validate email
validate.php
  <form method="POST" action="">
  <table>
     <tr>
    <td><b>Email:</b></td>
    <td><input type="text" name="email"/></td>
  </tr>
   <tr>
    <td></td>
    <td><input type="submit" name="submit" value="Validate"/></td>
  </tr>
  </table>
  </form>
<?php
if(isset($_POST['submit'])){
 
$email =$_POST["email"];
 if(!empty($email)){
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo '<b style=color:red>'.$email.'</b> is Not Valid Email'; 
}else{
 echo '<b style=color:green>'.$email.'</b> is Valid Email';
}
 }else{
  echo 'Email Address Required';
 }
}
?>

That's it Friends how to validate email address in php..thank you for visiting..

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.