is String Valid English Or Chinese - Android Internationalization

Android examples for Internationalization:Chinese

Description

is String Valid English Or Chinese

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Hashtable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{


    public static boolean isValidEnglishOrChinese(String str) {
        if (null == str) {
            return false;
        }/*from  w  w w.  j  ava  2s .  c o  m*/
        Pattern p = Pattern.compile("^[A-Za-z]*|[\u4E00-\u9FA5]*$");
        Matcher match = p.matcher(str);
        return match.matches();
    }

}

Related Tutorials