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 来检查字符串是否全是数字和 10 个数字长的快速方法。
例如:
4343434345 - 这将被接受(所有数字 10 个字符)
343434344 - 这不会(9 个字符)
sdfefsefsdf - 这不会。
谢谢
if (preg_match('~^\d{10}$~', $str)) { ... }
或者
if (ctype_digit($str) && strlen($str) == 10) { ... }
前任:-
if(preg_match('/^\d{10}$/', $str)) echo "A match was found."; } else { echo "A match was not found."; }