我只是想问一下如何才能允许 @ abc.co.uk 或 @ def.com.tr 或其他电子邮件扩展内容。当用户注册我的网站时?
如果用户尝试使用(name@hotmail.com)注册,则此电子邮件不允许。但如果用户尝试注册( name@abc.co.uk或@ def.com.tr),则用户可以注册该网站。
$("#email").change(function()
{
var email = $("#email").val();
var msgbox = $("#estatus");
if(email.length >= 3)
{
$("#estatus").html('<div class="checking">Checking availability...</div>');
$.ajax({
type: "POST",
url: "check_mail.php",
data: "email="+ email,
success: function(msg){
$("#estatus").ajaxComplete(function(event, request, settings){
var d = msg;
var str=msg.substr(0, 2);
$("#estatus").html('');
if(str == 'OK')
{
$("#email").removeClass("no");
$("#email").addClass("yes");
//msgbox.html('<font color="Green"> Ok </font> ');
}
else
{
$("#email").removeClass("yes");
$("#email").addClass("no");
msgbox.html(msg);
}
});
}
});
}
else
{
$("#email").addClass("no");
$("#estatus").html('<div class="error">Enter a valid e-mail</div>');
}
return false;
});
PHP check_mail.php
<?php
error_reporting(0);
include_once 'includes/db.php';
include_once 'includes/Sc_Script.php';
$Sc = new Check_Email();
if(isSet($_POST['email'])){
$value=$_POST['email'];
// Check the mail is already in using or not
$check=$Sc->Login_Check($value,0);
if($check) {
echo '<div class="error">'.$value.' = This email address is already in use.</div>';
} else {
// Else continue
echo 'OK';
}
}
?>
答案 0 :(得分:2)
首先,您需要提取域名,然后您需要检查它是否包含在某些白名单数组中:
function isDomainAllowed($email_address)
{
$domain = substr($email_address, strrpos($email_address, '@') + 1);
if (in_array(strtolower($domain), array(
'abc.co.uk',
'def.com.tr',
)))
{
return TRUE;
}
return FALSE;
}
if (isDomainAllowed($email_address))
{
// Allowed
}
else
{
// Not allowed
}
答案 1 :(得分:1)
你已经检查过每一个&amp;每个白名单域都附带提供的电子邮件。
$emailList = array();
$emailList = ["abc.in","def.uk"];
$flag = false;
foreach($emailList as $email)
{
if(stripos($_POST['email'],$email) != false)
$flag = true;
}
if($flag == false)
echo "Invalid email domain";