Reputation: 318
This is a two-part question. Help on either (or both) is appreciated!
1) What is the best php method for checking if an email string is a Gmail address
2) How to strip out everything but the username?
Thanks!
Upvotes: 3
Views: 12622
Reputation: 21
For Multiple Emails
$expressions =
"/(gmail|googlmail|yahoo|hotmail|aol|msn|live|rediff|outlook|facebook)/";
if (preg_match($expressions, $input_email)) {
throw error
}
Upvotes: 2
Reputation: 4134
if (preg_match("/gmail.com/",$email_address)) {
$email_address = str_replace("@gmail.com","",$email_address);
}
Upvotes: 1
Reputation: 18853
Dunno about best method, but here is one method for checking a gmail address using stristr
.
if (stristr($email, '@gmail.com') !== false) {
echo 'Gmail Address!';
}
As for pulling out the username there are a ton of functions as well, one could be explode
:
$username = array_shift(explode('@', $email));
There are many ways to do it, the best depends on your needs.
Upvotes: 2
Reputation: 7656
list($user, $domain) = explode('@', $email);
if ($domain == 'gmail.com') {
// use gmail
}
echo $user;
// if $email is [email protected] then $user is toto
Upvotes: 18