Category Archives: Regular Expressions

Validate a Single Email Address Field in a Nintex Form

I recently built a Nintex Form that included a field where the user was asked to fill in their email address. The form needed to verify that the user was entering a valid email address.

This can be accomplished using a Regular Expression in the settings of the form control.  Below are the steps and Regular Expressions I used for validation the email address entered.

  1. Add a Single Line Textbox control to the form.
  2. Open the Control Settings and expand the Validation section.
  3. Change the “Use a regular expression” choice to Yes.
  4. Enter the one of the regular expressions below in the “Regular expression” field.
  5. Enter your custom validation message in the “Regular expression error message” field (for example, “Please enter a valid email address”).
  6. Save and publish the form.

Below is the main regular expression I have used to validate an email address on a form.

(?:[A-Za-z0-9!#$%&’*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&’*+/=?^_`{|}~-]+)*|”(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*”)@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[A-Za-z0-9-]*[A-Za-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

I have also used the regular expression below to validate an email address.  It’s much simpler but does not check as extensively for certain patterns.  It does check for a 2-4 domain extension after the period.

^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4};?)+$

Nintex Forms - Single Email Validation


Kudos to Eric Harris for first sharing this in his post on the Nintex Xchange site: Simple email validation for forms

Get a Parameter within a URL Using a Regular Expression in Nintex Workflow

Recently had a need to extract a parameter from within a URL string using Nintex Workflow.  Specifically, I needed to get the ID parameter from a URL.  In the example URL below, I needed to extract the number 987:

//mysite/mypage.aspx?ID=987&User=654

Follow these steps to get the ID number:

  1. Open the Nintex Workflow designer and add a Regular Expression action.
  2. Configure the Regular Expression action with the following settings:
    • Pattern =  (?<=ID=)[^&]+
    • Operation = Extract
    • Input Text = String, Inserted Reference or Workflow Variable
    • Store Result In = Collection workflow variable
    • Note: Your can use the “Run Now” option in the ribbon to test out the action.
  3. Next add a Collection Operation Action with the following settings:
    • Target Collection = Collection workflow variable
    • Operation = Get
    • Index = Integer workflow variable (with “Default value” = 0)
    • Store Result In = Text workflow variable
  4. The value (987 in the example) is stored in the Text workflow variable and can be used else where within your workflow.

Nintex Workflow Regular Expression - Extract Parameter from URL

Nintex Workflow Collection Operation - Extract Parameter from URL

Remove Line Breaks in Text Using a Regular Expression in Nintex Workflow

You can remove line breaks in a text string using the Regular Expression action in Nintex Workflow.

Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. Pattern = [\r\n]
    2. Replacement text = Keep this empty (or use a replacement character)
    3. Input text = Insert your text string (you can insert a reference to data in a list column or workflow variable)
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

RegExRemoveLineBreaks

Get Digits Before a Decimal Point Using a Regular Expression in Nintex Workflow

Using the Regular Expression action in Nintex Workflow, you can get the digits before a decimal point.

Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. String = Your number from a column or workflow variable.
    2. String Operation = Replace
    3. Pattern = \.[0-9]+
    4. Replacement String = Keep this empty
    5. Output = Text workflow vatiable
  3. You can then use the workflow variable as you need it.

Here are some examples from using this Regular Expression:

String Regular Expresssion Result
6.5 \.[0-9]+ 6
1234.5678 \.[0-9]+ 1234
1234567.89 \.[0-9]+ 1234567

 

Regular Expression to Get All Characters After a Specific Character in Nintex Workflow

You can get all the characters after a specific character in a string using Nintex Workflow.

Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. Pattern = (^.*?(?=-)-)  where the “-” is the character (replace both “-” with your desired character)
    2. Replacement text = Keep this empty
    3. Input text = Insert your text string (you can insert a reference to data in a list column or workflow variable)
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

Here are some examples from using this Regular Expression:

String Regular Expresssion Result
abc123-xyz456 (^.*?(?=-)-) xyz456
abc123;xyz456 (^.*?(?=;);) xyz456
abc123?xyz456 (^.*?(?=[?])[?]) xyz456

Remove a Forward Slash at the End of a URL String in Nintex Workflow

I recently had a need to remove a forward slash (“/”) from the end of a URL text string using Nintex Workflow.  Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. Pattern = /[^/]*$
    2. Replacement text = Keep this empty
    3. Input text = Insert your URL text string
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

Remove Spaces from Text Strings with Nintex Workflow

You can easily remove all spaces in text strings in Nintex Workflows. Follow these steps:

  1. Insert a Regular Expression action into the workflow.
  2. Configure it with the following settings:
    1. Pattern = \s
    2. Replacement text = Keep this empty
    3. Input text = Insert your text string
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

Error Creating an Item with a Person/Group Field in Nintex Workflow

Ran across an issue with a Nintex Workflow 2013 when using the “Create an item” action. The workflow runs when a list item is created and creates a document set in another list with metadata from the original item. One of the fields in the original item is a Person/Group field, which the workflow action uses as a field to bring over when creating the document set.

The workflow failed to create the item and gave the following error message:

Failed to create item. Invalid data has been used to update the list item. The field you are trying to update may be read only.

Resolution:

This issue seems to occur when using the “Create an item”, “Set field value” and “Update an item” actions.

Since the site uses forms based authentication, the value of the original Person/Group stored in a workflow comes over as:

i:0#.w|domain\username

Here are the steps I used to resolve this issue:

  1. Used a Regular Expression action to strip out the characters before the domain and stored the result in a workflow variable (UserNameOnly).
    • Pattern = i:0#.w[|]
    • Operation = Replace text
    • Replacement text = Leave empty
    • InputText = Original Person/Group field
    • Store result in = UserNameOnly
  2. Configured a Build String action to reformat the UserNameOnly variable to prepend it with -1;# and store it in the same variable.
    • Text = -1;#UserNameOnly
    • Store result in = UserNameOnly
  3. The resulting value from Step 2 of UserNameOnly is now -1;#domain\username.
  4. Reconfigured the “Create an item” action in the workflow to use the UserNameOnly workflow variable to update the Person/Group field of the new item.

Number Rounding Using Nintex Workflow (Part 2)

In my previous post titled “Number Rounding Using Nintex Workflow (Part 1)“, I discussed how to round a number using Nintex Workflow.

Well, it turns out that this approach only works for numbers less than 1,000. When you run the previous workflow I mentioned on a number greater than or equal to 1,000, you get the following error message in the “Convert value” step:

Error parsing value. Value ‘fn-Round(12,345.6789)’ is not compatible with the selected output variable type Number (double).

The issue seems to revolve around the commas in the number.

Resolution:
In order to remedy this issue, I had to modify the workflow to include these steps:

  1. Add a “Set a condition” action to check if the number is greater than or equal to 1,000.
    • If the number is less than 1,000, you can go to Step 2 below.
    • If the number is greater than or equal to 1,000, then follow Steps 3-6 below.
  2. Configure the “Build string” action to use the fn-Round Inline Function and store the result in a text workflow variable (i.e. wfvRoundedNumberText). Go to Step 7 next.
  3. Create a new text workflow variable to store the rounded number with commas (i.e. wfvConvertNumber).
  4. Configure the “Build string” action to use the fn-Round Inline Function and store the result in wfvConvertNumber. Go to Step 5 next.
  5. Use a “Regular expression” action to remove the commas in the text workflow variable from Step 2. Configure the action with these settings (then go to Step 6):
    • Pattern = ,
    • Operation = “Replace text”
    • Leave “Replacement text” empty
    • Input text = wfvConvertNumber
    • Store result in = wfvConvertNumber
  6. Use the “Set variable” action to set wfvRoundedNumberText = wfvConvertNumber.
  7. Configure a “Convert value” action to convert the wfvRoundedNumberText variable back to a number store in the Number workflow variable.

You can then use the Number workflow variable in the remainder of your workflow.

Here’s what the workflow should look like:
Nintex Workfow Number Rounding