I recently found out that the method I used to validate data entry takes on some values that I don't particularly like. I only need to take the natural numbers ( 1, 2, 3etc.) without character, without numbers.
My method is as follows:
function is_natural($str)
{
return preg_match('/[^0-9]+$/', $str) ? false : $str;
}
Therefore, it should return false if it finds anything else but an integer natural number. The problem is that it accepts strings of type "2.3"and even"2.3,2.2"
source
share