0
I want edit Text  should be validated characters alone allowed , character & number allowed but number alone not allowed.so can you help me with above issue. I cant able to fix can you help with this.

Below is the sample code. I want edit Text should be validated characters alone allowed , character & number allowed but number alone not allowed.so can you help me with above issue. I cant able to fix can you help with this.Below is the sample code.

Like this gavin - allowed, gavin1222 - allowed, 15 - not allowed
i want to validate - text with numbers allowed and numbers only not allowed

<EditText
 android:id="@+id/edit_employee_name"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 android:layout_marginStart="20dp"
 android:layout_marginLeft="20dp"
 android:background="@drawable/edittext_background"
 android:fontFamily="@font/poppins_medium"
 android:gravity="start"
 android:hint="Beautician Name"
 android:inputType="textPersonName||number"
 android:maxLength="25"
 android:padding="10dp"
 android:singleLine="true"
 android:text=""
 android:textSize="14sp" />
Toto
  • 89,455
  • 62
  • 89
  • 125
  • 1
    Does this answer your question? [How To Validate an EditText to handle numbers only in Android?](https://stackoverflow.com/questions/9449513/how-to-validate-an-edittext-to-handle-numbers-only-in-android) – Khal Aug 28 '20 at 11:43
  • no this is not correct – Clinton Eagle Aug 28 '20 at 12:01
  • What do you want to happen if the user starts by typing numbers, but intends to add letters as well? – Gavin Wright Aug 28 '20 at 13:44
  • I want able to write number and text and text only but number only not allowed @GavinWright – Clinton Eagle Aug 29 '20 at 04:57
  • Like this gavin - allowed, gavin1222 - allowed, 15 - not allowed – Clinton Eagle Aug 29 '20 at 05:01
  • Then you should get rid of the `inputType` attribute so the user can type whatever they want. Then, when they hit the Submit button or whatever it is, you validate the input in the `EditText` manually. Or add a `TextWatcher` to the `EditText` to validate the input as they type and [display an error](https://stackoverflow.com/questions/18225365/show-error-on-the-tip-of-the-edit-text-android) if the user's input is invalid. – Gavin Wright Aug 29 '20 at 09:10
  • i want to validate - text with numbers allowed and number only not allowed @GavinWright – Clinton Eagle Aug 31 '20 at 05:55
  • @ClintonEagle Right, I gave you two ways of doing that. But you can't do it with `inputType`. – Gavin Wright Aug 31 '20 at 08:07
  • What have you tried? What didn't work? What did you get? What did you expect? What doesn't work with your code and where is it? – Toto Aug 31 '20 at 08:57

0 Answers0