Hi,
I'm using PHP and MySQL. I have an HTML-page where there are several input fields. There is one field that is supposed to contain a SERIAL NUMBER (numeric data). I want to check if the user has entered alphanumeric data, because the insertion is succesful, however the value is changed to 0 by MySQL. Can you give me which function to use or what is the general idea? An example would be greatly appreciated.
Thanks, Akos
if it is truely numeric (only numbers 0 through9, NOTHIN else) you can check it with is_numeric($string)
Ok, ereg is your friend in this case 🙂
Try the following (with $value containing the value you want checked)
if (ereg("([A-Za-z0-9]*)$", $value) // This is alphanumeric else // sorry, its not
Hope that helps!
Chris King
Not really: the data you get from the POST or GET is in string form.
Check this out:
<?php $data_from_POST = "1234"; echo gettype( $data_from_POST ); ?>
and see what it tells you. Chris's suggestion is the way to go!
Sure, but now try this:
$data_from_POST = "1234"; echo gettype( $data_from_POST ); echo "\n"; if (is_numeric($data_from_POST)) { echo "is numeric\n"; } else { echo "is not numeric\n"; };
then try changing the "1234" to "a1234"