tags:

views:

1045

answers:

4

Dear Friends, I want to know how to make a validation on EditText.That is ,I am having one EditText that edit text should has to accept only numaric values,If other than numaric value is typed by user then it should show some alert message "pls type the numaric value...." Is any function is avilable to find the entered text is particular type..pls give me some idea how to handle this situation.if possible give code snippet.

regards, s.kumaran.

+2  A: 

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

Will
A: 

another way , editText.setInputType(InputType.TYPE_CLASS_NUMBER);

piyushnp
A: 

Hi,

The default capabilities for text/checkbox etc validation is poor within android. I have written some supporting classes to fix this. It contains a validator interface, an abstract inplementation,a validationresult class and 2 examples of custom implemented validations. 1 for regular expressions on text and a simple one to check if a checkbox is checked.

Here is the link to my blog containing the sources and a small bit of explaining Form validation on Android

Kind regards [http://nl.linkedin.com/in/marcdekwant]

Jaavaaan