简体   繁体   English

编译失败:字符类在偏移量12处范围混乱

[英]Compilation failed: range out of order in character class at offset 12

I have a very basic HTML form with text boxes defined as 我有一个非常基本的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> 

This input is validated in a php file called email_send_pt.php using 此输入使用以下文件在名为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 />';
}

I am getting a constant "Compilation failed: range out of order in character class at offset 12 in email_send_pt.php on line 45" 我得到一个常量“编译失败:字符类的范围乱序,第45行的email_send_pt.php中偏移量12”

Line 45 is "if(!preg_match($string_exp,$first_name) ||" As input I used "teu" (without "") which should be accepted… 第45行是“ if(!preg_match($ string_exp,$ first_name)||”作为输入,我使用了“ teu”(不带“”),应该接受…

Any idea why this error message is appearing ? 知道为什么会出现此错误消息吗? Thank you for your help. 谢谢您的帮助。

You have to close brace here and remove the || 您必须在此处关闭大括号并删除|| operator. 运营商。

Also it is die() and not died() 也是die()而不是die() died()

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

Putting it all together 放在一起

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

The message means that there is an error at character 12 in your regex. 该消息表示您的正则表达式中的字符12处有错误。 Since that is the apostrophe (single quote), my guess is that you need to escape it. 由于这是撇号(单引号),所以我想您需要将其转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编译失败:字符类中偏移量 12 处的范围无效 - Compilation failed: invalid range in character class at offset 12 preg_match_all 编译失败:字符类在偏移量处的范围乱序 - preg_match_all Compilation failed: range out of order in character class at offset Symfony 验证错误:preg_match():编译失败:字符 class 在偏移处的范围乱序 - Symfony Validation error: preg_match(): Compilation failed: range out of order in character class at offset 编译失败:字符类在偏移量4处的范围无效 - Compilation failed: invalid range in character class at offset 4 Unicode 正则表达式:编译失败:字符类中的范围乱序 - Unicode Regular Expression: Compilation failed: range out of order in character class preg_match():编译失败:偏移处的字符类范围无效 - preg_match(): Compilation failed: invalid range in character class at offset 警告:preg_split()[function.preg-split]:编译失败:字符类中的范围乱序 - Warning: preg_split() [function.preg-split]: Compilation failed: range out of order in character class 字符类中的范围乱序 - Range out of order in character class PHP正则表达式中的“字符类中的范围乱序”? - “range out of order in character class” in PHP regex? JavaScript Unicode Regex - 字符类中的顺序乱序 - JavaScript Unicode Regex - Range out of order in character class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM