Join the Team Forms community

Updated last month

How to use regular expression pattern to set validation in a text field?

At a glance

The community member has a text field that they are using for email input, and they want to validate that the input ends with their company domain. A community member recommends using JavaScript custom validation instead of regular expressions, as it can be easier to read and understand. The steps provided include dragging a text field onto the form, navigating to the validation tab, and entering JavaScript code to check if the input ends with the company domain. The community member also suggests updating the custom error message to notify the user why the input is invalid.

I have a text field that I'm actually using as a field where respondents input their email. I want to put a validation that checks if the inputted text ends with our company domain. How can this be achieved?

Marked as solution

Hi @Yoradel Ambrad


Using JavaScript Custom Validation

Although this is possible using regular expressions, my recommendation would be to use the "Custom validation" to instead validate the input using some JavaScript. In my personal opinion is JavaScript can be easier to read and understand. Here are the steps you could use:

  1. Drag and drop a textfield in your form

  2. In the components settings navigate to validation tab and go to the "custom validation" section

  3. Here enter the following JavaScript to check the input ends in the correct domain

JavaScript
valid = instance.getValue().endsWith('@companydomain.com')
  1. Under the validation tab it's also a good idea to update the "Custom Error Message" property to display a message to notify the user of why the input is invalid (e.g. please enter an email address from the company domain)


View full solution
E
1 comment

Hi @Yoradel Ambrad


Using JavaScript Custom Validation

Although this is possible using regular expressions, my recommendation would be to use the "Custom validation" to instead validate the input using some JavaScript. In my personal opinion is JavaScript can be easier to read and understand. Here are the steps you could use:

  1. Drag and drop a textfield in your form

  2. In the components settings navigate to validation tab and go to the "custom validation" section

  3. Here enter the following JavaScript to check the input ends in the correct domain

JavaScript
valid = instance.getValue().endsWith('@companydomain.com')
  1. Under the validation tab it's also a good idea to update the "Custom Error Message" property to display a message to notify the user of why the input is invalid (e.g. please enter an email address from the company domain)