How to create EditText accept alphabets only in android

How to make a edittext into android application that can only get/accept Alphabetic value from user.

EditText alphabetic condition allows us to set condition on our EditText so it will only demand alphabetic values likes [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r , s, t, u, v, w, x, y, z]. So here is the complete step by step tutorial for How to create EditText accept alphabets only in android by adding android:digits=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz” attribute into edittext.

android-project-download-code-button

How to create EditText accept alphabets only in android.

Code for MainActivity.java file.

 package com.edittextalphabets_android_examples.com;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.edittextalphabets_android_examples.com.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:hint="EditText "
 android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" >

 
 </EditText>

</RelativeLayout>

Screenshot:

How to create EditText accept alphabets only in android

Click here to download How to create EditText accept alphabets only in android project.

Leave a Reply

Your email address will not be published. Required fields are marked *