B.B King
B.B King

Reputation: 111

How to validate emails in PHP using filter_var() function.

i have this line for validation email and non empty email field:

if ( filter_var($tmpEmail, FILTER_VALIDATE_EMAIL)  == TRUE) || (!empty($email)) {
...
}

but i see this error :

Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in 

how to fix this error?

Upvotes: 0

Views: 535

Answers (3)

samayo
samayo

Reputation: 16495

Try filter_var() function from the PHP manual, which can manipulate/validate strings orders.

$email = '[email protected]'; 
if ((filter_var($email, FILTER_VALIDATE_EMAIL) == TRUE) || !empty($email)) {
   // your email is correct. 
}

Upvotes: 0

Alasjo
Alasjo

Reputation: 1240

The ) after TRUE ends the if statement, remove that and the ( before !empty.

Upvotes: 2

000
000

Reputation: 27227

Your parentheses are mismatched. Try:

if ( filter_var($tmpEmail, FILTER_VALIDATE_EMAIL) || !empty($email)) {

Upvotes: 2

Related Questions