The condition should work when registering a user, that when he enters his nickName then it must consist of letters of the Latin alphabet and without spaces. I know how to check for spaces, but how to check that a string consists of letters of the Latin alphabet?
- oneProbably you need to check not the language, but the alphabet. The English alphabet is only 26 letters when coerced to one register ... - Vladimir Martyanov
- Check what you need. It's one thing if it's just Latin letters and quite another if you need to recognize grammar. - Sergiy Medvynskyy
- @SergiyMedvynskyy I just need latin letters - Aleksey Timoshchenko
- @ Vladimir Martiyanov even it seems to me that this is not quite right ... I hope there is a more even method. Although if I don’t find it, I’ve already thought to do so ... - Aleksey Timoshchenko
- oneAnd what this does not suit you? I don’t know for a toad, but on a python if str [i] in englishLetters ... is a couple of lines. - Vladimir Martyanov
|
1 answer
Check the string for the presence of only Latin characters:
boolean onlyLatinAlphabet = string.matches("^[a-zA-Z0-9]+$"); Prevent entering Latin characters in EditText:
<EditText android:inputType="textFilter" android:digits="@string/myAlphaNumeric" /> <string name="myAlphaNumeric">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</string> Or
editText.setFilters(new InputFilter[]{new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { Pattern pattern = Pattern.compile("^[a-zA-Z0-9]+$"); Matcher matcher = pattern.matcher(source); if (!matcher.matches()) { return ""; } return null; } }}); - And what is the difference between how to set the restriction for the
EditTextin the XML file or in the code to implement as you described? Only in the implementation? or is there a difference in work? - Aleksey Timoshchenko - @AlekseyTimoshchenko, the difference is only in implementation - katso
|