Checks if text length is between given bounds
/** * Uses regular expression matching to return an array of valid e-mail addresses * * @param string $strAddresses Single string containing e-mail addresses and anything else * @return string[] An array of e-mail addresses only, or NULL if none */ public static function GetEmailAddresses($strAddresses) { $strAddressArray = null; // Define the ATEXT-based DOT-ATOM pattern which defines the LOCAL-PART of // an ADDRESS-SPEC in RFC 2822 $strDotAtomPattern = "[a-zA-Z0-9\\!\\#\\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~\\.]+"; // Define the Domain pattern, defined by the allowable domain names in the DNS Root Zone of the internet // Note that this is stricter than what RFC 2822 allows in DCONTENT, because we assume developers are // wanting to send email over the internet, and not using it for a completely closed intranet with a // non-DNS Root Zone compliant domain name infrastructure. $strDomainPattern = '(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]*[a-zA-Z0-9])?\\.)*[a-zA-Z0-9](?:[a-zA-Z0-9\\-]*[a-zA-Z0-9])?'; // The RegExp Pattern to Use $strPattern = sprintf('/%s@%s/', $strDotAtomPattern, $strDomainPattern); // See how many address candidates we have $strCandidates = explode(',', $strAddresses); foreach ($strCandidates as $strCandidate) { if (preg_match($strPattern, $strCandidate, $strCandidateArray) && count($strCandidateArray) == 1) { $strCandidate = $strCandidateArray[0]; $strParts = explode('@', $strCandidate); // Validate String Lengths, and add to AddressArray if Valid if (QString::IsLengthBeetween($strCandidate, 3, 256) && QString::IsLengthBeetween($strParts[0], 1, 64) && QString::IsLengthBeetween($strParts[1], 1, 255)) { $strAddressArray[] = $strCandidate; } } } if (count($strAddressArray)) { return $strAddressArray; } else { return null; } }