Expand my Community achievements bar.

Limit the number of digits in a numeric field

Avatar

Level 2

Hi

I have been searching for the last hour to find out ho i can limit the numeric field on my livecycle form. I have seen lots of java script however nothing seems to work, all i want is for the user only to enter 6 digits (e.g. 123456) and if they try to enter more a message would say that only a 6 digit number can be entered.

This is driving me mad for something i though would be quite simple.

Can anybody help?

3 Replies

Avatar

Level 4

I am not 100% on the Javascripting; however in the Object window, Field Section there is an option to put the maximum number of characters in a numeric field. It says "comb of" and then it gives you an option of the maximum number of characters that can be allowed in the field. If you put 6 it will only allow 6 characters. However if that is not something you want you can go to the Value Section within the Object Window and click on the Validation Pattern button. In the Validation tab, in the pattern section type in "999999" and hit apply. It should replace it with "num{999999}" which is 6 numeric values. For a custom error message, in the same Value section, add a custom Validation Pattern Message (make sure to check the error box") and then save your file. If someone tries to put more than 6 values in it should pop up with your custom message. I do find it is easier for the user to understand if you use the comb function instead of the validation pattern. It is a lot more clear to the user on what you need. Just my personal opinion though.

Avatar

Level 10

There's a couple of ways of doing it.

You can use a text field with a character limit and regular expressions to limit the field to numbers.

//on the Change event

if (xfa.event.newText.match(/[^0-9]/)) {

xfa.event.change = "";

}

Or you can script to find the length of the numeric field and stop data entering after the length has been reached.

//on the Change event

if (xfa.event.newText.length > 6) {

     xfa.event.change = "";

}


Avatar

Level 3

This is years late... but Thank you Jono!

the latter script worked perfectly!!

Just to clarify for others... there's no need to change the code or your object name. just copy and paste.

I was changing the "newText" thinking it was a name reference.

Thanks again!