jmantra Posted July 25, 2007 Share Posted July 25, 2007 Hi all, I am trying to use an expression to validate an e-mail address, but if i enter a proper email addy (ie [email protected]) it tells me invalid email: <?php // check e-mail address // display success or failure message if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email'])) { die("Invalid e-mail address"); } echo "Valid e-mail address, processing..."; $file = fopen("/var/lists/flagstore/flagadd","a+"); fwrite($file, $_POST["name"] . ' '); fclose($file); ?> any help would be greatly appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/61728-email-validation-help-using-expression/ Share on other sites More sharing options...
soycharliente Posted July 25, 2007 Share Posted July 25, 2007 Don't ask questions. "/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(([,]|[, ])\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$/" Link to comment https://forums.phpfreaks.com/topic/61728-email-validation-help-using-expression/#findComment-307289 Share on other sites More sharing options...
stlewis Posted July 26, 2007 Share Posted July 26, 2007 Don't ask questions. "/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(([,]|[, ])\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$/" Hmm...I'm going to have to try that one Charlie... This one is fairly simple, actually readable...and hasn't screwed up on me yet... '/^[a-z0-9.-_]+@[a-z0-9.-_]+\.[a-z]{2,4}$/' Link to comment https://forums.phpfreaks.com/topic/61728-email-validation-help-using-expression/#findComment-308116 Share on other sites More sharing options...
soycharliente Posted July 26, 2007 Share Posted July 26, 2007 But does that account for e-mails like [email protected] ? Mine takes into account up to 4 dots in the domain as well Link to comment https://forums.phpfreaks.com/topic/61728-email-validation-help-using-expression/#findComment-308191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.