表单中不接受域.company

时间:2015-11-06 11:00:11

标签: php mysql email plugins joomla

我使用Joomla的JSN Uniform插件接收电子邮件,但它不接受.company域作为有效域。它接受通常的域名(com,net,org,info,biz,...),但是.company之类的域名不被接受。

现在,我真的没有PHP经验,因为我更喜欢JavaScript,但根据我的不足知识,我的问题的解决方案可能在form.php文件中,所以这里是部分代码。

PHP:

private function _fieldEmail($post, $fieldIdentifier, $fieldTitle, &$validationForm)
    {
        $postFieldIdentifier = isset($post[$fieldIdentifier]) ? $post[$fieldIdentifier] : '';
        $postFieldIdentifier = (get_magic_quotes_gpc() == true || get_magic_quotes_runtime() == true) ? stripslashes($postFieldIdentifier) : $postFieldIdentifier;
        $postEmail = $postFieldIdentifier;
        if ($postEmail)
        {
            $regex = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,6})$/';
            if (!preg_match($regex, $postEmail))
            {
                $validationForm[$fieldIdentifier] = JText::sprintf('JSN_UNIFORM_FIELD_EMAIL', $fieldTitle);
            }
            else
            {
                return $postFieldIdentifier ? $postFieldIdentifier : "";
            }
        }
        else
        {
            return $postFieldIdentifier ? $postFieldIdentifier : "";
        }

    }

有人可以帮帮我吗?

感谢。

编辑:我试图将正则表达式值从2,6更改为2,但仍然没有变化。

请在此处查看php fiddler:http://viper-7.com/CqxAMZ

3 个答案:

答案 0 :(得分:3)

你应该像这样替换正则表达式:

$regex = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,})$/';

接受任何大于1的域名。现在它被限制在2到6之间的大小。更多关于http://www.regular-expressions.info/repeat.html

中的主题

答案 1 :(得分:1)

最后将{2,6}更改为{2,7}

这表明正则表达式的最后一部分应包含2到7个字符("公司"超过6的限制)。

答案 2 :(得分:1)

替换:

$regex = '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,6})$/';
if (!preg_match($regex, $postEmail))
{
    $validationForm[$fieldIdentifier] = JText::sprintf('JSN_UNIFORM_FIELD_EMAIL', $fieldTitle);
}

使用:

if (!filter_var($postEmail, FILTER_VALIDATE_EMAIL)) {
    $validationForm[$fieldIdentifier] = JText::sprintf('JSN_UNIFORM_FIELD_EMAIL', $fieldTitle);
}

电子邮件验证比单行正则表达式更复杂。