Afternoon Everyone
I am having trouble validating the length of a variable returned from a form. The value received from the form appears to be correct, the results from strlen is within the required range but this check fails if the received input is numbers. If the input received from the form is alphanumeric, the function works correctly.
What am I missing?
Code:
PHP Code:
if (isset($_POST['devid'])) {
$Device->device_id = stripString($_POST['devid'], 'device_id');
if (strlen($Device->device_id) < 4 || strlen($Device->device_id > 20)) {
$user_msg = "<li>Device ID is not valid ($Device->device_id). len=".strlen($Device->device_id)."</li>";
}
} else {
Output echoed to screen when it failed:
Device ID is not valid (0002310). len=7
The value of "0002310" is 100% correct. As you can see from the output line, post stripping it has maintained the leading zeroes and is 7 characters long - which should not fail the length check.
I have tried within the $Device object, to define the variable as string using:
PHP Code:
$this->device_id = (string) $row->device_id;
to try to force it to work as a string.
Thanks.
Alan