Using Regular Expressions for Input Validation in Bot Flows

I am currently building a flow that requires the customer to enter their ‘Account Number’. Our account numbers are always two letters followed by six digits (e.g., AB123456). I am using the ‘Get User Input’ block, but I am finding that customers are entering all sorts of invalid formats. Is there a way to add a ‘Regular Expression’ (regex) validation directly to the input block in Architect, or do I have to use a complex series of decision blocks to validate the string?

Hey Tak25! I am a data migration engineer and I deal with these ‘Dirty Data’ issues all the time. You can definitely use regex in Architect! You do not put it in the input block itself. Instead, after the input is captured, use a ‘Decision’ block with the IsMatch function. Your expression would be IsMatch(Task.AccountNumber, "^[A-Z]{2}\\d{6}$"). This will return true if the input matches your format. It is much cleaner than using twenty different decision blocks for each character!

I have seen many developers struggle with the regex syntax in Architect. To follow up on San25, remember that Architect uses the .NET regex engine, so you must ‘Escape’ your backslashes with another backslash. That is why San25 used \\d instead of just \d. Also, make sure you are trimming any whitespace from the user’s input before you run the regex, or it will fail if they accidentally hit the space bar!