Jump to content

.EDU email Only


studgate

Recommended Posts

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: [email protected].

thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/228323-edu-email-only/
Share on other sites

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 = '[email protected]'; //your POST var in there


          if(preg_match($pattern, $subject)){
              echo 'correct emailadres';
          }else{
              echo 'incorrect emailadres';
          }
          ?>

Link to comment
https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177358
Share on other sites

Or since it's better not to use a pattern when other functions will suffice . . .

 

$address = '[email protected]';
$explode = explode('.', $address);
if( array_pop($explode) === 'edu' ) {
echo 'Good Address';
} else {
        echo 'Bad Address';
}

Link to comment
https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177360
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/228323-edu-email-only/#findComment-1177362
Share on other sites

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.