Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation on Edit Text

I would like to know how to make a validation on EditText. For example, I have one EditText that should only accept numeric values. If something other than a numeric value is typed by the user then it should show an alert message (i.e. "please use a numeric value....").

Is there a function available to find out if the entered text is particular type? If possible please include a code snippet.

like image 237
Kumar Avatar asked Jul 20 '09 04:07

Kumar


People also ask

How do I set text field validation?

In this example, learn how to add validation to a form that has a single text field using the following steps: Create a Form with a GlobalKey . Add a TextFormField with validation logic. Create a button to validate and submit the form.

What is text field validation?

Validation ensures that only certain values are entered in a field. Validation functionality is available for text and numeric fields. To enable validation, Add a Text or Numeric field to a form in the Builder view.

How do you add validation to a text box in HTML?

To validate the form using HTML, we will use HTML <input> required attribute. The <input> required attribute is a Boolean attribute that is used to specify the input element must be filled out before submitting the Form.


1 Answers

Rather than make a pop-up I would integrate a hint into the EditText and I would make it so the user could only type numbers into the EditText (android:numeric, android:hint):

        <EditText android:layout_height="wrap_content"
                      android:numeric="integer"
                      android:hint="@string/numberHint"
                      android:gravity="left"
                      android:id="@+id/name" 
                      android:layout_width="wrap_content" 
                      android:maxWidth="60dp" 
                      android:textSize="6pt">
        </EditText>

More information is available here: http://developer.android.com/reference/android/widget/EditText.html

like image 100
Will Avatar answered Sep 23 '22 02:09

Will