Formtext custom validation

I'm trying to use the built-in validation I'd like to test for a14-digit number, but can't seem to get it to work.

Original snippet using {if} to test:

{formtext: name=Unit GTIN; default=123457890}{if: testregex(`Unit GTIN`,"\d{14}")="no"}{error: requires 14-digit number; block=yes; type=warning}{endif}

Using built-in validation:

{formtext: name=Unit GTIN; default=1234567890; validate=[["regex": "\\d{14}", "message": "requires 14-digit number"]]}

I've tried several different combos of the RegEx with no success.

That looks pretty good. What you want though is probably this:

^\d{14}$

The "^" matches the start of the field, and the "$" matches the end of the field.

Yours (\d{14}) said to match anything that includes a 14 digit number. Mine would say to match only things that include exactly 14 digits and nothing else.

Note you will need to actually use the snippet to see this in action. The validation warning will only come up when you try to insert a form snippet. It won't show in the preview or the community. You will need to insert the snippet to have the validation trigger.

Thanks Scott!

I didn't realize that the validation only kicked in when inserting the snippet.

It's nice to have the indicator prior to inserting the snippet like in the if statements. Any chance of achieving the same behaviour in a future update?

It's possible we could add something like that in the future. It's not currently planned, though.

If you want full control over the error display, {if} and {error} commands are the way to go.