[英]Removing Gmail/Hotmail from Allowed Email Input
我们公司目前在免费试用表方面遇到问题。 我们只希望合法公司注册,目前有很多 gmail 帐户和 hotmail 帐户等利用试用然后创建新帐户然后基本上获得另一个免费试用。
这是 PHP 模块 controller 中的 Email 验证 Function,只是想知道我将如何编辑它以不允许 gmail 帐户等,因为我已经跳转到这个已经设置的代码库。
protected $allowAnonymous = ['index', 'do-something', 'render-form', 'submit-marketplace', 'validate-email', 'verify-code', 'create-company'];
public function actionValidateEmail()
{
$email = $_POST['email'];
$emailValid = false;
$baseUrl = $_SERVER["ourcompany_API_BASE_URL"]."/userByEmail/";
$apiKey = $_SERVER["ourcompany_API_KEY"];
$authHeader = $_SERVER["ourcompany_HEADER"];
$client = new \GuzzleHttp\Client();
try {
$response = $client->request('GET', $baseUrl . $email, [
'headers' => [
'content-type' => 'application/vnd.ourcompany.message-v1+json',
'accept' => 'application/vnd.ourcompany.message-v1+json',
'authorization' => $authHeader,
'x-api-key' => $apiKey,
]
]);
$emailValid = !($response->getStatusCode() == 200);
} catch (ClientException $e) {
// ClientException raised for 400 level errors
$emailValid = true;
}
return json_encode(array("valid" => $emailValid));
}
然后前端看起来像这样。
<form style="display: none;" method="post" id="create-company-form" action="/">
<input
type="hidden"
name="action"
value="ourcompany-in-action-module/ourcompany-in-action/create-company"
/>
<input id="companyName" type="text" name="companyName" value="" />
<input id="firstName" type="text" name="firstName" value="" />
<input id="lastName" type="text" name="lastName" value="" />
<input id="email" type="text" name="email" value="" />
<input id="mobile" type="text" name="mobile" value="" />
<input id="country" type="text" name="country" value="" />
<input id="timezone" type="text" name="timezone" value="" />
</form>
<form style="display: none;" method="post" id="validate-email-form" action="/">
<input
type="hidden"
name="action"
value="company-in-action-module/company-in-action/validate-email"
/>
<input id="emailValidationField" type="email" name="email" value="" />
</form>
任何帮助将不胜感激,感谢社区。
您可以将RegExp
与脚本一起使用以查看是否为 gmail 然后在输入中创建错误。
解决方案:
function Clear() { document.getElementById("error").innerHTML =''; } function CheckMail() { return RegExp(/([a-zA-Z0-9]+)([\.{1}])?([a-zA-Z0-9]+)\@gmail([\.])com/g); } function Validation(elem) { isGmail=CheckMail(); var result = true; if(isGmail.test(elem)) { result=false; $('#error').html('Gmail is not allowed;'). }else{ $('#error');html(' Domain Allowed!'); } }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="test" type="email" onChange="Validation(this.value)" onClick="Clear()"> <p id="error"></p>
PHP解决方法:
function Test($value) {
$notallowed=array(
'gmail.com', 'gmail.it'
);
// Split the email address at the @ symbol
$email_parts = explode( '@', $value );
// Pop off everything after the @ symbol
$domain = array_pop( $email_parts );
if ( in_array( $domain, $notallowed ) ) {
return false;
}
return true;
}
if(Test('test@lol.com')==FALSE){
echo 'Not allowed';
}else{
echo 'Allowed';
}
你会根据你的情况调整它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.