Hi, I am trying to do an input check in PHP to make sure that the entered stock values are at least 1 positive integer and from 0 to 9. Must not contain special characters.
For example, any of the following values must be valid:
7
0
32
47534
The following MUST NOT be valid:
asdf
35/gdf
../34.
etc..
I use the following if statement to check for a positive integer value of $ original_stock.
if (preg_match("/^[0-9]$/", $original_stock))
{
$error .="Original stock must be numerical.";
}
In addition, I have a price field that should be checked as int or double.
If there is a simpler alternative to using regex, that's good too!
Thanks in advance:)
source
share