Menu

Limit types of emails

Help
Chris Hood
2005-09-12
2013-06-03
  • Chris Hood

    Chris Hood - 2005-09-12

    Anyone have a quick solution or code that would allow me to edit the process.php file to only allow certain types of email to be entered into an email field on the form?  For instance if I Only wanted to allow .org email addresses to be entered into the form and .com or .net or anything else would receive the standard email error message that the address entered is not valid.

    Thanks.

     
    • TNTEverett

      TNTEverett - 2005-09-12

      Process.php can check standard email syntax. 
      Assuming the variable you want to check is named "Email".
      Here is the code that does this:
      if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
      $error.="<li>Invalid email address entered";
      $errors=1;
      }

      If you know your regular expression syntax, you can modify this section to do whatever you want. 

      $errors is the error flag
      $error is the message that is passed to the next section in process.php. 

      You will see;
      if($errors==1) echo $error;
      else{
      send email
      modify data file
      write thankyou page
      }

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.