我在这里有表格,我只想接受GMail电子邮件地址。
这是表格的一部分。
function is_email($email){
$x = '\d\w!\#\$%&\'*+\-/=?\^_`{|}~'; //just for clarity
return count($email = explode('@', $email, 3)) == 2
&& strlen($email[0]) < 65
&& strlen($email[1]) < 256
&& preg_match("#^[$x]+(\.?([$x]+\.)*[$x]+)?$#", $email[0])
&& preg_match('#^(([a-z0-9]+-*)?[a-z0-9]+\.)+[a-z]{2,6}.?$#', $email[1]);
}
elseif (!is_email($Email)) {
$resultado = "Please, use a valid email address. (Required for account activation)<br><br> <a href=javascript:history.go(-1)>Go back!</a>";
}
我已经尝试过“爆炸('@ gmail.com',$ email,3))== 2”,但反而给我一些错误。
答案 0 :(得分:1)
您只需要检查字符串是否以&#34; @ gmail.com&#34;:
结尾/**
* Check if an email is a Gmail address
* @param string $email The email address to check
* @return boolean
*/
function isGmail($email) {
$email = trim($email); // in case there's any whitespace
return mb_substr($email, -10) === '@gmail.com';
}
答案 1 :(得分:0)
检查条件:
preg_match("~@gmail\.com$~",$email)
答案 2 :(得分:0)
function validgmail($email) {
// do other checkings
if (substr($email, 0, -10) == "@gmail.com")
{
// it's valid email
} else {
//invalid
}
}
答案 3 :(得分:0)
尝试此方法有效
$email = 'mrshahbaznns@gmail.com';
if(preg_match("~@gmail\.com$~",$email)){
echo 'good';
}
else{
echo 'bad';
}