note 21271 rejected from function.ereg by torben
| From: | torben@php.net | Date: | Mon, 06 May 2002 01:45:33 +0000 |
| Subject: | note 21271 rejected from function.ereg by torben | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-30244@lists.php.net to get a copy of this message | ||
If you're looking for an email-validator, this might be what you're looking for.
<?php
$re = "^[^-._]+[-._a-zA-Z0-9]+@{1}";
// A string that does not begin with a dash, dot or underscore,
// but with At least one alpha-numerical character,
// including dots, dashes and underscores.
// Followed by exactly one @.
$re .= "[-._a-zA-Z0-9]*[-_a-zA-Z0-9]{2,}";
// Followed by an optional amount of alphanumerical characters
// (sub domains) including dots, dashes and underscores.
// Followed by at least two alphanumerical characters (domain)
// including dashes and underscores (no dots!).
$re .= "[.]{1}[a-zA-Z]{2,3}$";
// Followed by exactly one period.
// Followed by two or three alpha-characters (com/org/net etc)
// at the end of the string.
$email = "my-email.address@sub.domain.ext";
if (ereg($re, $email))
echo "$email seems valid!";
?>
I have tried all kinds of variations, and I think it is pretty complete. I'm not sure if an
email address may start with a dash or underscore, so the first match might just be [^.].
Please correct me if I'm wrong, I'm not (yet) an expert at regular expressions or
email-specifications ;)