zend框架正则表达式问题:“使用模式时出现内部错误”

时间:2022-10-10 12:29:49

I've tested my regular expression on multiple testers and I've tried multiple regular expressions too but I keep getting the error: "Internal error while using the pattern '/^(04\d{2}/(\d{2} )\d{2} \d{2})$/'". I know it's probably not the best regex but I couldn't find a good one and I'm not really a pro at this and I have to move on. The phone numbers it should be matching are 04dd/dd dd dd with d being a number between 0 and 9. This is the code I'm using when creating the form.

我已经在多个测试人员上测试了我的正则表达式,我也尝试了多个正则表达式,但我不断收到错误:“使用模式时出现内部错误”/ ^(04 \ d {2} /(\ d {2} )\ d {2} \ d {2})$ /'“。我知道它可能不是最好的正则表达式,但我找不到一个好的,我不是真正的专业人士,我必须继续前进。它应该匹配的电话号码是04dd / dd dd dd,d是0到9之间的数字。这是我在创建表单时使用的代码。

$phone = $this->addElement('text', 'phone', array(
        'filters'    => array('StringTrim'),
        'validators' => array(
            array('regex', false, array('/^(04\d{2}/(\d{2} )\d{2} \d{2})$/'))
        ),
        'required'   => true,
        'label'      => 'Phone:',
    ));

How can I solve this problem? Thanks already.

我怎么解决这个问题?谢谢。

1 个解决方案

#1


3  

You have to escape the slash:

你必须逃避斜线:

array('regex', false, array('/^(04\d{2}\/(\d{2} )\d{2} \d{2})$/'))

#1


3  

You have to escape the slash:

你必须逃避斜线:

array('regex', false, array('/^(04\d{2}\/(\d{2} )\d{2} \d{2})$/'))