match Chinese by regex - Android java.util.regex

Android examples for java.util.regex:Character Pattern

Description

match Chinese by regex

Demo Code


//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    private static final String V_CHINESE = "^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$";

    public static boolean Chinese(String value) {
        return match(V_CHINESE, value);
    }/*w  ww  .  j a va2 s.  co  m*/

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related Tutorials