codeigniter regex_match匹配'两个长度值'

时间:2015-06-26 22:46:31

标签: php codeigniter preg-match

我有这个regex_match喜欢 -

    regex_match[/^[0-9]{13}$/ ] 

验证所有13位整数。但我似乎无法找到一种只允许10位和13位整数作为输入传递的方法。我尝试了各种代码,如

    regex_match[/^[0-9]{13|10}$/ ] ,

    regex_match[/^[0-9]{13}{10}$/ ] 

甚至

    regex_match[/^[0-9]{13}$/ ] | regex_match[/^[0-9]{10}$/ ]

但他们都没有工作。 我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:0)

尝试

regex_match[/^([0-9]{13}|[0-9]{10})$/]

您可能需要转义括号。

答案 1 :(得分:0)

检查一下......这是经过测试的..

$number="12541254192";
    if( preg_match('/^([0-9]{13}|[0-9]{10})$/', number)==1){
        echo "Matching";
    }else{
        echo "Not Matching";
    }