Skip to main content

I was wondering if there was an easy way to create a validation rule to not allow spaces in a single line of text field. I am using a New responsive form and need to prevent users from including spaces in this particular field.

Hi JosePC. Good question!

This is what I normally do (maybe it can be done better but this works for sure. I am not a Regular Expression Wizard so I prefer to skip that).

First I define text field in my form:

Plain short text field. No settings changed

then I create a variable in the form:

it replaces the spaces in my text with just another character.

Then I create a SUBMIT rule that checks these two against one another. When different there must have been spaces.

 

Then I test it in preview. Enter a value with spaces and click Submit:

Hope this helps.

PS. If you would only allow e.g. letters, numbers, spaces, hyphens and underscores (as for filenames) you might be all right with something like this in the settings of the form variable:

 


You can do that by configuring Input Validation with a regular expression. Below are the steps:

1. Go to the configuration for the Text - Short field.
2.. Configure the Input Validation.

  • Input validation = Regular expression
  • Pattern = /s
  • Custom Regular expression message = Whatever you would like

This will trigger this validation in the filed if a user enters a space in the text. They will see the message and not be able to submit the form until correcting.

 


Hi @JosePC 

One method is to simply replace “ “ spaces with “” blank using Form Rules. Rule activates when the field lose focus. 

The Form Rules

Formula

 


Thank you very much for responding. I have tested all three and they work flawlessly. 


Reply