http://www.iteye.com/topic/30728
1.只能是数字加字母
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<input type="text" name="test1" id="test1"/>
<input type="button" name="测试" value="测试" οnclick="test1()"/>
<script language="javascript">
function test1(){
var s = document.getElementById("test1");
//只能是数字加字母
var patrn=/^[A-Za-z0-9]+$/;
if (!patrn.test(s.value)){
return false ;
}
}
</script>
</BODY>
</HTML>
2.判断js字符长长度,含中文
var tmp = "223sdf测试";
tmp.replace(/[^\x00-\xff]/g,"**").length;