Register.php rejecting email [message #1395] |
Thu, 11 April 2002 21:12 |
TimothyB
Messages: 2 Registered: April 2002
Karma: 0
|
Junior Member |
|
|
We ran into a problem on one of our test machines here. Everytime a user would try to register, it would reject perfectly valid email addresses. I tracked this down to email.inc in the forum_data/include directory. I also found that the second regex does not seem to operate correctly in php. Works fine in perl. Was able to fix the offending regex by replacing the function used. The posix regex function returns a different answer than the perl regex function. So, with little to do, here is the diff:
@@ -21,7 +21,14 @@ function validate_email($email) { - if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !eregi ("^.+\@(\[?)[-_a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) { +/* Lines commented out to correct problem in register.php +* +* if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !eregi ("^.+\@(\[?)[-a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) { +* +* Commented regex is BROKEN. Second regex of parse returns opposite +* value of actual. Changed to perl regex matching. +*/ + if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !preg_match("/^.+\@[-_a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})$/" ;, $email)) { return 1; } else {
This was with the new v1.2.4.
Regards, Tim
|
|
|
|
Re: Register.php rejecting email [message #1399 is a reply to message #1398] |
Thu, 11 April 2002 22:08 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
After playing with regex and reading email RFCs
I belive that this should be a good check for email validity:
return !preg_match('!([-_A-Za-z0-9\.]+)\@([-_A-Za-z0-9\.]+)\.([A-Za-z0-9]{2,4})$!' , $email);
This also fixes a small bug in the old code (your change also has it) which dissalows emails from new domain types like .info
I will do further testing, but if you can please see if this function works fine with the emails that you have.
FUDforum Core Developer
|
|
|
|
Re: Register.php rejecting email [message #29655 is a reply to message #1395] |
Sat, 07 January 2006 14:05 |
geekmug
Messages: 5 Registered: January 2006
Karma: 0
|
Junior Member |
|
|
I'm gonna drudge this back up rather than start a new topic. The current validate_email function is still incomplete. In particular, I noticed that it does not support a '+' in the local-part. I did a brief amount of research into finding a fully RFC compliant function and ran across http://www.ilovejackdaniels.com/php/email-address-validation/.
function validate_email($email)
{
// Orignally by Dave Child, 2004 (http://www.ilovejackdaniels.com/php/email-address-validation/)
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return true;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return true;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return true; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return true;
}
}
}
return false;
}
//edited to invert the boolean logic (true = invalid, instead of true = valid).
[Updated on: Sat, 07 January 2006 14:13] Report message to a moderator
|
|
|
|