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 jmantra@domain.com) 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 Quote Link to comment 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+)*)*$/" Quote Link to comment 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}$/' Quote Link to comment 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 first.last@gwinnett.k12.ga.us ? Mine takes into account up to 4 dots in the domain as well Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.