如何限制用PHP注册的公共电子邮件ID? [英] How to restrict public email id for registration in PHP?

查看:114
本文介绍了如何限制用PHP注册的公共电子邮件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册表,使用任何类型的电子邮件注册。我想把它限制在公司邮件ID的唯一。换句话说,没有免费的电子邮件服务提供商的邮件ID可以用于注册。

解决方案

由于您没有提供任何其他信息使用PHP的 preg_match()函数以及$ code提交以下内容,以及如何定义和/或输入表单? > b 和 i 模式分隔符和数组。



b - 字边界

i - 不区分大小写





以下将与Gmail或Gmail等匹配有人想欺骗系统。



包括Hotmail,Yahoo。您可以添加到数组。

 <?php 
$ _POST ['email'] =email @ Gmail.com;
$ data = $ _POST ['email'];

if(preg_match(/ \b(hotmail | gmail | yahoo)\b / i,$ data)){
echo找到免费电子邮件服务。
退出;
}

else {
echo找不到免费电子邮件服务的匹配项。
退出;
}






其实可以使用如果(preg_match(/(hotmail | gmail | yahoo)/ i,$ data))


 

而不是:

  if(preg_match(/ \b(hotmail | gmail | yahoo)\b / i,$ data))

其结果相同。


I have a registration form that uses any kind of emails for registration. I want to restrict it to company mail id's only. In other words, no free email service provider's mail id would work for registration.

解决方案

Since you have not provided any additional information as to how E-mail addresses are being defined and/or entered into a form or not, am submitting the following using PHP's preg_match() function, along with b and i pattern delimiters and an array.

b - word boundary
i - case insensitive

The following will match against "gmail" or "Gmail" etc. should someone want to trick the system.

Including Hotmail, Yahoo. You can add to the array.

<?php 
$_POST['email'] = "email@Gmail.com";
$data = $_POST['email'];

 if(preg_match("/\b(hotmail|gmail|yahoo)\b/i", $data)){
    echo " Found free Email service.";
    exit;
}

else{
    echo "No match found for free Email service.";
    exit;
}


Actually, you can use:

if(preg_match("/(hotmail|gmail|yahoo)/i", $data))

instead of:

if(preg_match("/\b(hotmail|gmail|yahoo)\b/i", $data))

which gave the same results.

这篇关于如何限制用PHP注册的公共电子邮件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆