【问题标题】:Compilation failed: range out of order in character class at offset 12编译失败:偏移 12 处的字符类范围乱序
【发布时间】:2013-11-09 16:10:51
【问题描述】:

我有一个非常基本的 HTML 表单,其文本框定义为

<li id="li_1" >
<label class="description" for="element_1">O teu nome </label>
<span>
<input id="element_1_1" name= "element_1_1" class="element text" pattern="[a-z0-9. -]+" maxlength="255" size="8" value=""/>
<label>Primeiro</label>
</span>
<span>
<input id="element_1_2" name= "element_1_2" class="element text" pattern="[a-z0-9. -]+" maxlength="255" size="14" value=""/>
<label>Apelido</label>
</span> 

此输入在名为 email_send_pt.php 的 php 文件中使用

进行验证
// validation expected data exists
if(!isset($_POST['element_1_1']) ||
!isset($_POST['element_1_2']) ||
!isset($_POST['element_2']) ||{
died('Lamentamos, mas constam erros no seu registo.'); 
}

$first_name = $_POST['element_1_1']; // required
$second_name = $_POST['element_1_2']; // required
$email = $_POST['element_2']; // required

$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name) ||
!preg_match($string_exp,$second_name)) {
$error_message .= 'O nome que preencheu não parece ser válido.<br />';
}

我收到一个常量“编译失败:第 45 行 email_send_pt.php 中偏移量 12 处的字符类范围乱序”

第 45 行是 "if(!preg_match($string_exp,$first_name) ||" 作为输入,我使用了应该被接受的 "teu"(没有 "")...

知道为什么会出现此错误消息吗? 感谢您的帮助。

【问题讨论】:

    标签: php html


    【解决方案1】:

    您必须在此处关闭大括号并删除 || 运算符。

    也是die() 而不是died()

    died('Lamentamos, mas constam erros no seu registo.'); 
    

    把它们放在一起

    if(!isset($_POST['element_1_1']) ||
        !isset($_POST['element_1_2']) ||
        !isset($_POST['element_2'])){
        die('Lamentamos, mas constam erros no seu registo.');
    }
    

    【讨论】:

      【解决方案2】:

      该消息意味着您的正则表达式中的字符 12 处存在错误。由于那是撇号(单引号),我猜你需要转义它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-20
        • 2019-09-19
        • 2020-02-18
        • 1970-01-01
        • 2014-11-30
        • 1970-01-01
        • 2022-11-22
        • 2020-01-28
        相关资源
        最近更新 更多