How to validate lead's input using regular expressions

A regular expression (shortened as regex), is a string of text that allows you to create patterns that help match, locate, and manage text.
With Continually you can add conditional logic and set rules for your customers to match. You can choose a field, then set the criteria you want your customers to match for that field. 

Sometimes you want the user's input to follow a strict format, but it won't be logical to enter all the possible combinations for the user's input to check against them. That's where regular expressions come in handy. It allows you to validate the user's input against certain patterns. Also, using regular expressions with conditional logic allows you to change the conversation's path depending on the user's input.

Find out more about Conditional Logic here.

How to use Regular Expressions with Conditional Logic

The first step is to add the question you want to validate its answer, make sure to save the answer to a custom field.

After the question step add a Conditional Logic object to the bot and connect it. Pick the field you saved the answer to and set the condition to Regular Expression. 

Add the required regex rule and save. Now the conditional logic will give you two path : True and False, the conversation will follow the True path when the value of that field matches the regex, if not it will follow the False path.

Let's take a practical example to explain this to you. Let's say we want the lead to enter their phone number in the US patten eg. (555) 555-1234, or similar patterns that looks the same but have different small changes, like the position of the space or the hyphen or the brackets.

Add the phone question and save its value to a custom field, we will call us usphone. Add a conditional logic to it and set the regular expression. The regex rule for the US pattern is :

\(?\d{3}\)?-? *\d{3}-? *-?\d{4}<br>
	
This will validate a lot of of patterns that leads enter their phone number like: 3087774825 or (281)388-0388 or (281)388-0300 or (979) 778-0978 or (281)934-2479 or (281)934-2447 or (979)826-3273 or (979)826-3255.

Connect the True path to the next object when the phone is formatted correctly, if  it is not then add a text to tell the user to enter their phone number in a correct US format.

And that's it! Let's test it now in the preview!

Examples of Regular Expressions rules

There are numerous regular expressions that you can use to validate the answers, you can even create your own rules. RegEx is a flexible language that you can adapt to your needs, you can use google to learn more about it and find more examples that you can use.
Here is a list of useful web pages that list useful regex rules:

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.