DIGIT-ARC read-only archive · snapshot: July 23, 2026

unable to validate email address in php

4 posts · originally from https://geek.digit.in/community/threads/unable-to-validate-email-address-in-php.135628/

cute.bandar
cute.bandar Original post #1
Jan 3, 2011 at 12:53 AM
This should work, but I just can't figure out what wrong here. HOping that there is something simple I am missing

Code:
function email_valid ($email) 
        {  
          if (preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) 
                        return true;
          else  return false;
          
        }
if ( email_valid($email)  == FALSE ) ;
{
      $errors[] = "notemail" ;
}
In this email_valid always returns false , no matter what the parameter is.
What is wrong here. Every email address supplied is treated as invalid.
Help!
khmadhu
khmadhu #2
Jan 3, 2011 at 12:05 PM
u have a typo here..
if ( email_valid($email) == FALSE ) ;

why there is a semicolon at the end of if statement!! ?

remove that it will work.. :)

and a tip for u..
and in regex if u r giving /i at the end u dont need to specify A-Z
cooljeba
Jan 3, 2011 at 12:10 PM
that's the problem with regex.. it is so complex..
cute.bandar
Jan 3, 2011 at 12:58 PM
why there is a semicolon at the end of if statement!! ?
dammnit! that was the error. I spent hours trying to fix this. arghhh!

thanks man