Is_Numerical String Function ?
Moderator: General Moderators
Is_Numerical String Function ?
Hi guys, what's the best way to test if a string contains only numbers (0...9) ? Should I use the string comparison functions or the preg_match ones ? I learn best from example and could really use one. Thanks.
I figured it out. Here is a cool way to check someone's age if they decide to enter it:
$strAge="None Specified";
// frmAge is the name I used for the age in the <FORM>
if($_POST['frmAge'] != ""){
if(preg_match("([0-9])",$_POST['frmAge']) == 0)
{
$strAge="Invalid Entry";
}
else{
$strAge=$_POST['frmAge'];
}
}
// you can also do a strlen() test to see if it's more than 2 or 3 characters
I just thought I'd chip in after all the help you guys have given me.
I Love PHP !
$strAge="None Specified";
// frmAge is the name I used for the age in the <FORM>
if($_POST['frmAge'] != ""){
if(preg_match("([0-9])",$_POST['frmAge']) == 0)
{
$strAge="Invalid Entry";
}
else{
$strAge=$_POST['frmAge'];
}
}
// you can also do a strlen() test to see if it's more than 2 or 3 characters
I just thought I'd chip in after all the help you guys have given me.
I Love PHP !