Jump to content

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: me@anyschool.edu.

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 = 'lalala@lalala.edu'; //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 = 'my.mail@uni.versi.ty.edu';
$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

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.