Validation allow only number and characters in edit text in android

后端 未结 9 1434
抹茶落季
抹茶落季 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:10

    You can validate this by two ways , both worked for me, hope will be helpful for you too.

    1> Mentioning the chars in your edittext .

    android:digits="0,1,2,3,4,5,6,7,8,9,*,qwertzuiopasdfghjklyxcvbnm,_,-" 
    

    2> Can validate pragmatically as answered by milos pragmatically

提交回复
热议问题