求输入只允许汉字的正则表达式?

changlin365 2005-10-27 05:47:58
求输入只允许汉字的正则表达式?
...全文
796 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qianqi1010 2005-10-28
  • 打赏
  • 举报
回复
up
pauliuyou 2005-10-28
  • 打赏
  • 举报
回复
学习..
leekooqi 2005-10-27
  • 打赏
  • 举报
回复
up
believefym 2005-10-27
  • 打赏
  • 举报
回复
只允许汉字的话改成
Pattern pa = Pattern.compile("^[\u4e00-\u9fa5]*$");//0个汉字应该也行的吧
Matcher m = pa.macther("我们")
return m.find();//true为全部汉字,否则是false
interhanchi 2005-10-27
  • 打赏
  • 举报
回复
import java.util.regex.*;
public class TestString {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s= "sfa10你cc";
Pattern pa = Pattern.compile("[\u4e00-\u9fa5]+");
Matcher ma = pa.matcher(s);
while(ma.find()){
System.out.print(ma.group());
}
}

}

网络精灵 2005-10-27
  • 打赏
  • 举报
回复
用什么编码?我也不知道汉字的范围,关注,up
sjjf 2005-10-27
  • 打赏
  • 举报
回复
帮你mark
whyxx 2005-10-27
  • 打赏
  • 举报
回复
汉字包括很广的,你是指中国字,简体? 繁体? 等等,可以查一下区位表,直接用\uxxxx-\uyyyy这种形式就可以了

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧