Making an EditText field accept only letters and white spaces in Android

前端 未结 10 703
别跟我提以往
别跟我提以往 2020-12-18 21:09

I have an EditText field in my project which stands for the full name of the person.So I want only letters and spaces to be allowed in it.So I tried the following in the

10条回答
  •  失恋的感觉
    2020-12-18 21:50

    Add this line in your EditText tag.

    android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

    Your EditText tag should look like:

    
    

    it works perfectly and no validation condition required


    update 1

    regex src.toString().matches("[a-zA-Z ]+")


    update 2

    Fair enough if that's the case then simply add space in between.

    android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"

提交回复
热议问题