note 21271 added to function.ereg

From: Date: Mon, 06 May 2002 01:31:57 +0000
Subject: note 21271 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-30242@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 ;) -- http://www.php.net/manual/en/function.ereg.php http://master.php.net/manage/user-notes.php?action=edit+21271 http://master.php.net/manage/user-notes.php?action=delete+21271 http://master.php.net/manage/user-notes.php?action=reject+21271

« previous php.notes (#30242) next »