Hi, I want to validate that a variable only contains numbers. I came up with
this code
$variable = "154545"; -> must give me true.
$variable = "$%54545"; -> must give me false
$variable = "$% 54545"; -> must give me false
$variable = "4545;#"; -> must give me false
$variable = "004545"; -> must give me false
CODE STARTS HERE
$variable = "55555";
$variable = trim($variable);
if (ereg ("[a-zA-Z]", $variable)) {
echo "NOT ONLY NUMBERS: $variable";
$variable = "";
}
if (ereg ("[0-9]", $variable)) {
$variable = $variable * 1;
if ($variable == 0) {
echo "IS NOT A NUMBER";
} else {
echo "JUST NUMBERS: $variable";
}
}
Another thing that I thought about was this :
$variable= ereg_replace( "[^0-9]", "", $variable );
But is not what i am looking for...
I know there is a simpler way to do it. I just couldn't figure it out.
Thanks in advance....
Ricardo
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]