日期:2014-05-16 浏览次数:20864 次
<script language="jscript" runat="server">
var encode=function(str){
if(str==undefined) return "";
if(str=="")return "";
var i, j, aL1, aL2, c, p,ret="";
aL1 = Array(0x22, 0x5C, 0x2F, 0x08, 0x0C, 0x0A, 0x0D, 0x09);
aL2 = Array(0x22, 0x5C, 0x2F, 0x62, 0x66, 0x6E, 0x72, 0x74);
for(i = 0;i<str.length;i++){
p = true;
c = str.substr(i,1);
for(j = 0;j<=7;j++){
if(c == String.fromCharCode(aL1[j])){
ret += "\\" + String.fromCharCode(aL2[j]);
p = false;
break;
}
}
if(p){
var a = c.charCodeAt(0);
if(a > 31 && a < 127){
ret +=c
}else if(a > -1
------解决方案--------------------
a < 65535){
var slashu = a.toString(16);
while(slashu.length<4){slashu="0"+slashu;}
ret += "\\u" + slashu;
}
}
}
return ret;
};
</script>
<%
response.write encode("测试")
%>
Function JS_CN_STR(ByVal str)
With New RegExp
.Global = True
.Pattern = "%u([A-Fa-f0-9]{4})"
JS_CN_STR = Unescape(.Replace(Escape(str), "\u$1"))
End With
End Function
Response.Write JS_CN_STR("用户名不能全是数字")