For chestnut:
In order to verify the information submitted is pure digital input, I define a click event check information submitted (), as follows:
<form action="InsertServlet?opr=insert" name="form" method="post">
<p>只能输入数字:<input type="text" name="b" ></p>
<p><input type="button" value="保存" οnclick="check()">
</p>
</form>
check () method is as follows, where / ^ \ d $ / 0-9 represents any one of a regular expression authentication information input in this way to meet the requirements:
function check(){
var reg = /^\d$/;
//获取到输入的值
var b = document.getElementsByName('b')[0].value;
//判断是否是正则表达式的格式
var flag = reg.test(b);
if(!flag){
alert("必须是数字");
}else {
window.location.href="javascript:document.form.submit()";
}