cancel
Showing results for 
Search instead for 
Did you mean: 

Numerical and Alpha Field Validation

Workflow Hero
13 54 10.4K

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 [a-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.

54 Comments
Workflow Hero

The same I use!.

It 'd be great to have on future version a masked control.

Some users/forms need to validate the input on at the same time they are writting the content.

Workflow Hero

I agree

Workflow Hero

I'm using O365 and the "Required" flag is missing under the Validation section for what I think may be any Control that is connected to a field/list column.  Is this by design or a bug?

Not applicable

How do I do it if I want to check on numbers only, but also on "-" special char.

I have social security numbers it need to validate containing on 6 numbers + 4 numbers with a "-" between.

like this 234567-3332

Workflow Hero

^\d{6,6}-\d{4,4}$

Not applicable

Hi Christie Steever

Did you ever have an answer about this?  I have Forms 2010 and have the same issue - the required flag is missing.

Thanks

Karen

Workflow Hero

I need to create regular expression only to accept numeric values , but  can not have the decimal part

Has to be 27489881 and not 27489.881

Workflow Hero

^\d+$

Workflow Hero

not work

Workflow Hero

post screenshot of your setup and example of input that do not work

Workflow Hero

Configuration

I Can save

Workflow Hero

hm, that seems to absolutely correct.

isn't it control disabled?

check developer console for any errors, it may cause validation is not executed.

Workflow Hero

I need to create regular expression only to accept exact 8 numeric values.

With onprem this regular expression works fine, whereas with O365 it did not: \d\d\d\d\d\d\d\d

BTW: it needs to be 12345678 and not 12.345.678

What is the right expression for O365?

Workflow Hero

Try this:

\d{8}

Workflow Hero

Nice. That works! Thanks!

Unfortunately I still have those seperators in: 12.345.678 instead of 12345678

Workflow Hero

Are you saying that 12.345.678 passed that regular expression?

It didn't in my environment.  Weird.

Workflow Hero

In fact if you create a new item it works. When you then try to edit it, it doese not work any longer. Smiley Surprised

Workflow Hero

Hi Michael,

that's really weird. I can't seem to reproduce this.  I think you might need to reach out to Nintex Support on this one, because this is really weird behavior.

Vadim

Workflow Hero

I just switched column data type from "number" to "single line of text". Validation with regular expression \d{8}.

Everything fine now!

Workflow Hero

That's awesome.  Glad it was that easy

Workflow Hero

Thanks for your help!

Workflow Hero

How do i get exactly 9 characters that includes a dot after 6 places. For example: 123456.89

Can be number or string.

Workflow Hero

Just what I was looking  for...

Workflow Hero

Is there a way to validate so that my number cannot start with or end with a zero?

Workflow Hero

Although I haven't tried this in Forms yet, see if this helps:

^(?!0)\d+(?<!0)$

Workflow Hero

I got the Zeros to work...and I have the MAX digits set to 6. How to make the min 6?  I set the MAX to 6 simply using the properties in the SP column field. 

Workflow Hero

I figured out the MAX digits!  A previous thread.  You have to put the validation in Nintex....

Workflow Hero

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

Workflow Hero

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. 

Workflow Hero

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

Workflow Hero

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)
Workflow Hero

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.

Workflow Hero

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) 

Workflow Hero

SOLVED: Final piece 

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

Workflow Hero

Great stuff Michelle!!!

Workflow Hero

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

Workflow Hero

replace square brackets with round brackets

Workflow Hero

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

Workflow Hero

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

Workflow Hero

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

Cheers

Workflow Hero

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

Workflow Hero

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

Workflow Hero

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.

Workflow Hero

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

Workflow Hero

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".

Workflow Hero

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

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

Workflow Hero

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

Workflow Hero

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

Workflow Hero

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.

Workflow Hero

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