开发者

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? Will be used to validate phone number entries.


ctype_digit()


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜