samoi Posted October 13, 2009 Share Posted October 13, 2009 Hello Guys! Look through this code: <?php /** * @author samoi * @copyright 2009 */ error_reporting(E_ALL & E_NOTICE); include ('func.php'); if (!isset($_POST['submit'])) { echo '<form action="" method="post"> username: <input type="text" name="username" /> <br /> password: <input type="password" name="password" /> <br /> email: <br /> <input type="text" name="email" /> <input type="submit" name="submit" value="register" /> </form>'; } else { if (!empty($_POST['username'])) { if (!empty($_POST['password'])) { if (!empty($_POST['email'])) { $email = $_POST['email']; if (!preg_match('/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})\be(\w*)s\b/', $email)) { echo 'Enter a valid email format!'; exit; } else { $user = $_POST['username']; $pass = md5($_POST['password']); if (checkreg($user, $email)) { register($user, $pass, $email); echo 'Welcome ' . $user . ' You have been sent an email regarding your registration!'; } else { echo 'There is a user or email with that user or email you entered!'; } } } else { echo 'Email is not entered!'; exit; } } else { echo 'Password is not entered!'; exit; } } else { echo 'User is not entered!'; exit; } } ?> problem: Everything goes great except for the email validation ! It keeps giving me that the email is wrong format! Help me please! Quote Link to comment https://forums.phpfreaks.com/topic/177495-solved-email-validation-through-preg_match-registration-form/ Share on other sites More sharing options...
cbrooks Posted October 13, 2009 Share Posted October 13, 2009 you might try the following function: function valid_email($address) { // check an email address is possibly valid if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $address)) { return true; } else { return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/177495-solved-email-validation-through-preg_match-registration-form/#findComment-935852 Share on other sites More sharing options...
samoi Posted October 13, 2009 Author Share Posted October 13, 2009 Thank you very much man! that helps alot! Quote Link to comment https://forums.phpfreaks.com/topic/177495-solved-email-validation-through-preg_match-registration-form/#findComment-935878 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.