Skip to main content

Regular expressions

info

Before you write your own regular expressions, you can check our column types. They contain among others pre-built regex validations and cover the most common use cases, so you do not have to write one or multiple regex yourself.

General

If you want to add additional validations to your target column apart from unique and required you can use regular expressions (regex) within the nuvo pipelines. Set the validate property of a validation object to regex and insert your JSON-escaped regular expression as a string into the regex object's property. You can also customize the error message by specifying a value for the errorMessage property. The default error message is "Invalid format". For learning more about regular expressions, building and testing them, we recommend using RegExr.

info

When using regex within the pipelines, there are some essential differences from its use in standard Javascript: (1) The regex needs to be JSON-escaped, meaning specific characters such as " or \ have to be converted to \" or \\. To learn more about JSON escaping or converting your string correctly, you can use Code Beautify. (2) You need to provide the regex as a string. For example the regex ^[0-9]{1,3}$ needs to be inserted into the nuvo pipelines as "^[0-9]{1,3}$". Please note that regex flags cannot be used within your regex string inside the nuvo pipelines.

Examples

Regex for e-mail address format

If you want to ensure that the user is only uploading values in the correct e-mail address format, you can copy the following code snippet. Every cell containing a value that does not fit the e-mail address format is displayed as an error and is therefore highlighted in red.

columns: [
{
label: "E-Mail Address",
key: "email_address",
validations: [
{
validate: "regex",
regex: "^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|'(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*')@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$",
errorMessage: "The input is invalid. Please enter a valid email address, e.g. [email protected]."
}
]
}
]

Regex for DMY date format

In the following, you can find an example of using regex within the nuvo pipelines to ensure that the user-submitted values of the column registration date have the DMY date format:

columns: [
{
label: "Registration Date",
key: "registration_date",
validations: [
{
validate: "regex",
regex: "^(?:(?:31(\\.)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)(\\.)(?:0?[13-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29(\\.)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\\d|2[0-8])(\\.)(?:(?:0[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{4})$",
errorMessage: "The input is invalid. Please enter a date in the following format: mm.dd.yyyy, e.g. 12.31.2022",
},
],
},
];