Table of Contents

Using Regular Expressions (Regex) With Your App

Danielle Kellogg Updated by Danielle Kellogg

What are Regular Expressions?

Regular Expressions, also called Regex, are strings of characters that allow you to define specific search patterns.

Using Regular Expressions with Your App

Regular expressions can be used within validation rules and text formulas to perform many functions. For more information on using Regex within your Knack app, take a look at the following articles:

Getting Help With Regular Expressions

Regex falls outside the scope of our support. This means that we’re unable to help further with setup or troubleshooting. Additionally, with a code-based solution, we can’t guarantee its functionality or full compatibility with Knack.

While we can’t help further, there are many resources that can point you in the right direction:

  • You can ask for help in our community of other Knack users.
  • You can learn about, write, and test regex at https://regex101.com/. Use the ECMAScript/Javascript option.
  • Rubular is a helpful regex editor to test regular expressions as you write them.
  • Share your question in external developer communities such as Stack Overflow.

Regular Expression FAQ

Can I prevent users from submitting blank or only spaces on form fields?

Yes, you can prevent whitespace characters from being submitted in fields using regular expressions (regex) in field validation rules

To do this, you'll need to create a validation rule in the field(s) involved. This should look like when [field] does not match regular expression ^(?=.*\S).+$ followed by your error message.

Can I extract the username from an email address?

Yes, you can use the extractRegex function in a Text Formula field to extract the username before the @ in an email address using the following:

extractRegex({Email_Field},([^@]+) 

Yes, you can validate a user-entered URL in a link field type by using two fields for the validation: 

  • A short text field type where the user enters the value, which has a robust validation rule using regex.
  • A link field type that will be used to allow the URL to be clicked and accessed.

So you'll have 2 fields:

The Short Text field where the user inputs the URL value will contain a regex validation rule that looks like this:

^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$

You may need to tweak the regex for your purposes. This is not a specific recommendation. 

Next, you'll apply a conditional rule to the Link field to set it's value using the URL captured in the Short Text field. The Link field is needed if you want users to be able to click to access the URL:

How did we do?

Integrate with Make (formerly Integromat)

Integrate with Zapier

Contact