Check email address format (PHP & Javascript)

Here are two code snippets to verify email addresses, which is quite useful when you wish to validate a form with Javascript or PHP, avoiding users to write anything as email.

Verify email format with Javascript

Insert this code between <head> and </head> tags of your HTML document :

Insert a form between <body> and </body> tags :

Eventonsubmit calls checkMail() function and gives him text value of email field. Email field is identified by ID email.

Try this script online

Verify email format with PHP

This little PHP function allows you to check if the user wrote a valid email address that may exist. You call this function when you’re checking POST values after form submission.

function validMail($addr) {
if ((!ereg(“.+\@.+\..+”, $addr)) || (!ereg(“^[a-zA-Z0-9_@.-]+$”, $addr)))
// Use :
if(!validMail(‘’)) {
echo “Your email address is invalid!”;

It won’t prove real existence of the email address, but it will avoid the user from writing stupid stuff.

Ce message est également disponible en : French

32 thoughts on “Check email address format (PHP & Javascript)

  1. Slots on Net

    it runs two php scripts when followed first adds the deny from IP to the .ht access that’s in the root below all directories {except the directory containing the error pages and php scripts for blacklisting

  2. radwa

    this error is detected and i can’t fised it 🙁

    Deprecated: Function ereg() is deprecated in C:\Program Files\EasyPHP-\www\Admin-php\phpcheck.php on line 29
    Invalid email


    Preserving Venice, which is sinking one to two millimetres each year, has been the city and the Italian governments focus, with the first stages of the going into effect in 2013. The 78 floodgates installed in the lagoon will eventually close off the three inlets during high tides, blocking them from swamping the city.

  4. Lebron Women shoes

    in Clerkenwell is a special place. Its rooms are small but big on personality. Its restaurant, Bistrot Bruno Loubet, and Atrium Bar, with alfresco drinking,Michael Kors Outlet, are superb (8688 Clerkenwell Rd; rooftop studios from 300).


    I could be a boxer or a sword fighter or a horseback [rider].
    ‘Users almost always pay with credit card; their purchase details are not removed as promised,
    and include real name and address, which is of course the most important information the users want removed.
    Researchers are looking to invest in something that they can benefit or get a cut from.

    My page hay day hack (

  6. wedding guest maxi dress

    Cheap Bridesmaid Dresses and Bridal Party Gowns – Cheap bridal party dresses and long formal gowns.Shop range of bridesmaids’ dresses, incl. elegant or embellished dresses, tulle, lace & chiffon styles, perfect for a big day on a budget!Cheap Bridesmaid Dresses Online | Bridesmaid Dresses for 2019.Fast shipping. Get the perfect bridesmaid dress under 100 for your special day! You can select red or pink bridesmaids dresses under affordable price.
    wedding guest maxi dress

Leave a Reply

Your email address will not be published. Required fields are marked *