开发者

Quickest way to check that a value in PHP only contains digits?

开发者 https://www.devze.com 2023-02-27 06:37 出处:网络
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+$/\', $strin

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

精彩评论

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

关注公众号