Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在用 php 编码,如果有人可以帮助我使用正则表达式来验证 +233 245 245 245 或 0245 245 245 格式的电话号码,我会很高兴。
我还希望验证电话号码是否包含空格。提前非常感谢。
像这样简单的东西会起作用:
$string = "(232) 555-5555"; $expr = '/^\+?(\(?[0-9]{3}\)?|[0-9]{3})[-\.\s]?[0-9]{3}[-\.\s]?[0-9]{4}$/'; if (preg_match($expr, $string) == 1) { echo "number validated successfully."; }