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: [email protected] will return true. [email protected] will return true. [email protected] will return true. ... so on.... while [email protected] will return false. [email protected] will return false. [email protected] will return false. any idea? I am bad in REGEX. I need you guy's help. Link to comment https://forums.phpfreaks.com/topic/106393-solved-regex-help~/ 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: [email protected] will return true. [email protected] will return true. [email protected] will return true. ... so on.... while [email protected] will return false. [email protected] will return false. [email protected] 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 https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-545709 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: [email protected] -> return true [email protected] -> return true also maybe i will have more than one email domain. How can I do that? Link to comment https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-547838 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. Link to comment https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-547948 Share on other sites More sharing options...
effigy Posted May 23, 2008 Share Posted May 23, 2008 /^\S+@(?!yahoo|hotmail)\S+\.\S+$/i Link to comment https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-548054 Share on other sites More sharing options...
xenophobia Posted May 26, 2008 Author Share Posted May 26, 2008 That work fine if user entered: [email protected] or [email protected] But if user enetered: [email protected], 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 https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-549984 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 Link to comment https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-550760 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. Link to comment https://forums.phpfreaks.com/topic/106393-solved-regex-help~/#findComment-556265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.