Jump to content

Code replacement help!


Pavlos1316

Recommended Posts

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

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.

 

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 /    :shrug:  :)

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.