Hide options

Email address validator

This small function validates the input of a string and return true when an emailaddress is given or false when it's not a valid emailaddres
<?php
   /*
    * Function that checks if the given string is valid
    * In:  String representing an emailaddress
    * Out: Boolean true or false
   */

   function is_valid_email($email) {
      // Checks for proper email format
      if (! preg_match( '/^[A-Za-z0-9!#$%&'*+-/=?^_`{|}~]+@[A-Za-z0-9-]+(.[AZa-z0-9-]+)+[A-Za-z]$/', $email)) {
         return false;
      }
      else {  
         return true;
      }
   }
?>


Description

PHP function to test email addresses


Top