0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1136875
  • 613
  • 1
  • 9
  • 22
  • server crashes if you use a different language? How does the server even know what language the text you send is in? – zapl Mar 18 '12 at 18:37

1 Answers1

2

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});
Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521