Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: PHP
Expertise: Beginner
Oct 19, 2004



Application Security Testing: An Integral Part of DevOps

Validating Email Addresses with Regular Expressions in PHP

Most Web forms designed in PHP are made for user interaction. This generally means information exchange, and the most common way this is done is via email.

Because of this, validating email addresses for misprints or false entries is crucial for succesful interactions.

The following class is small and very easy to use. It uses regular expressions for validating email adresses.


class email{

function valid($str)
	if (ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $str))
		return 1;
		return 0;

---------Example usage---------------------------------------

$check_valid = new email;

  echo "<br> Email is valid";
  echo "<br> Email is not valid";

Cem Aykan
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date