is Chinese English by regex - Android Internationalization

Android examples for Internationalization:Chinese

Description

is Chinese English by regex

Demo Code

import android.text.TextUtils;
import android.util.Base64;
import java.io.UnsupportedEncodingException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Main{


    public static boolean isChineseEnglishFormat(String str) {
        Pattern p = Pattern
                .compile("^[\\u4E00-\\u9FA5\\uF900-\\uFA2DA-Za-z0-9]+$");
        Matcher m = p.matcher(str);
        str = str.replaceAll("[^\\x00-\\xff]", "**"); 
        int length = str.length();
        return m.matches() && (length >= 4 && length <= 16);
    }//  w w  w . ja va2s.  c o  m

}

Related Tutorials