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);
精彩评论