cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Form Validation- Single Line Of Text Length Requirement

Jump to solution

I need to crate validation for a single line of text column. The validation required is to count the total number of characters( Text and Numbers) entered amd validate that 7 items were entered.

When someone enters in their ID take  "JN76161" for example I want the column to validate that they entered a total of 7 characters. No more no less.

If we can also validate so that it requires that the first two characters are text that would be awesome too.

Thanks,

Jacob

Reply
9 Replies
Highlighted
Workflow Hero

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Hi Jacob,

for the length check you can use a simple validation rule:

  • Select your text control
  • Click "Add Rule" in the ribbon
  • Configure the rule
    • Name: Whatever you like
    • Ruly Type: Validation
    • Condition: not(equals(length({Self}), 7))  <-- make sure the reference to your field is working properly, so dont just copy/paste

This rule checks how many characters have been entered in the textbox and will only allow to submit the form if 7 characters have been entered.

For the check of the first two letters, you will probably need a little more effort. My idea would be to use a regular expression in javascript (unless there a runtime function for regexs I'm missing?!). Go to the settings of the control and add a javascript variable name so you can reference your field in your javascript code.

Here is a reference for how to implement simple javascript into nintex form: Re: Nintex Forms and JavaScript basics

And here is a reference for using regular expressions in javascript: https://wiki.selfhtml.org/wiki/JavaScript/Objekte/RegExp

And last but not least something usefull to create/test regular expressions: Online regex tester and debugger

Cheers

Philipp

Reply
Workflow Hero

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

using regular expression validation you may ensure both your requirements for length and starting with two (uppercase?) chars by following expression

[A-Z]{2}\d{5}$

Reply
Workflow Hero

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Use regular expression in control settings:

^[A-Z]{2,2}\d{5,5}$

  • ^ assert position at start of the string
  • [A-Z]{2,2} match a single character present in the list below
    • Quantifier: {2,2} Exactly 2 times
    • A-Z a single character in the range between A and Z (case sensitive)
  • \d{5,5} match a digit [0-9]
    • Quantifier: {5,5} Exactly 5 times
  • $ assert position at end of the string
Reply
Not applicable

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Thank you Manfred, your regular expression worked.

Now, associates are allowed to type their ID either uppercase or lowercase. That being said I had to add.....

((^|, )(part1|part2))+$ I added your expression in part1 and part2 only changing the [a-z] to [A-Z].

((^|,)(^[a-z]{2,2}\d{5,5}$|^[A-Z]{2,2}\d{5,5}$))+$

It now accepts.... JN76161 or jn76161, but not JN7616 or jn7616.

Thank you,

Jacob

0 Kudos
Reply
Not applicable

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Phillip,

Thank you for your quick response. Unfortunately I couldn't get your way to work.

I was able to use regular expressions explained by Manfred Lauer below.

Thanks,

Jacob

0 Kudos
Reply
Workflow Hero

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Manfreds suggestion is certainly the better way. I forgot you can use regex directly in the control settings.

Cheers

Philipp

0 Kudos
Reply
Workflow Hero

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

You wanted to match 5 digits. So what You mean by 'but not JN7616 or jn7616'?

To match first 2 characters either lower or upper case use:

^([a-z]{2}|[A-Z]{2})\d{5,5}$

To match first 2 characters mixed case use:

^[a-zA-Z]{2,2}\d{5,5}$

Reply
Not applicable

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Oh sorry, no it works exactly how you sent it to me. I was just going into greater detail for those reading the forum. I simply was clarifying that it works because it fails when I type more than 5 or less than 5.

0 Kudos
Reply
Workflow Hero

Re: Form Validation- Single Line Of Text Length Requirement

Jump to solution

Manfred Lauer

I understand that your suggested reg. requires the exact format...
However, how can I make it so it request the "minimum" and maximum in following format:

minimum: ABCD.12345

maximum: ABCD.12345.12.123

What can go through examples:

ABCD.12345
ABCD.12345.12
ABCD.12345.12.123

0 Kudos
Reply