Our email, date, and number blocks contain validation rules to make sure that answers given by users contain a specific structure and set of patterns.
But also, Joonbot allows you to check the user input data against your own predetermined rules.
It's especially useful for phone number validation!
What is a Regex?
Before we get into that, you may or may not have knowledge about regular expressions or "Regex" for short. If you do, skip to the next section below. If not, well, let me make it brief.
A regex is a string of text that allows you to create patterns that help match, locate, and manage text. It is used in all sorts of programming to validate inputs. Joonbot allows you to harness the power of regex in your chatbots.
Regex looks something like this:
Phone numbers:
United States: ^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$
France: (?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}
India: ((\+*)((0[ -]*)*|((91 )*))((\d{12})+|(\d{10})+))|\d{5}([- ]*)\d{6}
Brazil: ^\s*(\d{2}|\d{0})[-. ]?(\d{5}|\d{4})[-. ]?(\d{4})[-. ]?\s*$
Great Britain: ^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$
Italy: ^(([+]|00)39)?((3[1-6][0-9]))(\d{7})$
Postal codes:
United States and Canada: ^(\d{5}(-\d{4})?|[A-Z]\d[A-Z] ?\d[A-Z]\d)$
France: (?:0[1-9]|[13-8][0-9]|2[ab1-9]|9[0-5])(?:[0-9]{3})?|9[78][1-9](?:[0-9]{2})?
The regex can be used for any form of data validation. The set of characters above provide the rules for input verification. You can create your own custom regex with those rules. From ZIP codes to phone numbers, from emails to even definitive texts, the possibilities are endless.
But, to make it simpler, a simple google search can help you find the right regex for your use cases. Few trustable sources are Stackoverflow and Regexlib where people publish and verify various regular expressions.
You can also test the regex you've chosen against your set of inputs on Regex101 which has a comprehensive and exhaustive testing method to test the validity of your regex.
How can I include a Regex in my Joonbot?
Joonbot allows you to include your custom regex in the "Open answer" block.
1. Insert an open answer block where you want to insert your own rules and add the question.
2. When you scroll down, you can find the space for "Regex validation". Enter the custom rules' regex you've created there to validate the user input.
Add a creative fallback text to let the users know if they've entered otherwise.
3. Continue further building your Joonbot!
And voila, you've created your own rules and added them to your Joonbot! Yay! 🎉🎉🎉
Comments
0 comments
Please sign in to leave a comment.