<html>
<head>
<title>php正则表达式实例</title>
<script language="javascript" type="text/javascript">
function Button1_onclick(){
if(!test_hanzi(document.form1.Text1.value)){
alert("姓名只能是汉字");
return false;
}else{
alert("验证通过");
}
}
//验证电子邮件
function test_email(strEmail){
var myReg = /^[_a-z0-9]+@([_a-z0-9]+.)+[a-z0-9]{2,3}$/;
if(myReg.test(strEmail)) return true;
return false;
}
//只能输入数字
function test_shuzi(strshuzi){
var myReg =/^[0-9]*$/;
if(myReg.test(strshuzi)) return true;
return false;
}
//只能输入汉字
function test_hanzi(strhanzi){
var myReg =/^[u4e00-u9fa5]{0,}$/;
if(myReg.test(strhanzi)) return true;
return false;
}
</script>
</head>
<body>
<form name="form1">姓名:
<input id="Text1" name="Text1" type="text" />
<input name="按钮" type="button" id="Button1" onclick="return Button1_onclick()" value="button" language="javascript" />
</form>
</body>
</html>