How to validate the user input in entity node

I have built a flow where the bot collects user input in an entity node. The value from the entity node needs to be passed as the request body to a service node. The user input may contain invalid values such as ‘sfsrwsrg’, ‘sdfad342342’, ‘252342’, or ‘*(%^$&#%’, which should be validated before passing to the service node. How I can achieve this using the entity node or script?

Akash,
There multiple ways to validate an entity input, so the best method will depend on the format of the valid input value. I typically solve this challenge in one of two ways: use the custom entity type or use an script node after the entity collection.

The easiest way to validate (IMHO) is to use the custom entity type.


You can create a REGEX expression to check the format of the input. If the input does not match the pattern, the node will prompt the user to enter a valid value.

If the entity input value needs to be manipulated before validation, use a script node after the entity collection. Common use cases for a script node are to delete spaces (very common with voice channel entries), to remove (or add) special characters or to change capitalization (case). This method is slightly more complicated because if the input is not valid, you must clear the entity value, provide an error message and loop back to the entity node to recapture a valid entry. Something like this:

I hope this helps. Good luck!

1 Like