I don't know why, but whenever I enter an email it keeps coming up as invalid! Can someone help me figure out why it's coming out as invalid? also, is there a way to debug this, so I will know how in the future? Thanks <?php // Function used to check e-mail syntax function validateEmail($email) { // Create the e-mail validation regular expression $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+) (\.[a-z0-9-]+)*(\.[a-z]{2,6})$"; // Validate the syntax if (eregi($regexp, $email)) return 1; else return 0; } // Has the form been submitted? if (isset($_POST['submit'])) { $name = htmlentities($_POST['name']); $email = htmlentities($_POST['email']); printf("Hi %s<br />", $name); if (validateEmail($email)) printf("The address %s is valid!", $email); else printf("The address <strong>%s</strong> is invalid!", $email); } ?> <form action="subscribe.php" method="post"> <p> Name:<br /> <input type="text" id="name" name="name" size="20" maxlength="40" /> </p> <p> E-mail Address:<br /> <input type="text" id="email" name="email" size="20" maxlength="40" /> </p> <input type="submit" id="submit" name = "submit" value="Go!" /> </form> PHP:
function validateEmail($email) { // Create the e-mail validation regular expression $regexp = "~^([_a-z0-9\-]+)(\.[_a-z0-9\-]+)*@([a-z0-9\-]+) (\.[a-z0-9\-]+)*(\.[a-z]{2,6})$~"; // Validate the syntax if (preg_match($regexp, $email)) return true; else return false; } PHP:
<?php $email = "xx@xx.com"; if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { echo "Valid email address."; } else { echo "Invalid email address."; } ?> PHP: regards...
Just wanted to say, that the majority of email address would be in the format of if the email address your trying to validate contains any symbols or extra .dots you must allow your preg_match pattern to allow for this. So although this thread is a few days old, if you do reply, please post an example of the email address your trying to validate.