---
title: "EditText field accept only letters and white spaces in Android"  
description: "EditText field accept only letters and white spaces in Android"  
author: "Anonymous User"  
published: 2014-10-19  
updated: 2014-10-19  
canonical: https://www.mindstick.com/forum/2418/edittext-field-accept-only-letters-and-white-spaces-in-android  
category: "android"  
tags: ["android", "java", "validation"]  
reading_time: 1 minute  

---

# EditText field accept only letters and white spaces in Android

I have an EditText [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) in my [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) which stands for the [full name](https://answers.mindstick.com/qa/110831/what-is-queen-elizabeth-ii-s-full-name) of the person.So I want only letters and spaces to be allowed in it.So I tried the following in the [XML file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php)\

```
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
```

\
But it didn't work.Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) how to do it?

## Replies

### Reply by Anonymous User

**use regex.**. pattern should be\
Full_Name_Pattern = "[A-Z][a-z]+( [A-Z][a-z]+)*";

### Reply by Anonymous User

**Try this:**

```
EditText yourEditText = (EditText) findViewById(R.id.yourEditText);yourEditText.setFilters(new InputFilter[] {    new InputFilter() {        @Override        public CharSequence filter(CharSequence cs, int start,                    int end, Spanned spanned, int dStart, int dEnd) {            // TODO Auto-generated method stub            if(cs.equals("")){ // for backspace                 return cs;            }            if(cs.toString().matches("[a-zA-Z ]+")){                 return cs;            }            return "";        }    }});
```


---

Original Source: https://www.mindstick.com/forum/2418/edittext-field-accept-only-letters-and-white-spaces-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
