Validating Date Fields

How can I validate input?

For instance, how can I determine if an email address, zip code or phone number is valid? Correct number of characters, correct characters, etc.

For instance an email needs to be alphanumeric@alpahnumeric.alphanumeric.

Thanks!

You have two options here. The easiest and recommended way to do this is to use a custom code function. This will provide the most flexibility in terms of validation, and given how many examples of validation exist in the wild, these are very easy functions for LLMs to help you write if you don’t want to dig into the code manually.

The simplest example, if your user input variable is named zipCode and you wanted to make sure it was five digits, would be something like:

if (ai.vars.zipCode.length !== 5) {
   throw new Error('Zip Code is invalid');
}

You could also use a logic block, if you do not want to write code and are okay with things potentially not being 100% accurate, depending on the model and input. You could use a logic block with the context: The user's zip code is {{zipCode}} and two cases: 1: The zip code is a valid 5 digit zip code, 2: The zip code is invalid or malformed. However be aware that depending on the type of validation you need, the LLMs may or may not do a good job of performing it. For example, an LLM could easily validate "{{jobTitle}}" is a job title and not gibberish, but might struggle with something like "{{value}}" is larger than 2 million.