How to determine if edittext has english characters

I want to determine if my edittext English characters and notify the user of its change, because I want just Persian characters for the first and last name. how can i filter edittext to accept only persian characters or detect english characters and show error?

+5
source share
5 answers

I think that it is not easy to detect and tell the user to instruct. You can just do something like that. In the XML file:

 <EditText android:id="@+id/LanguageText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="text" android:digits="@string/app_lan" /> 

In Strings.xml:

 <string name="app_lan">YOUR LANGUAGE</string> 

Example If English:

 <string name="app_lan">abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ</string> 

For the ur language is the same as this.

+9
source

Persian characters are within the range: [\u0600-\u06FF] . Confirm your string with a regex.

+4
source

Try the following regular expression Persian character range.

 public static final Pattern RTL_CHARACTERS = Pattern.compile("[\u0600-\u06FF\u0750-\u077F\u0590-\u05FF\uFE70-\uFEFF]"); Matcher matcher = RTL_CHARACTERS.matcher("Texts"); if(matcher.find()){ return true; // it RTL } 

Or use this method.

 public static boolean textPersian(String s) { for (int i = 0; i < Character.codePointCount(s, 0, s.length()); i++) { int c = s.codePointAt(i); if (c >= 0x0600 && c <=0x06FF || c== 0xFB8A || c==0x067E || c==0x0686 || c==0x06AF) return true; } return false; 
+4
source
 public final static String PERSIAN_STRING = "ا آ ب پ ت ث ج چ ح خ د ذ ر ز ژ س ش ص ض ط ظ ع غ ف ق ک گ ل م ن و ه ی"; public final static String LATIN_STRING = "abcdefghijklmnopqrstu vwxyz"; if (PERSIAN_STRING.contains(str.toLowerCase())) lang = "PERSIAN"; if (LATIN_STRING.contains(str.toLowerCase())) lang = "LATIN"; 
+1
source

Summing up a couple of things here. Since @Sergei Podlipaev noted that Persian characters range from \u0600 to \u06FF , you can use a regex. I am not sure if I am defining the boundaries correctly, but this will give you an idea.

To find out if the English character set is used - ^[a-zA-Z0-9]*$
To see if the Persian character set is used - ^[\u0600-\u06FF]+$

+1
source

All Articles