Jump to content

[SOLVED] Regex Help~


xenophobia

Recommended Posts

Alright, I want a searching regex statement to achieve this:

 

I want to search for an email address that is under the specified domain. Eg:

I want all the user under this domain: yahoo.

So:

aaa@yahoo.com will return true.

bbb@yahoo.com will return true.

ccc@yahoo.com will return true.

... so on....

while

aaa@hotmail.com will return false.

bbb@anydomain.com will return false.

ccc@mydomain.org will return false.

 

any idea? I am bad in REGEX. I need you guy's help.

Link to comment
Share on other sites

<pre>
<?php
$data = <<<DATA
Alright, I want a searching regex statement to achieve this:

I want to search for an email address that is under the specified domain. Eg:
I want all the user under this domain: yahoo.
So:
aaa@yahoo.com will return true.
bbb@yahoo.com will return true.
ccc@yahoo.com will return true.
... so on....
while
aaa@hotmail.com will return false.
bbb@anydomain.com will return false.
ccc@mydomain.org will return false.

any idea? I am bad in REGEX. I need you guy's help.
DATA;

preg_match_all('/\S+@yahoo\.com/', $data, $matches);
print_r($matches);
?>
</pre>

Link to comment
Share on other sites

preg_match_all('/\S+@yahoo\.com/', $data, $matches);

print_r($matches);

 

Alright, the regex work fine.

 

Now i got a small request. How if i want to match more than just yahoo? Example like i want hotmail to be return true also. meaning:

abc@yahoo.com -> return true

abc@hotmail.com -> return true also

 

maybe i will have more than one email domain. How can I do that?

Link to comment
Share on other sites

Alright. After figuring, I got this:

 

/^\S+@(?:yahoo|hotmail)\.\S*$/Uis

 

whereby if user enter any domain with yahoo or hotmail, it will return true. Now what I want is, I want to negate it! Meaning, if user using yahoo or hotmail, i want it to return false. How to do it!?

 

Please help!!!

 

Thank in advanced.

Link to comment
Share on other sites

That work fine if user entered: abc@gahoo.com or efg@yaho.com

 

But if user enetered: abc@yahoos.com, it return false too! Meaning, it match! Suppose it is not.

 

Is it putting something like \b in between the `group`? But I tried, failed...

 

Please guide! Thanks a lot effigy~

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.