Page 1 of 1

Help in Regular Expression

Posted: Mon Jul 11, 2011 5:50 am
by tamilmani
HI All,

My Issue:-

I need to filter the email in PHP. I need to accept corporate email id. No need to accept gmail,yahoo,aol,rediff,hotmail, etc email ids.

This is my sample regular expression PHP code

Code: Select all

if(isset($_POST['email']))
{
	$str	=	$_POST['email'];
	$res	=	!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([gmail|yahoo|rediff|hotmail|aol]+\.)+[a-z]{2,6}$/",$str);
	print_r($res);
	echo "<br>";
	if($res)
	{
		echo "Correct Email Address";
	}
	else
	{
		echo "Wrong Email Address";
	}
}


For example: - when i try to run this email id "info@aitrg.com"- I am getting wrong email Address error message.

Is there any problem in code?

Please any one give me the suggestion for this problem?

Thanks
Tamilmani Mohan

Re: Help in Regular Expression

Posted: Mon Jul 11, 2011 6:58 am
by twinedev

Code: Select all

!preg_match(/^[a-z0-9._%+-]+@aitrg.com$/',$str);