Ignore:
Timestamp:
Jun 12, 2012, 1:27:14 PM (12 years ago)
Author:
mistic100
Message:

check email validity before subscribe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Subscribe_to_comments/include/functions.inc.php

    r15641 r15648  
    157157 
    158158  // check email
     159  if ( !empty($email) and !is_valid_email($email) )
     160  {
     161    array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     162    return false;
     163  }
    159164  if ( ( is_a_guest() or empty($user['email']) ) and empty($email) )
    160165  {
     
    679684
    680685/**
     686 * check if mail adress is valid
     687 * @param: string email
     688 * @return: bool
     689 */
     690function is_valid_email($mail_address)
     691{
     692  if (version_compare(PHP_VERSION, '5.2.0') >= 0)
     693  {
     694    return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
     695  }
     696  else
     697  {
     698    $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
     699    $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
     700    $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
     701
     702    if (!preg_match($regex, $mail_address)) return false;
     703    return true;
     704  }
     705}
     706
     707
     708/**
    681709 * crypt a string using mcrypt extension or
    682710 * http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php/802957#802957
Note: See TracChangeset for help on using the changeset viewer.