Possible Duplicate:
Alphabetic equivalent of PHP is_numeric
If you check开发者_开发百科 if the data is a number, we use is_numeric:
if(!isset($_POST['rnum'])||trim($_POST['rnum'])==""){echo "Error:Enter Room Number!";
echo '<input type="button" value="Back" onClick="history.go(-1);return true;">';
}else if(!is_numeric(trim($_POST['rnum']))){echo "Error: Enter A Numeric Value!";
echo '<input type="button" value="Back" onClick="history.go(-1);return true;">';
die();
}
How about checking if it is string?or expecting that the inputted data are just letters
You can try using regex like:
if(preg_match('/^[a-z]+$/i',$input_to_be_tested))
echo 'Has only letters';
else
echo 'Has non-letters';
If you wan to allow spaces in the input you can try:
/[\sa-z]+/i
DO you only want alphabetic characters? You could use a regular expression to match against [a-zA-Z]+
, but that would only get letters of the alphabet. Are other characters allowed or not?
精彩评论