Jump to content

Form input question


shinytoygun

Recommended Posts

Hey Everyone,

 

My website asks for an email address when one registers but I want to put a limit it on it (like to register you gotta have an email address from a specific domain). How can I edit the form input to do this?

 

Any help will be greatly appreciated, thanks  :shy:

 

-STG

Link to comment
Share on other sites

on your post handler script have something similr to this:

<?
function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         $isValid = false;
      }
      else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         $isValid = false;
      }
   }
   return $isValid;
}
function dcheck($email,$domains=NULL)
{
  if(validEmail($email))
  {
    $tld = explode('@',$email);
    if($domains==NULL){return true;}
if(in_array($tld[1],$domains)){return true;}
  }
  return false;
}
$allowed_domains = array('hotmail.com','msn.com');
$emailok = dcheck('bob@bob.com',$allowed_domains);
if($emailok)
{
  echo "EMAIL EXISTS AND IS IN ALLOWED LIST";	
}
else
{
  echo "EMAIL DOES NOT EXISTS OR NOT IN ALLOWED LIST";
}
?>

Link to comment
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.