用于保存电话号码的字符串的Regex


Regex for a string used for save a telephone number

我有个问题。以下单词的正则表达式应如何查找:+23456745678或+29845281058,(带逗号)我试过了,但没有结果:

if (!preg_match('#^'+[0-9]{11}$#',$string)) {
                    return ("Msisdn $string is incorrect!");
                    break;
                }

我总是犯这个错误。请帮我。提前Thx

模式应该是:

'/'+[0-9]{11},?/'

开头的^和结尾的$代表行首和行尾,我不确定你是否真的想在那里(我猜不是)。

在此处进行测试:http://www.phpliveregex.com/p/78v

另一种选择是将''d用于数字

'/'+'d{11},?/'