日期:2014-05-16 浏览次数:20459 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <script type="text/javascript"> function a(obj){ var val=obj.value; var reg=/[\d~!@#$%^&*()_+|:?><\"|{}\[\]\?;\:\'\|\\]/ if(reg.test(val)){ alert("This text is wrong!"); } } </script> <body> <input type="text" onblur="a(this);"/> </body> </html>
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function test(a){
var value=a.value;
var reg=/^[a-zA-Z\u4e00-\u9fa5]+$/;
var regc=/[\u4e00-\u9fa5]/g;
var rege=/[a-zA-Z]/g;
if(reg.test(value)){
var c=value.match(regc);
var e=value.match(rege);
if((c==null||c.length<=8)&&(e==null||e.length<=8)){
alert("true");
}else{
alert("false");
}
}else{
alert("false");
}
}
</script>
</head>
<body>
<input type="text" onblur="test(this)">
</body>
</html>
这样试试
------解决方案--------------------
var pattern = /^([\u4e00-\u9fa5]{0,8}|[a-zA-Z]{0,10})$/gi;
------解决方案--------------------