You can improve Webform effectiveness with client side field validation in your custom Webforms.
Webform text fields support field validation through regular expression testing, which allows the designer to specify a pattern that a document or form field must match. If the field does not match the pattern, an error dialog box is displayed and the input focus is set to the field in error. The designer can optionally specify the message to be displayed, or a generic default message is used. The associated field definition properties are:
- validateRegEx. The javascript regular expression that the field must match. The regular expression starts with "/" and ends with "/" or "/I".
- validateErrorMsg. The error message to display if the field value does not match the validateRegEx pattern. The name of the field label can be referenced with the parameter "{0}". If the validateErrorMsg is not specified, the contents of the message named fieldInvalid are displayed.
For example, your error message might be "The text you entered in the {0} field is invalid.".
Note: Place error messages in message files, not directly in the property value. For example, to explicitly reference the default message, the value of the validateErrorMsg property would be !py:webformsUtil.getNoArgMsg('fieldInvalid')
For details on javascript commands, see Using javascript.
For details on javascript regular expressions, consult a reference on JavaScript. One source on the web is:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsjsgrpregexpsyntax.asp
Additional sample patterns:
- /^[a-z]*$/. Any number of lowercase characters
- /^\d+$/. One or more digits (0-9)
- /^\d(2,4)$/. Between 2 and 4 digits
- /./. Required field that must not be empty
- /\S/. Required field that must contain something other than white space
- /^\w(3)\d?$/. Exactly three word characters and an optional digit
- /^(\d{3}|[a-z]|\?)$/i. Either three digits or an uppercase or lowercase letter (a-z) or a question mark character