Guided Conversation Regex Validation
The Collect Info and Form cards make it easy to collect data from Concierge users. Sometimes that data should be collected in a specific format, like as a phone number, or as an email.
The new Regex (regular expression) validation option provides an incredibly powerful and flexible method of validating the collected info. When a bot user enters the information, the regular expression checks if their input matches the desired format. If the format is incorrect, the bot will return the specified error message and request the user re-enter the information.
Important Form Card Validation Notes
- Form card validation will only work if the collection step has a defined “variable”.
- At this time, form cards will only show the first error encountered.
- Users will have to re-enter their form information when an error occurs.
What is Regex?
Regex is short for regular expression. A regular expression is a sequence of characters that specifies a pattern to which a text string should be matched. If all of that sounds confusing, don’t worry, you’re in good company.
In layman’s terms, a regex can be used to check if some text matches the format defined by the regular expression. People familiar with regex can build their own very specific validation. For the rest of us, we’re happy to provide common examples that can be copy pasted by any user.
Common Regex Expressions
Copy and paste the expressions below to use them for validation. Many other resources for examples of regex validation can also be found by searching the web.
Email
^[_]*([a-z0-9]+(\.|_*)?)+@([a-z][a-z0-9-]+(\.|-*\.))+[a-z]{2,6}$
Phone number
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
Integer
^-?\d+$
Positive number
^\d*\.?\d+$
Negative number
^-\d*\.?\d+$
Decimal
^\d+(\.\d+)?$
City
^[a-zA-Z\u0080-\u024F]+(?:([- '\s])[a-zA-Z\u0080-\u024F]+)*$
Zip Code
^\d{5}(?:-\d{4})?$
Currency
^\$?(\d{1,3})(,\d{3})*(\.\d{2})?$
Credit Card
^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9]{2})[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$