Sunday, 1 February 2015

Email Validation

If user enter invalid email we can validate it using filter_var() function using previous example
http://php-guidelines.blogspot.com/2015/02/form-validation.html:

replace following if statement  of email :

<?php
 if (empty($_POST["email"])) {
    $emailErr = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is valid or not
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format"; 
    }
  }

?>

Output Print


No comments: