Help in Regular Expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

Help in Regular Expression

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Help in Regular Expression

Post by twinedev »

Code: Select all

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