<%@ page contentType="text/html;charset=GBK" %>
<html>
<head>
<title>验证长度</title>
<script language="JavaScript">
<!--
var limit=16;
function  checklength(){
	var txt = document.forms[0].str.value;
	var len=0;
	for(i=0; i<txt.length; i++) {
		if(txt.charAt(i).search("[\u4E00-\u9FA5]")==0)
			len += 2;
		else
			len += 1;
	}

	if(len==0 || len>limit) {
		alert("字符串为空或太长");
		return false;
	}
	return true;
}
-->
</script>
</head>

<body>

<form method="POST" action="action_checklength.jsp" OnSubmit="return checklength()">
<p>请输入一个字符串（长度介于0~16):
<p><input type="text" name="str" size="34">
<p><input type="submit" value="提交">
</form>

</body>

</html>