Validation Patterns for Numbers, Text and More
A popular request from form builders is how to set validation patterns for text input fields. For example, with a Short Answer item the form owner can set the Validation setting to collect answers that match a preferred format.
The list of validation patterns includes:
- Text only
- Number
- Alpha-Numeric
- CC Expiration Date
- URL
- Phone Number
- US Phone Number
- Currency
- US Currency ($)
- Whole Number
- 12 Hour Time
- 24 Hour Time
Choosing the Correct Text Input Item
There are a few choices of text input item and choosing the right one depends on the expected answer.
Adding an Email Address item to the form validates the answer for proper email address formatting (x@x.x). The Email Address item uses the entered email address for sending Notification emails from Formsite.
Use a Number item for collecting a number with or without decimal places. The Number item strips leading zeros (as rational numbers do), and can be part of Calculation item equations.
The Short Answer item is the basic text input field and contains the Validation setting. The list of validation patterns includes numbers and currency, but does not work the same as the Number item. For example, the Number item can collect a number that can be part of an equation, while the Short Answer item would collect the number as text.
An easy way to see the difference is when collecting a string of numbers that has leading zeros, like a US zip code. Since zip codes may start with one or more zeros, using the Short Answer item instead of the Number item preserves those initial zeros.
Short Answer Validation Patterns
The Short Answer item also provides the ability to validate Numbers only, as well as Whole Numbers (no decimal) and Currency values (2 decimals).
The Alpha-Numeric pattern checks for only letters and numbers and doesn’t allow special characters. The URL pattern looks for a properly-formatted URL that begins with “http” and contains a real domain.
Note that the Validation setting only provides a way to check the format and does not validate the existence or legitimacy of URLs or email addresses.