studgate Posted February 20, 2011 Share Posted February 20, 2011 hey guys, you guys never seem to amaze me so this is the best place to post my question. I am looking for a check email function that will check if the entered email address is an education email address (ending with .edu) for example: me@anyschool.edu. thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/ Share on other sites More sharing options...
cssfreakie Posted February 20, 2011 Share Posted February 20, 2011 I bet preg_match can do the trick. give me a minute ill think about a regex for that edit: this is what i have, but as always Pickachu's solution is better <?php $pattern = "~^[a-zA-Z0-9\_\-]+[a-zA-Z0-9\.\_\-]*@([a-zA-Z0-9\_\-]+\.)+(edu)$~"; $subject = 'lalala@lalala.edu'; //your POST var in there if(preg_match($pattern, $subject)){ echo 'correct emailadres'; }else{ echo 'incorrect emailadres'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177358 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 Or since it's better not to use a pattern when other functions will suffice . . . $address = 'my.mail@uni.versi.ty.edu'; $explode = explode('.', $address); if( array_pop($explode) === 'edu' ) { echo 'Good Address'; } else { echo 'Bad Address'; } Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177360 Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 On second thought, have you already validated that the email address is valid at the point where you want to check to see if it's a .edu address? If not, then a pattern, or possibly filter_var would be appropriate. If you just want to separate the .edu addresses out from already validated addresses, the way I posted is fine. Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177362 Share on other sites More sharing options...
studgate Posted February 20, 2011 Author Share Posted February 20, 2011 I already validated the email address and want to check that it is .edu email address... i want any email address which ended with .edu to be accepted... Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177363 Share on other sites More sharing options...
cssfreakie Posted February 20, 2011 Share Posted February 20, 2011 well than pickachu just gave you what you want Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177364 Share on other sites More sharing options...
studgate Posted February 21, 2011 Author Share Posted February 21, 2011 thanks guys , I am gonna test and reply or mark as solved Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177366 Share on other sites More sharing options...
studgate Posted February 21, 2011 Author Share Posted February 21, 2011 hey guys, it works fine for me... thanks to cssfreakie and Pikachu2000 for the help, I appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177375 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.