Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2007, 05:11 PM   PM User | #1
Schteeve
New Coder

 
Join Date: Jun 2007
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Schteeve is an unknown quantity at this point
Smile Email validation

Hi,

Am trying to integrate some code i found at ilovejackdaniels.com into my form processing script.
Can anyone point out where I'm going wrong.

PHP Code:
<?php 
$email
=$_POST['visitor_email'];

// Validate Email Address
function check_email_address($email) {
// 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 false;
}
// 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 
false;
}
}
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 
false// 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 
false;
}
}
}
return 
true;
}

if (
check_email_address($email)) {
        }
        else{
            
$error.="Please, go back and check your <strong>Email Address</strong><br><br><a href=\"javascript: history.go(-1)\">< Back</a>\n";//----> ERROR if invalid
            
}
    
//-------->ERROR FREE??
    
if($error==""){

?>
Any help would be much appreciated!
__________________
You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
<!------------o\/o-----------?>
Schteeve is offline   Reply With Quote
Old 11-08-2007, 06:47 PM   PM User | #2
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
Quote:
Can anyone point out where I'm going wrong.
Can you? We need to know what the issue is before we can help.
aedrin is offline   Reply With Quote
Old 11-09-2007, 10:10 AM   PM User | #3
Schteeve
New Coder

 
Join Date: Jun 2007
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Schteeve is an unknown quantity at this point
Sorry having trouble explaining myself

I need the code to display an error message if the email address is invalid and stop the process.

i believe it's this final else statement that's the problem, the error message does not display and the process continues.
PHP Code:
else{
            
$error.="Please, go back and check your <strong>Email Address</strong><br><br><a href=\"javascript: history.go(-1)\">< Back</a>\n";//----> ERROR if invalid
            

Sorry if this is all seems a bit vague...still quite a noob at this.
__________________
You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
<!------------o\/o-----------?>
Schteeve is offline   Reply With Quote
Old 11-09-2007, 10:13 AM   PM User | #4
nikos101
Senior Coder

 
nikos101's Avatar
 
Join Date: Dec 2006
Location: London
Posts: 1,004
Thanks: 58
Thanked 10 Times in 10 Posts
nikos101 is an unknown quantity at this point
So you input an invalid email and nothing happens?
__________________

nikos101 is offline   Reply With Quote
Old 11-09-2007, 11:02 AM   PM User | #5
Schteeve
New Coder

 
Join Date: Jun 2007
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Schteeve is an unknown quantity at this point
It's ok, have fixed the problem...sorry to have bothered you.

I Was making it much more complicated than it needed to be, as is always the way the answer was right in front of me all along!

Thanks again!!
__________________
You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
<!------------o\/o-----------?>
Schteeve is offline   Reply With Quote
Old 11-09-2007, 11:05 AM   PM User | #6
nikos101
Senior Coder

 
nikos101's Avatar
 
Join Date: Dec 2006
Location: London
Posts: 1,004
Thanks: 58
Thanked 10 Times in 10 Posts
nikos101 is an unknown quantity at this point
Please post your valid code so we can learn from it
__________________

nikos101 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:29 PM.


Advertisement
Log in to turn off these ads.