Page 1 of 1
Is_Numerical String Function ?
Posted: Sun Aug 18, 2002 5:59 pm
by HUWUWA
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.
Posted: Sun Aug 18, 2002 6:11 pm
by HUWUWA
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 !
Posted: Sun Aug 18, 2002 6:13 pm
by fatalcure
or is_numeric($age);