Table of Contents

Formulas - Regex

Sofia Teran Updated by Sofia Teran

If is your first time with Formulas, please check our Getting Started guide here and our crash course here

Formulas available

  • RegexText

RegexTest

Check for numbers of 11 digits

In a case where you want to validate that the input from a user are 11 digits, what we need to do is store in Landbot variable (in this example we call it @code_number), then use the Formula block:

RegexTest(/^\d{11}$/,@code_number)

Note that we want to validate if is TRUE or FALSE, that the number matches our pattern, so we will set up the Block Outputs as TRUE/FALSE

You'll be able to set in the builder bot:

  • The True output (green arrow) to confirm the user that the number is in the correct format and with the correct number of digits.
  • The False output (red arrow) to send a message explaining that it's incorrect and connect this message with the text block to start the flow again (asking for the number).Β 

Check if the input is a valid UK postal code
RegexTest(/([A-PR-UWYZ][A-HK-Y0-9](?:[A-HJKS-UW0-9][ABEHMNPRV-Y0-9]?)?\s*[0-9][ABD-HJLNP-UW-Z]{2}|GIR\s*0AA)/,@text)

Check if the input contains a word that is "stop" or something that starts with "stop"

RegexTest(/^stop.*/,@text)

Check if the input time input is in format HH:mm:ss

In this example, in the variable @text we are storing the time by the user

RegexTest(/(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)/,@text)

Check if the input time input is in format yyyy-mm-dd

In this example, in the variable @date we are storing the date by the user

RegexTest(/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/,@date)

How did we do?

Formulas - Math

Formulas - String

Contact