JavaWeb学习(三)对输入的限制 , 复选框的使用
对输入的限制
<form name = "form1" action = "" method="post" onsubmit="return check()" > </form> <script type = "text/javascript"> function check() { var name = document.form1.name.value; ......... //非空 if(name == ''){ alert('姓名为空') return false; } .......... //判断负数,小数 if( (document.theForm.shu_mu.value.indexOf( "-" ) == 0|| !(document.theForm.shu_mu.value.indexOf(".") ) //身份证 function check_word() { var arr = ["a" ...."Z"]; for(var i = 0 ; i < arr.length ; i++)
{
for(var j = 0 ; j < str.length ; j++)
{
if( arr[i] == str.charAt(j) )
if( arr[i] == "X" && j == 18)
return false;
}
return true;
}
二. 复选框输入
JSP
<input type="checkbox" name="a1" value="" />
<input type="checkbox" name="a2" value="" />
...............
Servlet
String a1 = null; String a2 = null; ... if (request.getParameter("a1") != null) a1 = request.getParameter("a1") + ''; else a1 = "" ; String all = a1 + a2 +......;