半角数字に直して数字であるかをチェックする
Function
if, is_numeric
mb_convert_kana
html
<form action="ex.php" method="get"> <dl> <dt>年齢(数字でご記入ください)</dt> <dd><input type="text" name="age" size="5" maxlength="3" />歳</dd> </dl> <input type="submit" value="送信する" /> </form>
PHP
<?php $age = mb_convert_kana($_REQUEST['age'], 'n', 'UTF-8'); if (is_numeric($age)) { print($age . '歳'); } else { print('※年齢は数字でご記入ください'); } ?>