Created
July 28, 2017 20:12
-
-
Save kevinquillen/d7efe7e2bce417289f8fabc2e2f1fe62 to your computer and use it in GitHub Desktop.
Utility class with a helper method that lets me check if the incoming email address input by the user matches a given domain I am verifying against. See the corresponding test: https://gist.github.com/kevinquillen/85baa1fa69f49d1c34aa81369405d47e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\iana_netforum_auth\Utility; | |
/** | |
* Class EmailMatcher. | |
* | |
* @package Drupal\iana_netforum_auth\Utility | |
*/ | |
class EmailMatcher { | |
/** | |
* Check if the email address entered matches the domain. | |
* | |
* @param string $email_address | |
* The provided email address. | |
* @param string $domain | |
* The domain to match it against. | |
* @return bool | |
* TRUE if the email domain and provided domain match. | |
*/ | |
public static function emailDomainMatch(string $email_address, string $domain) : bool { | |
$check_for = explode('@', $email_address); | |
// Invalid email address. | |
if (count($check_for) != 2) { | |
return FALSE; | |
} | |
return (end($check_for) === $domain); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment