http://www.zmcn.com/bbs/html/5_191.htm
Rem 汉字判断
function isChinese(para)
on error resume next
dim str
dim i
if isNUll(para) then
isChinese=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isChinese=false
exit function
end if
for i=1 to len(str)
c=asc(mid(str,i,1))
if c>=0 then
isChinese=false
exit function
end if
next
isChinese=true
if err.number<>0 then err.clear
end function
%>如:
if not isChinese(request("name")) then
errmsg=errmsg+"
"+"<li>用户名应为汉字"
founderr=true
else
username=trim(request("name"))
end if
这样更简单
for(i=0;i<realname.length;i++){
char=realname.charCodeAt(i);
if(!(char>255)){
alert("真实姓名应为汉字!");
userform.realname.focus();
return false;
}
Rem 汉字判断
function isChinese(para)
on error resume next
dim str
dim i
if isNUll(para) then
isChinese=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isChinese=false
exit function
end if
for i=1 to len(str)
c=asc(mid(str,i,1))
if c>=0 then
isChinese=false
exit function
end if
next
isChinese=true
if err.number<>0 then err.clear
end function
%>如:
if not isChinese(request("name")) then
errmsg=errmsg+"
"+"<li>用户名应为汉字"
founderr=true
else
username=trim(request("name"))
end if
这样更简单
for(i=0;i<realname.length;i++){
char=realname.charCodeAt(i);
if(!(char>255)){
alert("真实姓名应为汉字!");
userform.realname.focus();
return false;
}
<input type=button value=ok onclick="cc()">
<script language=javascript>
function cc()
{
var j = 0;
var s = document.all.txt.value;
if (s=="")return;
if (/[^x00-xff]/g.test(s)) alert("含有汉字");
else alert("全是字符");
for (var i=0; i<s.length; i++)
{
if (s.charCodeAt(i) > 255) j = j + 2;
else j++
}
alert("字符数:"+j);
}
</script>
$s = "全球化的趋势在China蔓延。";
preg_match_all("/[\x80-\xff]?./",$s,$regs);
print_r($regs);
?>
按中文编码标准,一个汉字由两个字节组成,其中首字符的值>128即16进制80
$str = "我爱你:php";
if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str) {
echo "这是一个纯中文字符串";
} else {
echo "这不是一个纯中文字串";
}
BIG码汉字是0xA440-0xF97E、0xA4A1-0xF9FE吧?
以前我用一个切字符串的改处理简体就处理不了繁体改处理繁体就处理不了简体如何同时对繁简体进行检测?
可以匹配任何字符,其中
[\x80-\xff]匹配扩展ascii码部分,.匹配任意字符
任何宽字符都由一个“扩展ascii码”字符和一个“任意字符”组成,只是这个“任意字符”是受限的