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.
我需要验证手机号码
它应该只以 9 8 和 7 开头。数据类型应该是整数,长度应该是 10。
满足您标准的简单解决方案。
$isOk = preg_match("/^[789][0-9]{9}$/", $number) ;
此外,您可以稍后将其转换为int:
int
$number = (int) $number ;
此外,此来源包含很多示例:LINK
以下是如何验证符合您标准的数字
$regexp = "/^[987][0-9]{9}$/";