Client-side Programming | Deploying Your Application |
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.
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.
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
To invoke the decimal number validation function and make the field optional:
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.
To invoke the Visa card number validation function and make the field mandatory:
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.
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:
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.
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:
Each of the supplied routines is stored in a .js file, and referenced from another file called validate.cpt in the bin directory, so you need both to create your code and store it in a .js file, and to update the validate.cpt file. You can create your code from scratch, either in a text editor or in the Script Assistant, or you can copy one of the built-in routines and edit it to suit your requirements. Step-by-step instructions for the copy and edit approach can be found in the online Help; from the main Contents in the Help, click Programming, then Internet Application Programming, then Form Designer, Form Validation, then How to, Add your own validation function
.
Copyright © 1998 Micro Focus Limited. All rights reserved.
This document and the proprietary marks and names
used herein are protected by international law.
Client-side Programming | Deploying Your Application |