TheJadav

Restrict EditText for Numeric and Capital alphabets

Restrict edittext for numeric and capital alphabets input is so easy in android. We just need to add two lines of code in xml file and we are ready. textCapCharacters

Restrict EditText for numeric and capital alphabets input is so easy in android. We just need to add two lines of code in xml file and we are ready.

But why we need to do it?

May be we just want edittext for pan number verification, or may be other use case where we know user must enter all details in capital. The below EditText is capable enough to do it :

<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/etInput"
    style="@style/App_EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/margin_extra"
    android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    android:text="@={viewModel.currentQuestion.desc}"
    android:inputType="textCapCharacters"
 />

Share this content:

Share:

More Posts

How does data persistence work in Android?

Data persistence in Android is the ability to save data to the device so that it can be accessed later, even if the app is closed or the device is restarted. There are several ways to achieve data persistence in Android

Fragments and Activities: Two Pillars of Android Development

Fragments and Activities are both important components of Android development. Fragments are a good choice for creating reusable and dynamic UIs, while Activities are a good choice for managing the lifecycle of an app’s UI and implementing core features.

Table of Contents

Send Us A Message