StoreCenter Help : Online Editor : Variable Actions Samples : Form Validation with Correction
Form Validation with Correction
This example uses two variables to check the format of the value entered by a shopper for a phone number, corrects the input and generates warnings until the number is entered according to the correct format.
Figure 10.116: Actions insert brackets, spaces and dashes for a phone number and generates warnings until the input is correct.
Summary
A phone number must have the following format:
(123) 456-7890
You want to cope with the following examples of incorrect input:
1234567890
123-456.7890
123/456_7890
(123) 456 7890
Two variables are required to accomplish the validation and correction. One visible variable that validates the input of the user and another hidden variable that corrects the input of the first variable to the expected format. Only the hidden variable is used in the source code of the text frame in the document.
variable 1: Phone number_input
If the user types fewer or more than 10 digits, a warning is displayed. The action also displays a warning if the user enters a character which is not a digit, a space, a hyphen or round brackets. In addition to the warning, the action automatically omits the unsupported characters. This input variable is visible on the form.
Action type: Validate (In the Actions tab, edit Validate.)
Variable type: Short Text
Set to Visible
Regular expressions used in the action code for the regexp string:
/[^\d]/gi
/[^\d\-\/\(\)\. ]/gi
Action code: see screenshot
variable 2: Phone number_normalized
A second variable, in this example called Phone number_normalized, has a Value action type. This variable is used in the first variable but is not visible on the form.
Action type: Value (In the Actions tab, edit Value.)
Variable type: Calculated Field
Visible not selected
Regular expressions used in the action code for the regexp string:
/[^\d]/gi
Action code: see screenshot
doc. version 6.0.4