Validation allow only number and characters in edit text in android

后端 未结 9 1409
抹茶落季
抹茶落季 2020-11-27 16:20

In my application I have to validate the EditText. It should only allow character, digits, underscores, and hyphens.

Here is my code:

edit         


        
9条回答
  •  感情败类
    2020-11-27 17:21

    A solution similar to the android:digits="0123456789*", is to use this:

    EditText etext = new EditText(this);
    etext.setKeyListener(DigitsKeyListener.getInstance("0123456789*"));
    

    An added bonus is that it also displays the numeric keypad.

提交回复
热议问题