标签: php regex preg-match
我想对电话号码进行简单验证。电话号码的长度应为13,并且开头应包含+符号。因此,+123456789001是有效数字1234566780111无效。
+
+123456789001
1234566780111
我当前正在使用此字符,但是我不确定如何在开始时将+设置为必需字符。
/^[0-9]{13}+$/
在功能上:
function validate_mobile($mobile) { return preg_match('/^[0-9]{13}+$/', $mobile); }
答案 0 :(得分:1)
您的原始表达式很好,我们只需在其中添加HTML("<p>The source of the data is <a href = 'http://source.org'>source.org.</a></p>") :
HTML("<p>The source of the data is <a href = 'http://source.org'>source.org.</a></p>")
然后我们的函数可能类似于:
$re = '/^\+[0-9]{12}$/m'; $str = '+123456789001'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); var_dump($matches);
jex.im可视化正则表达式: