One of the most important aspects of building and processing a form is how you validate the input data. You want to assist users by providing them with information to help them make choices as they fill out the form and to understand what's required and optional before selecting the submit button.

In classic server-based Web applications, once the enter or submit button is clicked, form data is passed to CGI script, or some other technology. If the data contains an error, there will be a delay before the information travels over the Internet to the server, is examined on the server, and then returns to the user along with an error message.

We will incrementally build the registration page. Let's first start with a simple example using a TextField in order to discuss the syntax. The idea is to create a validation requirement that is associated with the control. The validate-with procedure is placed on each control that uses validation. The validator is the only required argument. This specifies the type of validation for the control to be valid, in our case a StringValidator.

A StringValidator ensures that a input value is not blank. We have also added keyword arguements to enforce size limits (min-chars and max-chars).

The procedure validate-with requests validation on the control. In our case, a TextField. A ValueChanged or ValueFinished event on the control triggers the validation cycle. Note that if you do not specify min-chars and min-chars, then any length String is acceptable.

Let's add a MessageDisplay to the validation. A MessageDisplay is graphical object used to display validation messages to the user. In the following example, the first control uses the default message created by Curl. We have also added a user-age input that validates using a NumericValidator that displays a custom message.

The MessageDisplay object needs to be created in order to hold the message. The MessageDisplay is referenced in each control, for example:

Code:

message-display = neme-feedback

Since each control object has its own MessageDisplay, if the user inputs an invalid value, then the associated message will display to the right of the control until the input becomes valid. A message will also appear if the user does not input a value for the user-age since required? = true is specified.

Now, let's place additional controls that target common types of entries such as phone number, email, and zip code. In these cases, we can specify a ValidationPattern. For example {validate-with ValidationPattern.us-zip-code} is used to validate a us zip code. Other patterns include credit cards, http-urls, social security numbers, as well as patterns for French, German, Japanese, and Chinese entries. Please see ValidationPattern for more information.

If you run a validation of the user’s form input before the form is submitted, there will be no wait time and redundant load on the server. Invalid inputs are already filtered out when input is passed to the server-based program. It also allows to simplify server-based program. In Curl, data can be validated in real-time, as the user enters information into the form.

Our example is a simple registration page that will validate the entries on the client machine (without the need to query the server). If an entry requires a specific input that has not been entered, a validation message will be displayed to the user. Once all valid information has been input into the dialog, the Enter button will be enabled. When the user clicks the Enter button, it will display the input information in a popup dialog.

•Used the same MessageDisplay for each control. The feedback will be displayed to the right of the Enter button.

While it is possible to use validation on individual controls, the system is most often used to validate controls grouped in a Dialog (including subclasses such as RecordForm or HttpForm). The validation cycle starts when an entry is changed and ends when all necessary feedback has been shown. This also allows us to enable the Enter button when the Dialog is valid.

In summary, form validation is the first step for allowing users to easily input form values. In our example, we presented the input values using a popup-message. If you wish to submit the valid information to a server for processing, please see the Curl Developer's Guide for more information.