日期:2014-05-18  浏览次数:20832 次

怎样验证一个文本框中输入的是汉字啊 ??
function   tt(){
  if(document.all.wenben.value!= 'chs '){
{alert( "请输入汉字 ");
document.all.wenben.focus();
document.all.wenben.value= " ";}
这个对吗??
为什么我输入是汉字的时候他也说错啊

------解决方案--------------------
MARK一下

------解决方案--------------------
你这是判断输入的是否是 'chs '
------解决方案--------------------
我这儿有一个用java写的判断用户输入中是否包含中文,也许对你有用
import java.io.*;
public class IsIncludeCH{
static BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
public static void main (String args[])throws IOException{
String sent;
int num;
System.out.print( "please input a String: ");
System.out.flush();
sent=keyboard.readLine();
java.util.regex.Pattern p=java.util.regex.Pattern.compile( "[\u4e00-\u9fa5] ");
java.util.regex.Matcher m=p.matcher(sent);
if(m.find())
{
System.out.println( "含有中文 ");
}else
{
System.out.println( "没有中文 ");
}
}
}

------解决方案--------------------
用正则表达式就可以了
function checkChs(str)
{
var reg=/^[\u4e00-\u9fa5](\s*[\u4e00-\u9fa5])*$/;
return reg.test(str);
}
------解决方案--------------------
很好,学习了/