Pavlos1316 Posted March 13, 2010 Share Posted March 13, 2010 I have this code for email validation: function checkEmail($email) { // checks proper syntax if(preg_match[color=red]("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) [/color] { // 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; } I want to insert/replace this line in: [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b Where exactly do I put it (I Know that is in the red letter area) but what do I have to delete from there? Thank you Link to comment https://forums.phpfreaks.com/topic/195123-code-replacement-help/ Share on other sites More sharing options...
cags Posted March 13, 2010 Share Posted March 13, 2010 I assume that's just a more comprehensive e-mail Regex than the one currently used, so it simply one's to replace the currently Regex. This means it would theoretically replace... ( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+ But since the new pattern seems to use the forward slash character (/) and you appear to also use that in your pattern, you will need to replace the forward slashes in the new pattern with... \/ To escape them. Link to comment https://forums.phpfreaks.com/topic/195123-code-replacement-help/#findComment-1025632 Share on other sites More sharing options...
Pavlos1316 Posted March 13, 2010 Author Share Posted March 13, 2010 Thanks for replying.. If I understood right my code from this: if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) { will become this: if(preg_match("/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b $/" , $email)) { I dind't get with what I replace the / Link to comment https://forums.phpfreaks.com/topic/195123-code-replacement-help/#findComment-1025637 Share on other sites More sharing options...
cags Posted March 13, 2010 Share Posted March 13, 2010 You have used the forward slash as the delimiter for the pattern. This means that all forward slashes in the pattern must be escaped. Characters are escaped using a backslash, thus you need to replace the forward slashes in the pattern with a backslash then a forward slash. IE replace / with \/ as I said in my last post. Link to comment https://forums.phpfreaks.com/topic/195123-code-replacement-help/#findComment-1025643 Share on other sites More sharing options...
Pavlos1316 Posted March 13, 2010 Author Share Posted March 13, 2010 Oh.. ok... I thought the \/ was a typing mistake... sorry for that.. I will give it a try... Thank you.. OH... do I replace the forward slash here also? +)+$/" , $email)) { Link to comment https://forums.phpfreaks.com/topic/195123-code-replacement-help/#findComment-1025644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.