Skip to main content
Nintex Community Menu Bar

When building a Nintex Form, you will inevitably be presented with a need for certain fields to have validation rules on them.  It could be a simple rule like the field needs to have data in it.  Or it could be that the field must be between 0 and 10.

 

In this post, we'll be talking about taking the validation to a next level, and we'll be using Regular Expressions to validation fields.  Specifically, the need to have some fields that have numbers and numbers only and others that have alpha characters and no numbers.

 

The example provided in this post will show you on-prem Nintex Forms, but the same functionality will work for Nintex Forms for Office 365.

 

Numbers Only

Firstly, since you probably already have a control on your form for this, I want to point out that we won't be using the Rules engine in Nintex Forms.  Although that is very powerful, there's no way in those rules to do this type of validation.

 

Instead, double click on the control to open the settings of that control.  There, you'll find the Validation section.  Click on it to expand it.

Numerical Validation.png

Notice that I've set the "Use a regular expression" option to Yes.  When you do that, you'll see the next fields become available.

The regular expression being used here is d+.  The d represents a digit and the + tells it that we need 1 or more of the previous token (digit).

 

Then, if the validation is not met, you have the text you can display on the form to let the user know what the issue is.

 

Alpha Only

 

For the alpha validation, it looks similar but the regular expression is a little different.

Alpha Validation.png

In this case, the expression is a-zA-Z]+.  Where the a-zA-Z tells us that we want to went upper or lower case alpha characters and the plus means any number of those in an combination.

 

If you want to add support for spaces, you could update the expression to ha-zA-Z ]+.

 

Conclusion

 

When you run this form, what will it look like if you don't put the right data in the fields?

Preview.png

You can see how the red text tells us what the issue is.  Note: you can also put your mouse over the red fields and it'll show you the same error message but the one that is specific to that field that is invalid.

 

I've attached a form to this post.  This is for On-prem Nintex Forms only.  But the O365 version of Nintex Forms also supports this validation.

Great stuff michelle.  So you put that into the Range Validation part on that control??


No..it did not work.    It did in theory but once I made the corrections (error was correct) it was not able to see the newly inputed information was correct. It just stayed incorrect. 


What about this for a validation regular expression:

^(?!0)d{0,6}(?<!0)$

the {0,6} means that you will need to have zero to 6 digits. zero being the minimum and 6 being the maximum number of digits.

Just modify this as you need it.

Vadim


So here is what I have for now: 

What works: 

  • My data can not have leading 0's
  • It can end with 0's
  • It has a max of 6 (set in SharePoint 2013) 

What does not: 

  • Prevent number set <6 from being saved. 

What I tried: 

  • Putting validation IN SP2013 using LEN (No)
  • Putting validation in Nintex via Rules (No)

Here is what happens when I use a rule. It WILL give the correct error BUT then it will not save once corrected. It just stays in that state. I think the RULE is thinking it must be 6 CHARACTERS vs my must be numeric rule.


the {0,6} means that you will need to have zero to 6 digits. zero being the minimum and 6 being the maximum number of digits.

Just modify this as you need it.

Vadim

**It's 6 as the min & max (only 6 digits accepted) 


SOLVED: Final piece 

Added --> ...|d{6})$ At the end of my string in the Nintex validation and removed the parameter in SharePoint column properties. 


Great stuff Michelle!!!


Hi All,

Hoping for some assistance in writing a rule. I want to write a rule for number combination. The number fields must start with either 5733, 671, 5756 and the length needs to be between 15 and 16 digits. 

My rule is currently written as ^^5733|671|5756]d{15,16}$ but its not working.

Thank you in advance


replace square brackets with round brackets


Hi Marian,

 

I have replaced as per your suggestion and its still not working for me. The rule is currently ^(5733)|(671)|(5756)d{15,16}$.

 

i want the input to be 5733123456789012, or 671234543654231, 5756231247865435. 

 

I need the person filling out the form to start with either of those three combinations followed by their own numbers totaling 15 to 16 digits.

 

Hope that makes sense

 

Thank you


not that way. as I said simply replace brackets.

plus, since you spent 3 or 4 digits for fixed strings you have to lower range for tailing digits


Thank you so much Marian. The above formula worked perfectly.

Cheers


Hi,

I have a field for serial number which requires it to be 7 digits. I have used the following simple formula "d{7}".

This works well, however, some people are simply keying in 0000000 on the form, This is not a valid serial number. What formula should I use to stop this?

Thanks


You could try with something similar:

d

So no leading 0. User can input ex. 1000000

Best regards,

Tomasz Poszytek

e-mail: tomasz@poszytek.eu

tel: +48 603 993 372

www/ blog: https://poszytek.eu

twitter: @TomaszPoszytek


Thanks but a leading zero can still be a valid serial. I simply need to invalidate 7 consecutive zeros ie. '0000000' is invalid. I'm not sure how to do this.


Then maybe add a new calculated field, that will have a calculation: if (control_name = 0000000) then “error” else “”.

Then create a validation rule on your serial number field, that will be invalid if a value in that calculation field equals “error”.

Best regards,

Tomasz Poszytek


Thanks Tomasz. The solution was quite simple actually - I didn't even need the calculated field.

All I needed to do was add a simple validation rule to the field: control is invalid if SerialNumber=="0000000".


Sean O‌, if you're still interested in regex solution, try following pattern

^(?!0{7})d{7}‍$


Hi Marian, thanks very much, this seems a much more elegant approach.

I just did a bit more research on regex and I came up with the following pattern to exclude other variations such as 1234567, 1111111, 2222222, 3333333 etc

^(?!0{7})(?!1{7})(?!2{7})(?!3{7})(?!4{7})(?!5{7})(?!6{7})(?!7{7})(?!8{7})(?!9{7})(?!1234567)d{7}$

It seems to work fine in my testing, but as I'm not experienced in creating complex expressions, I just wanted to check that this is the correct way, or whether there's a better/more simple solution?

Thanks


What are rules which input is valid and which not???


Hi Vadim Tabakman, I've read so many of your articles and blog posts. Thank you for the effort you put into providing so much help!

I have a Nintex form in which the number of digits required depends upon the value selected in a previous named field. Is there any way to reference that field in a regular expression? I've tried all day to do this with various rule conditions and nothing works. Here is the background info, and what I need to do:

ProductType is a choice field with two choices we'll call A and B; multiple selections are not allowed. The field is required. My validation on a single line of text field we'll call ProductNumber needs to be as follows.

If ProductType = A, then ProductNumber must have exactly 4 digits (no alpha; leading zeros are permitted), else ProductNumber digits must be exactly 5 (no alpha; leading zeros are permitted).

Thank you so much for any assistance you or anyone else can provide.


Hey Cheryl,

are you building a Classic form?

What I would probably look at, is building a custom validation function in Javascript.  Then do your Regex in the Javascript.

In JS, you'll be able to read the other field, and then your custom validation function will execute when they try to submit the form.

Vadim


I never expected such a fast response! Thank you!

Unfortunately I don't know how to write JavaScript. I've ended up with a combination solution, using 2 panels each with its own copy of the ProductNumber fields, and formatting rules that hide/show the appropriate panel based on the ProductType choice. Now I have separate fields where I can use /d{4} for the one that has to have 4 and /d{5} for the one that has to have 5, etc.


Are you doing this on-prem or 365?  Classic or Responsive?

Vadim


Reply