Expand my Community achievements bar.

SOLVED

Setting a Minimum Amount of Characters in a Numeric Field

Avatar

Former Community Member

Hello,

I would like to set a minimum and maximum amount of digits to a numeric field. I have used the following code in the change event (see below) to set the maximum, which is working for me, however I cant seem to set a minimum.

Is it possible to set a minimum, and if so, can someone please help?

var

maxLength = 6;

if(xfa.event.newText.length >maxLength)xfa.event.change = "";

Thank you,


Nik

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here is the updated form..

https://acrobat.com/#d=CHbixTuuKW*X*uFac4c6JQ

Few things I changed..

1) Removed the Validation pattern and Validation script message.

2) I am checking the input in the Change event and Exit event for Registration and ID fields.

My code is checking to have the minimum/ maximum values for both the fields. So user cannot leave the field without entering any input.

If you want to allow the user to leave the field with out entering input, then comment out the else part in Exit event code.

Hope this helps..

Thanks

Srini

View solution in original post

13 Replies

Avatar

Former Community Member

Also, I want to do this without using 'combs' in the object field

Avatar

Level 10

You need to place the following in the exit event of the field..

You can also place a messageBox to the user if you want..

Place it in Exit event.

var minLength = 2;

if(NumericField1.rawValue.toString().length <minLength){

     xfa.host.messageBox("Minimum 2 Numbers are needed");

     xfa.host.setFocus(this);

}

Thanks

Srini

Avatar

Former Community Member

Thank you for your help. I have tried what you suggesting and it is still not working. Would a message come up automatically if the minimum number has not been entered?

Avatar

Level 10

Use the following in Exit event..

var minLength = 2;

if(NumericField1.rawValue.toString().length <minLength){

      xfa.host.messageBox("Minimum 2 Numbers are needed");

     xfa.host.setFocus(this);

}

Thanks

Srini

Avatar

Former Community Member

if the minimum amount has not been entered, when you either hit enter or tab will a error message come up? or will it only give a warning at the end when the user hits validate?

Avatar

Level 10

Try this code in the exit event..If you do not enter any value in the NumericField, you need to directly display the message and set focus to the field.

var minLength = 2;

if(NumericField1.rawValue != null){

     if(NumericField1.rawValue.toString().length <minLength){

          xfa.host.messageBox("Minimum 2 Numbers are needed");

          xfa.host.setFocus(this);

     }

}

else{

     xfa.host.messageBox("Minimum 2 Numbers are needed");

     xfa.host.setFocus(this);

}

Thanks

Srini

Avatar

Former Community Member

Im not sure what I am doing wrong. I am copying exactly what you suggested....

Avatar

Level 10

Can you send the form so I can have a look at it..

Please mention which field on the form is giving the error..

Thanks

Srini

Avatar

Correct answer by
Level 10

Here is the updated form..

https://acrobat.com/#d=CHbixTuuKW*X*uFac4c6JQ

Few things I changed..

1) Removed the Validation pattern and Validation script message.

2) I am checking the input in the Change event and Exit event for Registration and ID fields.

My code is checking to have the minimum/ maximum values for both the fields. So user cannot leave the field without entering any input.

If you want to allow the user to leave the field with out entering input, then comment out the else part in Exit event code.

Hope this helps..

Thanks

Srini

Avatar

Former Community Member

Thankyou very much for your help, i appreciate it.

Avatar

Former Community Member

is it possible to have a minimum and maximum ONLY if a number is entered? i do not want this to be a required field but right now the way it is set up the user has to fill in the field. i would like the user to be able to tab past this field if they dont know the number. is this possible?

Avatar

Level 10

You can try commenting out the else part of the code earlier (which is usually gets executed only when the field is null)..

By commenting that, you are allowing the user leave the field without entering a value in it..

Thanks

Srini

Avatar

Level 1

Ok, what am I doing wrong?  I need to set a minimum amount of characters to be entered in a text field and I keep getting syntax errors when testing it...here is the code I am putting in on the mouseexit click.

var minLength = 2

if(Username.rawValue.toString().length <minLength)

then xfa.host.messageBox("Username must be 2-16 characters in length!”)

else xfa.host.setFocus(this)

endif