I need a code in PHP for check if a string is number using regular expression not using function is_number().
What's wrong with is_number()? :-)
and to do it with regexps you first need to define what you consider to be 'a number'.
I have a form where users fill the field named age (age pers.). I want to check if this string is number by 3 char.
if (preg_match('/[0-9]{3}/',$variable)) { echo 'yes'; } else { echo 'no'; };
or
if (is_numeric($variable) && ($variable>0) && (variable<150)) { echo 'yes'; };
That should be preg_match('/[0-9]{3}$/',$variable)
Indeed it should, thanks programmerman.