xenophobia Posted May 20, 2008 Share Posted May 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted May 20, 2008 Share Posted May 20, 2008 <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> Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 23, 2008 Author Share Posted May 23, 2008 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? Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 23, 2008 Author Share Posted May 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted May 23, 2008 Share Posted May 23, 2008 /^\S+@(?!yahoo|hotmail)\S+\.\S+$/i Quote Link to comment Share on other sites More sharing options...
xenophobia Posted May 26, 2008 Author Share Posted May 26, 2008 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~ Quote Link to comment Share on other sites More sharing options...
effigy Posted May 27, 2008 Share Posted May 27, 2008 Try this; it reinforces the domain by looking for a following period: /^\S+@(?!(?:yahoo|hotmail)\.)\S+\.\S+$/i Quote Link to comment Share on other sites More sharing options...
xenophobia Posted June 3, 2008 Author Share Posted June 3, 2008 Thanks! It work perfectly! You are a geniuses. Thank you. Quote Link to comment 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.