# Numerical and Alpha Field Validation

Show first post

### 52 replies

Userlevel 7
+11

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

+5

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.

Userlevel 7
+11

^(?!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.

+5

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)
+5

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.

+5

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.

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

+5

SOLVED: Final piece

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

Userlevel 7
+11

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.

Userlevel 5
+14

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

Userlevel 5
+14

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

+4

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

Userlevel 7
+17

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

+4

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.

Userlevel 7
+17

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

+4

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

Userlevel 5
+14

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

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

+4

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

Userlevel 5
+14

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

+5

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.

Userlevel 7
+11

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.

+5

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.

Userlevel 7
+11

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