[英]Quickest way to check that a value in PHP only contains digits?
I could do this the painful way with a double for loop, but surely there's an inbuilt method? 我可以使用double for循环来完成此痛苦的过程,但是肯定有一个内置方法吗? Will be used to validate phone number entries.
将用于验证电话号码条目。
preg_match('/^\d+$/', $string);
Checks to see if the whole string is just digits. 检查整个字符串是否仅是数字。
If you want to match spaces as well: 如果还要匹配空格:
preg_match('/^[0-9 ]+$/', $string);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.