siddharthjhala Posted February 2, 2013 Share Posted February 2, 2013 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 More sharing options...
codebyren Posted February 2, 2013 Share Posted February 2, 2013 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... } ?> Link to comment https://forums.phpfreaks.com/topic/273946-email-validation-error/#findComment-1409688 Share on other sites More sharing options...
siddharthjhala Posted February 2, 2013 Author Share Posted February 2, 2013 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! Link to comment https://forums.phpfreaks.com/topic/273946-email-validation-error/#findComment-1409697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.