androiduser-inputdatabase-server

Limit languages in Android/iOS for input text


Is there any way to limit the input text of edittext to english and hebrew only? Since data is transferred to a server SQL DB, and I do not want to store other languages.... So is it a way to limit to specific language input?

Or maybe there is other way to handle these situation so server will not crash...

Yoav


Solution

  • You can create a custom InputFilter and set it as a filter for your EditText. There's more info about how to do this in this thread. Here's an adaptation of what's there:

    InputFilter filter = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end, 
            Spanned dest, int dstart, int dend)
        {
            for (int i = start; i < end; i++) {
                if (!isEnglishOrHebrew(source.charAt(i))) { 
                    return "";
                }
            }
            return null; 
        }
    
        private boolean isEnglishOrHebrew(char c) {
            . . .
        }
    }; 
    
    edit.setFilters(new InputFilter[]{filter});