-1

Hello I want to check if email is valid like blabla@blabla.com and not like just plain text 'BLbalbalba'.

I have this function:

function VerifyEmail($address) 
{
   $Syntax='#^[w.-]+@[w.-]+.[a-zA-Z]{2,5}$#';
   if(preg_match($Syntaxe,$adrdess))
      return true;
   else
     return false;
}

And checking it like this:

    $email = htmlentities($_POST['email']);
if (!empty($email) && !empty($password) && !empty($message) && VerifyEmail($email) === true) {

Getting these errors:

Notice: Undefined variable: Syntaxe in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Notice: Undefined variable: adrdess in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Warning: preg_match() [function.preg-match]: Empty regular expression in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Notice: Undefined variable: Syntaxe in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Notice: Undefined variable: adrdess in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Warning: preg_match() [function.preg-match]: Empty regular expression in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Why is this happening? What did I do wrong? Is it a stable way of checking if email is valid? Thanks!

purepksor purepk
  • 133
  • 1
  • 11

2 Answers2

5

No, it's not "stable", it's not "valid", and it will not do a good job. use

filter_var($email, FILTER_VALIDATE_EMAIL)

instead. relevant docs: http://www.php.net/manual/en/function.filter-var.php

Marc B
  • 356,200
  • 43
  • 426
  • 500
3

some spelling mistakes here

should be

function VerifyEmail($address) 
{
   $Syntax='#^[w.-]+@[w.-]+.[a-zA-Z]{2,5}$#';
   if(preg_match($Syntax,$address))
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100