API15

Difference between revisions of "JMailHelper/isEmailAddress"

From Joomla! Documentation

< API15:JMailHelper
(New page: ===Description=== Verifies that the string is in a proper e-mail address format. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JMailHelper/isEmailA...)
 
m (preparing for archive only)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JMailHelper/isEmailAddress|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JMailHelper/isEmailAddress}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 99: Line 99:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JMailHelper/isEmailAddress|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JMailHelper/isEmailAddress}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=isEmailAddress
 
  category=isEmailAddress
 
  category=JMailHelper
 
  category=JMailHelper
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 19:57, 24 March 2017

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Verifies that the string is in a proper e-mail address format.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

isEmailAddress($email)
Parameter Name Default Value Description
$email $email String to be verified.

Returns[edit]

boolean True if string has the correct format; false otherwise.

Defined in[edit]

libraries/joomla/mail/helper.php

Importing[edit]

jimport( 'joomla.mail.helper' );

Source Body[edit]

function isEmailAddress($email)
{

        // Split the email into a local and domain
        $atIndex        = strrpos($email, "@");
        $domain         = substr($email, $atIndex+1);
        $local          = substr($email, 0, $atIndex);

        // Check Length of domain
        $domainLen      = strlen($domain);
        if ($domainLen < 1 || $domainLen > 255) {
                return false;
        }

        // Check the local address
        // We're a bit more conservative about what constitutes a "legal" address, that is, A-Za-z0-9!#$%&\'*+/=?^_`{|}~-
        $allowed        = 'A-Za-z0-9!#&*+=?_-';
        $regex          = "/^[$allowed][\.$allowed]{0,63}$/";
        if ( ! preg_match($regex, $local) ) {
                return false;
        }

        // No problem if the domain looks like an IP address, ish
        $regex          = '/^[0-9\.]+$/';
        if ( preg_match($regex, $domain)) {
                return true;
        }

        // Check Lengths
        $localLen       = strlen($local);
        if ($localLen < 1 || $localLen > 64) {
                return false;
        }

        // Check the domain
        $domain_array   = explode(".", rtrim( $domain, '.' ));
        $regex          = '/^[A-Za-z0-9-]{0,63}$/';
        foreach ($domain_array as $domain ) {

                // Must be something
                if ( ! $domain ) {
                        return false;
                }

                // Check for invalid characters
                if ( ! preg_match($regex, $domain) ) {
                        return false;
                }

                // Check for a dash at the beginning of the domain
                if ( strpos($domain, '-' ) === 0 ) {
                        return false;
                }

                // Check for a dash at the end of the domain
                $length = strlen($domain) -1;
                if ( strpos($domain, '-', $length ) === $length ) {
                        return false;
                }

        }

        return true;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]