我有这个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}$/ ]
但他们都没有工作。 我怎样才能做到这一点?
答案 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";
}