Skip to main content
Using Regular Expression

You can use reg ex. to require users to input a specific format on a Text question

Ashleigh Alldredge avatar
Written by Ashleigh Alldredge
Updated over a week ago

To require users to input a specific format when filling out a 'Text' question, such as phone number, character limit, or a date within a specific range, you can apply Regular Expression (reg ex) to the question configuration. 

You can apply regex to any 'Text' Global Question, question template, or local question. Simply choose 'Text' as the question type when building a new question.

When configuring the question, whether it be a Phone Number or Birth Year question, you will need to take the following steps:

1. Set 'Input Restrictions' to 'Use Regular Expression'

2. In the 'Expression' field, you can paste in any Reg. Ex of your choice. We recommend utilizing external Reg. Ex libraries to research which format works best for your business scenario. 

For example, if you wish to require your users to use the Phone Number format: ###-###-#### , you can enter the following code:  (\d{3})-(\d{3})-(\d{4})

 *Note This specific phone number format will exclude other cases. This includes leading 1s in toll free numbers (1-800-588-2300), people who have extension numbers without a direct line (214-555-5000 x1351), and international formats (+44 1865 270000).

3. In the 'Error Message' field, enter the message the donor will receive if they do not follow the aforementioned format (ex. Please enter the correct using correct format: ###-###-####)

4. Lastly, the Input Restriction dropdown has 2 options. You can choose to Whitelist this answer format which will require that the text inputted must match the expression code you pasted in. The other option is to Blacklist it which will require that the text inputted does not match the format of the expression code. 

Our question configurator can utilize several reg ex codes that you can find via Google. One common library we like is https://regexr.com/ 

Most Common Cases:

Graduation Year: (19|20)\d{2}
This would cover anything from last century or this one.

Middle Initial: ^[A-Za-z]\.?
This allows for an optional period at the end

EIN: ^\d{2}\-?\d{7}

Website: Visit Stack Overflow for different examples

Preventing Emojis: (\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])

To prevent users from inputting emojis on the question, set the input restriction to Blacklist and paste in the above expression. 

Whether you are looking for an international phone number format, a specific work domain email address format, a character limit, or a date within a specific range, we always recommend testing the question before going live. 

Please reach out to our support team at enterprise-support@givegab.com with any questions!

Did this answer your question?