客户端验证:
<html>
<body>
<form action="test.asp" name="form1" onSubmit="return checkForm()">
<input name="test" type="text">
<input type="submit">
</form>
<script>
function checkForm(){
var checkStr=form1.test.value
if (!checkStr) return false
for (var i=0;i<checkStr.length;i++)
if (checkStr.charCodeAt(i)<256) {
alert('对不起,只能输入中文')
return false
}
}
</script>
</body>
</html>
服务器端验证:
<%
dim testStr,i
testStr=request("test")
if testStr="" then
response.write "<script>history.back();</script>"
response.end
end if
for i=1 to len(testStr)
if asc(mid(testStr,i,1))>0 then
response.write "<script>"&vbcrlf&"alert('对不起,只能输入中文');"&vbcrlf&"history.back();"&vbcrlf&"</script>"
response.end
end if
next
response.Write testStr
%>