Jump to content

email validation error


siddharthjhala

Recommended Posts

Hi fellow geeks I need some help in creating my first website.

 

I am stuck with email validation, I have checked plenty of links from google but I am just not able to get through with email validation.

I would be greatful if you can help me with it.

 

This is the code where I am facing issues..

if(preg_match('/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/',$eml))
  {
   die("invalid email address");
   $flag=false;
  }

 

now whenever I try inserting a valid email address, it pops up an error as:

 

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\xampp\htdocs\cms_xhtml\customerinsert.php on line 159

 

please give me a solution to this issue or give me some other email validation code which can replace the above mentioned code.

Thank you again, gracias

Link to comment
https://forums.phpfreaks.com/topic/273946-email-validation-error/
Share on other sites

Firstly, the delimiters look fine - are you sure the "no ending delimiter" error is the one you are still getting?

 

Secondly, preg_match will only return FALSE if $eml does NOT match the pattern - so your IF statement isn't quite right as it will die with the "invalid email address" message for emails that match the pattern. You could negate the condition to fix this:

 

<?php
if ( ! preg_match($pattern, $subject)) {
// no match...
}
?>

 

Finally, you could use php's filter_var function for email validation if your server has PHP 5 >= 5.2.0:

 

<?php
if (filter_var('[email protected]', FILTER_VALIDATE_EMAIL)) {
// email appears ok...
}
?>

Firstly, the delimiters look fine - are you sure the "no ending delimiter" error is the one you are still getting?

 

Secondly, preg_match will only return FALSE if $eml does NOT match the pattern - so your IF statement isn't quite right as it will die with the "invalid email address" message for emails that match the pattern. You could negate the condition to fix this:

 

<?php
if ( ! preg_match($pattern, $subject)) {
// no match...
}
?>

 

Finally, you could use php's filter_var function for email validation if your server has PHP 5 >= 5.2.0:

 

<?php
if (filter_var('[email protected]', FILTER_VALIDATE_EMAIL)) {
// email appears ok...
}
?>

 

yes that is the error I am facing!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.