DevKB
Web Development Knowledge Base
HOME | TOP 20 | WRITE AN ARTICLE |
Sections :



RSS RSS Feed

You too, please publish your useful code snippets in any programming language :
write an article !


Valid HTML 4.0 Transitional

Plateforme d'envoi de gros fichiers en ligne
Dépannage site web
Blog infogérance
Hébergement e-mail

Olivier Ligny - - 21/08/2012 - vue 29409 fois

Check email address syntax with PHP regex

If you need to save and use email addresses that you got from user input, you need to check these addresses are valid and safe to use.
But you can't just check for a "@" sign, you need to check the syntax is really valid from the beginning to the end of the address.
 

Here is a simple regex code that detects if the emails looks valid or not :

function isValidEmail($email) { return @eregi("^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,6})$", $email); }

Example usage :

echo "Your email is : ".(isValidEmail("john@smith.com") ? "valid" : "incorrect");



Write a comment :
Your name :     E-mail (optional) :

AntiSpam : what animal is visible on this picture ? :

Nos partenaires : iPhone 8 Cases & Protection