Menu

Email validation in PHP

  • Email validation is a part of validation in PHP.
  • eregi function is helpful for checking email validation using PHP.
  • We can check the email is added in a proper email format.
  • You can enter any email address and can check the email is valid or not. This tutorial is helpful for knowing more about PHP form validation.

How to receive the email address

  • There are two ways to receive the email address.
  • They are GET and POST methods.
  • The GET method is used to receive the email address using URL and the POST Method is used for receiving using the POST Method.
  • The POST method is more secure than GET method and is secure.

Using Get Method:

        $email = $_GET['email_address'];

Using Post Method:

        $email = $_POST['email_address'];

Email validation code in PHP

<?php
            if (!eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email)){ 
                echo 'You entered valid email address';
            }else{
                echo 'The email address you entered is incorrect';
            }
        ?>
  • Better use preg_match