Forum Moderators: coopster
I removed the dashes from the code I thought were the culprit but it's still rejecting dashes. Look at the code and see if you can find it.
Here's the original code,
if(ereg("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.) ¦(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}¦[0-9]{1,3})(\]?)$", $var)) {
return TRUE;
} else {
return FALSE;
} and so I removed the dashes "-" that I thought would fix it but didn't.
Here's what it looks like now,
if(ereg("^([a-zA-Z0-9_\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.) ¦(([a-zA-Z0-9]+\.)+))([a-zA-Z]{2,4}¦[0-9]{1,3})(\]?)$", $var)) {
return TRUE;
} else {
return FALSE;
} Can you find it? Am I missing the obvious?
[edited by: dreamcatcher at 9:09 am (utc) on Dec. 21, 2007]
[edit reason] fixed side scroll [/edit]
<?php
function validate_email($email)
{
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";// Presume that the email is invalid
$valid = 0;// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}return $valid;
}
?>
Keep adding suggestions and comments....
true if you want to use regular expressions on a large volume of data (scan the pages of a book and replace a name instance for another one, for example).
in case of validating a single email adress, even if you force the server to perform some thousants such checks, you wont notice a significant improvement on speed.
Either way, this is a good note to keep in mind.