Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Validation Message

I have an XML layout file that contains an EditText and a Button. I would like to display the following validation message to provide feedback to the user:

You must enter 4 numbers

What's the best way to go about accomplishing this?

like image 653
User616263 Avatar asked Feb 22 '11 19:02

User616263


People also ask

What is a validation message?

When you have validation enabled, you can receive messages that validate a filter or function expression. You can receive either warnings or errors based on the information that you have specified in your mapping specification.

How do I display all validation messages in one control?

Add a ValidationSummary control to the page at the location where you want to display the collected error messages. Set the ErrorMessage and Display properties of the individual validation controls. (Default) Each error message appears as a bulleted item. Each error message appears on its own line.

Which HtmlHelper is used to show the validation messages?

ValidationMessage(HtmlHelper, String) Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.

How do you show error messages?

In order to display error messages on forms, you need to consider the following four basic rules: The error message needs to be short and meaningful. The placement of the message needs to be associated with the field. The message style needs to be separated from the style of the field labels and instructions.


1 Answers

From my experience, this is the best way:

EditText yourEditText;

// when you detect an error:
yourEditText.setError("Input must be 4 digits and numeric");

The result is:

enter image description here

Also, if the input must be numeric, use android:inputType="numberSigned" in the EditText definition. That way the device won't allow the user to put non-numeric values; even better, it will show a special keyboard to do so:

enter image description here

like image 147
Cristian Avatar answered Oct 06 '22 19:10

Cristian