Text Blaze Feature of the Week #4: Validation (Error command)

Hey Text Blaze community :fire:

It's week 4 of the Text Blaze Feature of the Week series where I post weekly about cool features to showcase all the awesome stuff you can do with Text Blaze :sunglasses:

Text Blaze Feature of the Week #4: Error Command (Validation)

The error command is useful if you want error messages to display within your snippets when certain conditions aren't met.

It's like the note command, but you can also prevent a snippet from being inserted if there are unmet conditions. This can help prevent you from making mistakes while inserting snippets (validating your content).

{note}This is note text{endnote}

{error: this is error text}

error-command

Three things you need to know about the error command:

  1. The error command's block setting makes it to where your snippet cannot be inserted if the conditions are not met (which is useful if you tend to make mistakes while inserting content in your snippets). See example 1

  2. The error command works well with the {if} command, as it can help you show errors if certain parameters are met with in your snippets.

  3. Using regular expressions (regex), you can validate content such as email addresses or phone numbers in your snippets. When combined with the error command, you can show errors when the text submitted doesn't match the conditions you set (such as the basic syntax of an email). See example 3

Bonus: The Formula Reference is very useful if you are looking to utilize regex in your snippets.

Example 1

This example shows how you can use the error command to test conditions set by an if command and form field.

{formtext: name=amount; default=11}

{if: amount>10}{error: amount field can't have a value greater than 10; block=yes}{endif}


Example 2

This example shows how you can use regex paired with the error command to show an error message if the conditions are not met.

{formtext: name=amount}

{if: testregex(amount, "[1]+$")}This is a valid amount{else}{error: numbers only please}{endif}


Example 3

This example shows how you can use the error command and regex to verify whether an actual email was inserted in the form field.

{formtext: name=email; default = email}

{if: testregex(email, "^\w+.?\w+?@\w+.\w+?.?\w+?.?\w+?$")}This is a valid email address{elseif: email==""}{else}{error: use a valid email address; block=yes}{endif}


  1. 0-9 ↩ī¸Ž

2 Likes