当前位置: 代码迷 >> JavaScript >> 弱弱问一个有关问题,请支援
  详细解决方案

弱弱问一个有关问题,请支援

热度:155   发布时间:2012-03-14 12:01:12.0
弱弱问一个问题,请支援
这是什么字符啊???
var   m=/^[\u4e00-\u9fa5a-z0-9][\u4e00-\u9fa5a-z0-9\-]{6,20}$/i


------解决方案--------------------
unicode编码

可以这样子


<!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= " ">
<script language= "javascript " src= "prototype.js "> </script>
</HEAD>
<BODY>
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function trim(s){
return rtrim(ltrim(s));
}
//去左空格;
function ltrim(s){
return s.replace( /^\s*/, " ");
}
//去右空格;
function rtrim(s){
return s.replace( /\s*$/, " ");
}
//验证信息;
//空字符值;
function isEmpty(s){
s = trim(s);
return s.length == 0;
}
function Escape()
{
//code = " "+trim($F( "Mycode "));
//alert(code.length);
//code= "\u4e0a\u4f20\u6587\u4ef6\uff0c\u8bf7\u4e0b\u8f7d\u5230\u672c\u5730\u6253\u5f00 "
var code= "\u4e00 ";
//str = code;
//alert(code)
str = code.unescapeHTML();
//alert(str);
$( "div1 ").innerHTML = trim(str);

}

//-->
</SCRIPT>
<FORM METHOD= "post " ACTION= " " name= "form1 ">
<div id= "div1 "> </div> <br>
<INPUT TYPE= "button " value= "escape " onclick= "Escape(); ">
</FORM>
</BODY>
</HTML>

------解决方案--------------------
正则表达式
var m=/^[\u4e00-\u9fa5a-z0-9][\u4e00-\u9fa5a-z0-9\-]{6,20}$/i
汉字字母数字开头
后面为汉字字母数字中杠
一共7到21个字符
  相关解决方案