Pavlos1316 Posted March 11, 2010 Share Posted March 11, 2010 Hello, I have the below register.php file //database info //database connection //check if username is empty exit(); } //check ... ... password is empty exit(); } //check if username exists exit(); } //check if captcha is the same as the provided exit(); } //post to database Where ever I put the email validation code (as it is) it doesn't work even if i put 1234 for email, it accepts it. function checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) return false; list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) return true; else { try { if(!@fsockopen($Domain, 25, $errno, $errstr, 30)) throw new Exception (mysql_error()); else return true; } catch (Exception $e) { return false; } } } Thank you. Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/ Share on other sites More sharing options...
cags Posted March 11, 2010 Share Posted March 11, 2010 The eregi functions are deprecated and you should consider using the preg functions instead. Have you actually tested your code with a valid e-mail? The reason I ask is your code appears to say if the e-mail matches an e-mail pattern return FALSE. Surely you wish to return false if the pattern is not matched? Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024714 Share on other sites More sharing options...
Pavlos1316 Posted March 11, 2010 Author Share Posted March 11, 2010 Thank you. Can you link me a tutorial about preg email validation? Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024882 Share on other sites More sharing options...
cags Posted March 11, 2010 Share Posted March 11, 2010 http://www.regular-expressions.info/email.html Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024884 Share on other sites More sharing options...
Pavlos1316 Posted March 11, 2010 Author Share Posted March 11, 2010 ok.. Now I am using this, but still, where ever I put it, is not validating...!!! function checkEmail($email) { // checks proper syntax if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) { // gets domain name list($username,$domain)=split('@',$email); // checks for if MX records in the DNS if(!checkdnsrr($domain, 'MX')) { return false; } // attempts a socket connection to mail server if(!fsockopen($domain,25,$errno,$errstr,30)) { return false; } return true; } return false; } Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024919 Share on other sites More sharing options...
cags Posted March 11, 2010 Share Posted March 11, 2010 Assuming you copied the Regex correctly, then it is likely one of the other tests that is failing. Put an echo statement inside both to see which one it is. Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024921 Share on other sites More sharing options...
Pavlos1316 Posted March 11, 2010 Author Share Posted March 11, 2010 Ok you are right about one thing... Since I entered the captcha session (which is working) The pasword check if empty, stopped. (Don't know why )The thing is, it doesn't give me an error if the email is wrong... is just accepts it. exept if the captcha session conflicts that also... Here is my capthcha session just in case: session_start(); if($_SESSION['captchaCheck'] != $_POST['providedCaptcha'] && !empty($_SESSION['captchaCheck'])){ // TODO include 'register.php'; echo "<center><font color=#FF0000>Οι χαρακτήρες που γράψατε (".$_POST['providedCaptcha'].") δεν είναι οι ίδιοι με τους αναπαραγώμενους (".$_SESSION['captchaCheck'].")!</font></center>"; unset($_SESSION['captchaCheck']); exit(); } Link to comment https://forums.phpfreaks.com/topic/194892-email-validation/#findComment-1024927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.