cancel
Showing results for 
Search instead for 
Did you mean: 

Numerical and Alpha Field Validation

Nintex Employee
Nintex Employee
13 54 18.7K

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
fhunth
Nintex Newbie

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.

Nintex Employee
Nintex Employee

I agree

steeverca
Nintex Newbie

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

Automation Master
Automation Master

^\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

jose_fidalgo
Nintex Newbie

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

Automation Master
Automation Master

^\d+$

jose_fidalgo
Nintex Newbie

not work

Automation Master
Automation Master

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

jose_fidalgo
Nintex Newbie

Configuration

I Can save

Automation Master
Automation Master

hm, that seems to absolutely correct.

isn't it control disabled?

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

mai-kel
Nintex Newbie

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?

Nintex Employee
Nintex Employee

Try this:

\d{8}

mai-kel
Nintex Newbie

Nice. That works! Thanks!

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

Nintex Employee
Nintex Employee

Are you saying that 12.345.678 passed that regular expression?

It didn't in my environment.  Weird.

mai-kel
Nintex Newbie

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

Nintex Employee
Nintex Employee

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

mai-kel
Nintex Newbie

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

Everything fine now!

Nintex Employee
Nintex Employee

That's awesome.  Glad it was that easy

mai-kel
Nintex Newbie

Thanks for your help!

bhashwar_bhatta
Nintex Newbie

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

Can be number or string.

chelledavis11
Nintex Newbie

Just what I was looking  for...

chelledavis11
Nintex Newbie

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

Nintex Employee
Nintex Employee

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

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

chelledavis11
Nintex Newbie

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. 

chelledavis11
Nintex Newbie

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

Nintex Employee
Nintex Employee

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

chelledavis11
Nintex Newbie

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. 

Nintex Employee
Nintex Employee

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

chelledavis11
Nintex Newbie

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)
chelledavis11
Nintex Newbie

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.

chelledavis11
Nintex Newbie

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) 

chelledavis11
Nintex Newbie

SOLVED: Final piece 

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

Nintex Employee
Nintex Employee

Great stuff Michelle!!!

iaindreas
Nintex Newbie

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

Automation Master
Automation Master

replace square brackets with round brackets

iaindreas
Nintex Newbie

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

Automation Master
Automation Master

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

iaindreas
Nintex Newbie

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

Cheers

ohagas
Nintex Newbie

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

Automation Master
Automation Master

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

ohagas
Nintex Newbie

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.

Automation Master
Automation Master

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

ohagas
Nintex Newbie

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

Automation Master
Automation Master

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

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

ohagas
Nintex Newbie

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

Automation Master
Automation Master

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

cherylshah
Nintex Newbie

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.

Nintex Employee
Nintex Employee

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