0

I am facing this problem, I don't want someone to enter any special char or numbers in my name field.

I want to restrict people from entering any numbers or special characters in my name edittext. Please help me resolve this issue. I am creating a setup profile form for my users.

This is My XML file

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout2"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="20dp"
    android:hint="Enter your Name"
    android:textColorHint="@color/edittxtline"
    app:boxStrokeColor="@color/edittxtline"
    app:errorTextColor="@color/reddark"
    app:hintTextColor="#5A20CB"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView4">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionNext"
        android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout4"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="20dp"
    app:boxStrokeColor="@color/edittxtline"
    app:hintTextColor="#5A20CB"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textInputLayout2">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Email"
        android:inputType="textEmailAddress" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayout5"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="20dp"
    android:textColorHint="@color/edittxtline"
    app:boxStrokeColor="@color/edittxtline"
    app:endIconMode="password_toggle"
    app:hintTextColor="#5A20CB"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textInputLayout4">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Password"
        android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>

<Button
    android:id="@+id/button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="20dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="20dp"
    android:backgroundTint="@color/reddark"
    android:padding="10dp"
    android:text="Update"
    android:textAllCaps="false"
    android:textColor="#FFFFFF"
    android:textSize="15sp"
    app:cornerRadius="5dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textInputLayout5" />

This is the Imageenter image description here

Vivek M Fauzdar
  • 127
  • 1
  • 13
  • 1
    what have you tried ? there are loads of posts explaining how to handle text input and validation, what are you struggling with ? – a_local_nobody Feb 01 '22 at 06:58
  • 1
    Does this answer your question? [How can restrict my EditText input to some special character like backslash(/),tild(~) etc by soft keyboard in android programmatically](https://stackoverflow.com/questions/21828323/how-can-restrict-my-edittext-input-to-some-special-character-like-backslash-t) – a_local_nobody Feb 01 '22 at 07:11
  • i don't know how to restrict these characters or numbers so I did not use anything. – Vivek M Fauzdar Feb 02 '22 at 05:24

1 Answers1

-1

Use this code:

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="text"
Moklesur Rahman
  • 543
  • 6
  • 12