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?
-
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 Answers
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.

- 35,455
- 10
- 90
- 93
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"

- 1
- 1

- 27,363
- 32
- 109
- 125
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.

- 122
- 1
- 4
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."