PreviousClient-side Programming Deploying Your ApplicationNext

Chapter 11: Form Validation

This chapter explains how you can call up built-in JavaScript functions to validate the input fields in your form, and how you can add your own validation functions.

The Help topic Validation contains detailed step-by-step descriptions of how to use the features described in this chapter.from the main Contents in the Help, click Programming, then Internet Application Programming, then Form Designer, Form Validation, then Overview - Validation.

11.1 Validation Functions Supplied

Built-in validation functions are available for the following HTML controls:

You can specify whether a field is required and whether you want a prompt displayed on the status line, as well as in a pop-up. The status line prompt is displayed all the time the field has focus, while the pop-up prompt is displayed only when the field loses focus and if the validation fails. You can change the text of the prompt.

The validation function for a field is executed twice:

The following validation functions are supplied with NetExpress:

Name of function Validation performed
American Express card number Conforms to the format for an American Express card number
Credit card number Conforms to all the credit card number formats (American Express, Mastercard and Visa)
e-mail address Conforms to the format for an e-mail address
Mastercard card number Conforms to the format for a Mastercard card number
Number Is a whole number with no sign
Number (decimal) Is a number containing a decimal point; may be signed
Number (signed positive) Is a positive whole number
Number (signed) Is a whole number with an optional sign
Phone number - international Conforms to the format for an international phone number
US phone number Conforms to the format for a US phone number, that is, 10 digits. There may be a space after the third digit and after the sixth digit
US social security number Conforms to the format for a US social security number, that is, 9 digits. There may be a space after the third digit and after the fifth digit
US state code Is one of the valid two-letter abbreviations for a US state
US zip code Conforms to the format for a US zip code, that is, 5 or 9 digits
Visa card number Conforms to the format for a Visa card number

Note: Credit card numbers (American Express, Mastercard and Visa) are not checked to be valid numbers in the sense of having been issued to a particular person.


11.2 Validation Examples

This section contains three examples of invoking validation. These examples assume that you have an .htm file open that contains one or more fields of the type that can have validation applied to them: text input fields, text area fields and password fields.

The Validation dialog box is shown below.


Figure 11-1: Validation Dialog Box

11.2.1 Example 1: To Validate an Optional Decimal Number

To invoke the decimal number validation function and make the field optional:

  1. Select the field that you want to be validated.

  2. Right-click and select Validation... from the popup menu (or select Validation... from the Edit menu). The Validation dialog box appears.

  3. Click Number (decimal) from the Validation list.

  4. Click Required field No. This indicates that the field is optional.

  5. The prompt text associated with the decimal number validation routine is shown in Prompt. If you want to you can edit the text. If you want the prompt to appear on the status line, click Status line prompt.

  6. Click OK.

The effect of invoking this routine is that the end-user can choose to leave the field blank, but if they enter any value that is not a decimal number, they are prompted to return to the field and enter a valid value.

11.2.2 Example 2: To Validate a Mandatory Visa Card Number

To invoke the Visa card number validation function and make the field mandatory:

  1. Select the field that you want to be validated.

  2. Right-click and select Validation... from the popup menu (or select Validation... from the Edit menu). The Validation dialog box appears.

  3. Click Visa card number from the Validation list.

  4. Click Required field Yes. This indicates that the field is mandatory.

  5. The prompt text associated with the Visa card number validation function is shown in Prompt. If you want to you can edit the text. If you want the prompt to appear on the status line, click Status line prompt.

  6. Click OK.

The effect of invoking this routine is that the end-user must enter a valid value. If they do not, they are prompted to return to the field and enter a valid value.

11.2.3 Example 3: To Check that a Mandatory Field is Present

Even if none of the supplied validation functions are appropriate, you can still use the Validation dialog box to specify that a field is mandatory. To do this:

  1. Select the field that you want to be mandatory.

  2. Right-click and select Validation... from the popup menu (or select Validation... from the Edit menu). The Validation dialog box appears.

  3. Click None from the Validation list.

  4. Click Required field Yes. This indicates that the field is mandatory.

  5. The prompt text associated with no validation is shown in Prompt. If you want to you can edit the text. If you want the prompt to appear on the status line, click Status line prompt.

  6. Click OK.

The effect of invoking this routine is that the end-user must enter a value. If they do not, they are prompted to return to the field and enter a value.

11.3 Adding Your Own Validation Functions

You can write your own validation functions for any text input, text area or password fields for which the supplied functions are not appropriate. To do this you need a good grasp of JavaScript or JScript; see the references in the chapter Form Programming for further details.

You have a choice of two ways of incorporating the extra validation into your form:

.


Copyright © 1998 Micro Focus Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.
PreviousClient-side Programming Deploying Your ApplicationNext