Form Validation
This example checks the syntax of the value entered by a shopper and creates a yellow icon with a warning in the tooltip.
Figure 10.114: A Validate action checks the syntax of an e-mail address and generates a warning icon with tooltip.
Summary
The action code uses a regular expression to validate the shopper’s input on the form. Several action code samples are given below to validate an e-mail address, a car license plate and a bank account number.
Action type: Validate (In the Actions tab, edit Validate.)
Variable type: Short Text
Document with variables defined and set to Visible
Regular expressions used in the action code for the regexp string:
an e-mail address: e.g. john.doe@mycompany.com
^([a-zA-Z0-9.\-]+)@([a-zA-Z0-9.\-]+)$
a license plate: e.g. 1 ABC 234
^(([0-9]{0,1}[ ]*[A-Z]{3}[ ]*[0-9]{3})|([0-9]{3}[ ]*[A-Z]{3}))$
a bank account number: e.g. 123-4567891-23
^[0-9]{3}-[0-9]{7}-[0-9]{2}$
a phone number: e.g. 123 45 678
^[0-9]{3}[ ][0-9]{2}[ ][0-9]{3}$
Action code:
to validate an e-mail address:
1 if stringFunctions matchesRegExp string: variable My_Email value is not true
regexp: string ^([a-zA-Z0-9.\-]+)@([a-zA-Z0-9.\-]+)$
2 return string The e-mail you entered is not correct.
3 end if
Action code: to validate a license plate:
1 if stringFunctions matchesRegExp string: variable My_License value is not true
regexp: string ^(([0-9]{0,1}[ ]*[A-Z]{3}[ ]*[0-9]{3})|([0-9]{3}[ ]*[A-Z]{3}))$
2 return string The license plate you entered is not correct.
3 end if
Action code: to validate a bank account number:
1 if stringFunctions matchesRegExp string: variable My_Account value is not true
regexp: string ^[0-9]{3}-[0-9]{7}-[0-9]{2}$
2 return string The account you entered is not correct.
3 end if
Action code: to validate a phone number (with return long string to create a tooltip with multiple lines):
1 if stringFunctions matchesRegExp string: variable My_Phone value is not true
regexp: string \d\d\d <space> \d\d <space> \d\d\d
2 return long string This phone number is not formatted correctly. The expected format is: 123 45 678
3 end if
Figure 10.115: Return long string creates a validation tooltip with multiple lines.
doc. version 6.0.4