---
title: "JAVA验证中文正则"
author: "adamed"
date: "2012-02-20T22:03:12Z"
tags: []
categories: ["Web前端"]
slug: "java"
draft: false
lastmod: "2012-02-20T22:03:12Z"
id: 1415146
url: "https://adamed.iteye.com/blog/1415146"
---

public static void main(String\[] args) {

String userName = "将";

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

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

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

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

} else {

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

}

}