function checkName(){
if(inputname.value.length!=0){if(value.match(/^[\u4e00-\u9fa5]+$/))alert('ok')else alert('enter chinese')}else{alert('not empty')}}
<%@ page language="java" contentType="text/htmlcharset=utf-8"pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8">
<title>Insert title here</title>
<script type="text/javascript">
function submit(){
var b1 = valiDateAge()
var b2 = valiDateName()
var b3 = valiDatePhone()
if(!(b1 &&b2 &&b3)){}
alert("输入有误!")
return false
}else{
return true
}
function valiDateAge(){
var age = document.getElementById('age').value
var ageReg = "/^[0-9]$/g"
var flag = false
if(ageReg.test(age)&&age<=200){
flag = true
}
return flag
}
function valiDateName(){
var name = document.getElementById('name').value
var nameReg= "/^[\u4e00-\u9fa5]{1,3}$/g"
var flag= false
if(nameReg.test(name)){
nameage = true
}
return flag
}
function valiDatePhone(){
var phone= document.getElementById('phone').value
var phoneReg = "^[/d]{11}$"
var flag = false
if(phoneReg.test(phone)){
flag = true
}
return flag
}
</script>
</head>
<body>
<form action="" onsubmit="return submit()">
<table>
<tr>
<td>名字:</td>
<td><input type="text" id="name"/></td>
</tr>
<tr>
<td>年龄: </td>
<td><input type="text" id="age"/></td>
</tr>
<tr>
<td>
电话:
</td>
<td><input type="text" id="phone"/></td>
</tr>
<tr>
<td><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
</html>
没测试 环境原因 不知道正确不正确
英文名正则吗?百度啊!算了我不能这么不负责任
正则式如下:
var reg=/[a-zA-Z0-9]{0,10}//*支持英文和数字,且字符最多为10*/var reg=/[\x00-\xff]//*据说可以屏蔽所有中文代码(包括字符),这个ok吗*/