TechniqueUse the following regular expression. (The double escapes are for double quotation marks; use single escapes for single quotation marks.) ^([a-z0-9_]\-\.)+@(([a-z0-9_]\-)+\.)+[a-z]{2,4}$ CommentsTo call this code, you must use eregi () . ( ereg() will not work because the search needs to be case-insensitive.) Here is how you might call this code in a Web page: <?php if (!eregi ("^([a-z0-9_]\-\.)+@(([a-z0-9_]\-)+\.)+[a-z]{2,4}$", $email)) die ("Invalid E-mail"); ?> The previous regular expression is a PHP-compatible global e-mail-checking regular expression, but it is not the most secure way of checking an e-mail address. For example, somebody@something-foo.cde would be validated because it is in the correct format, but it is obviously not a valid e-mail address. |