Counting Strings with leading zeros - validation


Badge +4

Hi,

 

I have a little problem with Nintex Forms. I Need a Validation on a singleline textfield.

 

Here is my formular:

Length({Self}) != "5"

 

The expected length should be 5.

So here is the problem: I used a textfield. But when the user enters a number with leading zeros (00066) then Nintex Forms reduce it to 66 (only a lenth of two!). Why? I choose TEXTFIELD... Even if I add a prefix then it goes A00066 -> A66

 

Is there any way to fix this?

 

Thank you.

 

Regards

Oliver


9 replies

Badge +4

Hi Dave,

no - still the same Problem...

79242_pastedImage_0.png

Userlevel 7
Badge +11

Hi Dave,

here's a workaround for you.

Open the text field and in the Formatting section, add a Control CSS Class name (eg. nf-TitleField).

Then expand the Validation section, and turn the Custom Validation to "Yes".

For Custom Validation Function name, put in a function name like fnTitleLengthValidation.

Save the settings, now open the Form Settings.

Expand the Custom JavaScript section and add the function below (you may need to rename it and tweak it a little to handle your function name and your class name).  I've highlighted the bits you may need to tweak to work in your environment:

function fnTitleLengthValidation(source, arguments)

{

  var myObj = NWF$('.nf-TitleField');

  if(myObj != null)

  {

    if(myObj.val().length == 5)

      arguments.IsValid=true;

    else

      arguments.IsValid=false;

  }

  else

    arguments.IsValid=false;

}

Hope this helps as a temporary workaround.

cheers,

Vadim

Userlevel 5
Badge +12

You can try something like this too, swap out Title with your control's Named Reference:

length(Title.toString())!=5

Userlevel 7
Badge +11

Hey Mike,

that worked for you?  I need to try that out again, because I couldn't get that to work in my environment, which is why I ended up doing in JS.

cheers,

Vadim

Userlevel 5
Badge +12

Hi Vadim,

You are right, upon testing, the code I posted only works when there are numbers without leading 0000.  Good catch!

Mike

Badge +4

Hi,

thank you for your answers.

I have to do some tests. Today I will have a Workshop and I will be back tomorrow...

A few informations: trim and xxx.toString() aren't working. Still miss the zeros.

Now I have to test the java-solution.

Regards

Oliver

Badge +3

Try using regular expression,

80664_pastedImage_0.png

Badge +4

Hi Rohan,

this works pretty well! Thank you!

And thanks to the other one's too...

Regards

Oliver

Userlevel 7
Badge +11

That's brilliant!!

Reply