Welcome Guest, Not a member yet? Register   Sign In
Problem with POST data types
#7

(04-08-2024, 01:55 PM)kenjis Wrote: First of all, you need to define what values are really valid in this case.
Then validate user input (string value if it is POSTed).
If it is valid, then convert to int.

PHP Code:
function validateRange(int $number): bool {
  return $number 0;
}

// All outputs are `true`.
var_dump(validateRange(' 6 '));
var_dump(validateRange('6.'));
var_dump(validateRange('06'));
var_dump(validateRange('1e2')); 

https://3v4l.org/1EnTK

Try load this function like this

'number' => [
'label' => ' ',
'rules' => 'required|validateRange'
]
Reply


Messages In This Thread
Problem with POST data types - by motoroller - 04-07-2024, 05:39 PM
RE: Problem with POST data types - by kenjis - 04-07-2024, 07:23 PM
RE: Problem with POST data types - by motoroller - 04-08-2024, 12:20 AM
RE: Problem with POST data types - by kenjis - 04-08-2024, 01:47 AM
RE: Problem with POST data types - by motoroller - 04-08-2024, 08:55 AM
RE: Problem with POST data types - by kenjis - 04-08-2024, 01:55 PM
RE: Problem with POST data types - by motoroller - 04-10-2024, 01:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB