0

I wounder if there is some different way of validating EditText on android controlls.. Or should I use the regular java way of doing this?

Troj
  • 11,781
  • 12
  • 40
  • 49
  • If you call the `validate()` method, it reads your mind and knows if what the user input is what you consider valid – Falmarri Oct 28 '10 at 21:06

5 Answers5

0

Depending on what your requirements are, you can look at the android:inputType attribute. This can be quite a bit easier in some cases. For example, specifying android:inputType=number will simply disallow non-numeric symbols from being entered into the EditText box.

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
0

What kind of validation are we taking about?

Numbers:

android:numeric="decimal"

Length:

android:maxLength="10"

You can also provide "hints" of what the valid data should be:

android:hint="@string/numberHint"

Also see this answer

Community
  • 1
  • 1
Bryan Denny
  • 27,363
  • 32
  • 109
  • 125
0

If you really want some fancy validation use the java.util.regex class

link text

(Matcher and Pattern)

NickT
  • 23,844
  • 11
  • 78
  • 121
0

Validation is somewhat tedious. Maybe I can help you in a more generic manner. I have written a basic framework to validate fields in Android.

It is totally free, and you can do whatever you like with it.

Jaavaaan
  • 122
  • 1
  • 4
0
if(TextUtils.isEmpty(password)){
                    nPassword.setError("Password is required");
                    return;
                }

if(password.length() < 6){
                    nPassword.setError("Password must be greater than 6 characters");
                    return;
                }

''''''''''

"These are two sample validation, one checks if EditText is empty or not. Second one checks if length of the string in edit text is greater than 6 or not."