0

is there a php function that I can verify if the string contains all digital number, not alphabetic charactor? thanks.

5
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by smac
0

While I would agree with the regular expressions. It is the best and proper way. Regular expressions can be hard to make.

An alternative would be to have an array like this
$my_nums = array("0","1","2")

and then loop through the length of the string and do a check like this

if (in_array($your_string, $my_nums))

-Brad

www.azpixels.com

0

If you're willing to allow scientific notation etc.., how about using is_numeric():

From the manual: http://us3.php.net/is_numeric

bool is_numeric ( mixed var )

Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.