Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid email address using preg_match [duplicate]

Tags:

php

Possible Duplicate:
How to validate an email in php5?

I have used the following code to ensure email addresses provided on signup are valid.

(!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email))

I entered a standard email address such as

[email protected]

and it is flagging up as being invalid.

Can anyone help me with why this may be happening?

like image 430
sark9012 Avatar asked Jun 23 '11 11:06

sark9012


1 Answers

Why not just use filter_var

var_dump(filter_var($email,FILTER_VALIDATE_EMAIL));

EDIT

if(filter_var($email,FILTER_VALIDATE_EMAIL) === false)
{
   echo 'Email is not valid';
}
else
{
   //do the stuff
}
like image 77
Shakti Singh Avatar answered Oct 23 '22 12:10

Shakti Singh