Validate inputs

Validating inputs and warning the user is an essential part of handing over your template to others users

The scenarios are plural and can quickly fork into multifold if you really want to get nitty gritty with what the users can and can't input.

The important thing here is to understand that the examples given here is only an small fraction of possibilities, and an unspecified number of validations and combinations can be made with this approach. These only serves as inspiration and are suggested to be combined with the Preview only tags for final results.

Character amount

In the event where you want to limit the amount of characters a user can input into a field, that could be in situations where the design gets ruined if they input more, you can use the following logic.

Simple warning

{% assign header_length = article.header_text | size %}

{% if header_length > 15 %}
<span style="color:red;">⚠️{{ article.header_text }}</span>
{% else %}
{{ article.header_text }}
{% endif %}

Remove excess

empty field

Character types

For some inputs you want to control if it's a number that can be inputted, or maybe some symbols or a sequence of specific characters that's present or not present.

Numbers only

Contains a specific wording or character

Last updated