Skip to content

Instantly share code, notes, and snippets.

@kevinquillen
Created July 28, 2017 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinquillen/d7efe7e2bce417289f8fabc2e2f1fe62 to your computer and use it in GitHub Desktop.
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
<?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