程序設計中我們時常需要檢測用戶輸入是否正確,特別是姓名,地址等等是不是輸入的漢字。那么,如何判斷一個字符是不是漢字呢?其實在asp中至少有兩種方式 一、直接將某字符用asc轉為ascii碼,如果是英文,他應該是0-127的范圍,而漢字則是一個比較大的數字,所以可以使用以下代碼來判斷: if abs(asc(whichchar))>127 then response.write whichchar & "是一個漢字" else response.write whichchar & "不是一個漢字" end if 二、漢字的unicode編碼范圍是4e00-9fa5,所以使用正則表達試就可以判斷一個漢字是不是漢字了。 set regexpobj=new regexp regexpobj.pattern="^[/u4e00-/u9fa5]+$" regcheck=regexpobj.test(whichchar) set regexpobj=nothing if regcheck then response.write whichchar & "是漢字" else resposne.write whichchar & "不是漢字" end if