Cognito-forms – limit a text field in Cognito Forms to NOT allow alpha characters

cognito-formsdata validation

I have a question on a form that the only answer would be a single number, or a list of numbers. "1" or "1,3,4,17,26", etc. Is it possible to not allow alpha characters in the field. I'm trying to prevent an answer such as "all lines", when the answer should be 1-10 or 1,2,3,4,5,6,7,8,9,10.

Best Answer

We will be releasing support for custom text format validation in Cognito Forms next week. You can track the release of this feature on our Idea Board. This will allow you to simply select a predefined format, like Numeric, enter simple masks, or even use custom regular expressions!

In the meantime, you can set up a Custom Error message on your Text field to display an error when a user enters in an alpha character. You can use the following calculation to do this, you will just need to change 'TextField' to reflect your own field's label.

=TextField.ToLower().IndexOfAny(['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']) > -1