js代码:
functionisChn(str){varreg=/^[u4E00-u9FA5]+$/;if(str.length()>=5&&str.length()<=18){if(reg.test(str)){returntrue;}}returnfalse;}java代码:publicstaticbooleanisChn(Stringstr){if(str.length()>=5&&str.length()<=18){str=newString(str.getBytes());//用GBK编码Stringpattern="[u4e00-u9fa5]+";Patternp=Pattern.compile(pattern);Matcherresult=p.matcher(str);returnresult.matches();//是否含有中文字符}returnfalse;}追问你这个java代码能不加首尾匹配?? “+”能屏蔽掉非中文??
publicstaticbooleancheck(Stringsource){Patternp=Pattern.compile("[u4E00-u9FA5]{5,18}");Matcherm=p.matcher(source);while(m.find()){returntrue;}returnfalse;}
java:publicstaticbooleanisChinese(Stringstr){returnstr.matches("^[u4e00-u9fff]{5,18}$");}js:functionisChinese(str){return/^[u4e00-u9fff]{5,18}$/.test(str);}