ITeye博客

JAVA验证中文正则

adamed · 2012-02-20 22:03 · 技术类 · Web前端 · Markdown

public static void main(String[] args) {

String userName = "将";

//验证字符串只能是中文且长度1-4个字符

//重点在于最后那个\p表示Unicode查询,大写的P表示标点见:http://www.unicode.org/reports/tr18/

if (userName.matches("[\u0391-\uFFE5\\pP]{1,4}")) {

System.out.println("匹配");

} else {

System.out.println("不匹配");

}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。