Similar code on the network is generally used by JS to determine whether all strings are Chinese, but few codes are used to determine whether the strings contain Chinese characters. Three methods are provided here:
<Script language = "JavaScript"> function funcchina () {var OBJ = document.form1.txt name. value; If (/. * [\ u4e00-\ u9fa5] +. * $ /. test (OBJ) {alert ("cannot contain Chinese characters! "); Return false;} return true ;} </SCRIPT> <form name = "form1"> <input type = "text" name = "txtname"> <input type = "button" name = "buttxt" value =" determine whether it is a Chinese character "onclick =" funcchina () "> </form>
<Script language = "JavaScript"> function ischina (s) {var patrn =/[\ u4e00-\ u9fa5] | [\ ufe30-\ uffa0]/GI; If (! Patrn.exe C (s) {return false;} else {return true;} alert (ischina ("www.zzsky.cn"); </SCRIPT>
<Script language = "JavaScript"> var STR = 'webmaster of China sky www.zzsky.cn '; If (escape (STR ). indexof ("% u") <0) {alert (" 文 ");} else {alert (" 文 ") ;}</SCRIPT>
In Java:
/*** Determine whether STR is a Chinese character. ** @ Param Str * @ return */Private Static Boolean chineseencode (string Str) {char [] chars = Str. tochararray (); Boolean isgb2312 = false; For (INT I = 0; I <chars. length; I ++) {byte [] bytes = ("" + chars [I]). getbytes (); If (bytes. length = 2) {int [] ints = new int [2]; ints [0] = bytes [0] & 0xff; ints [1] = bytes [1] & 0xff; if (ints [0]> = 0x81 & ints [0] <= 0xfe & ints [1]> = 0x40 & ints [1] <= 0xfe) {isgb2312 = true; break ;}} return isgb2312 ;}