Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Limit the input in a numeric field

Avatar

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile
_Marechal_Micha
Level 2

11-02-2009

Hello,



I would like limit the user input in a numeric field to 10 character for example, but I want verify this limit dynamically.



It's for that I try to work with the event change. I succeed to do that :



var value= xfa.event.newText;

var nb= value.length;

if(nb>10)

{

xfa.host.messageBox("Limit : 10 figures");

}



I succeed to get the value but I fail to change the value to delete the last input character.



If you have any idea to help me 🙂

However, I don't want use the comb property.



Thanks



Regards,

Michaël

Replies

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

11-02-2009

That method will test each char as it is entered (not very efficient). It might make more sense to run the script on the exit event then test the value that was entered.



//get the field value into a string variable

var strTest = this.rawValue

//test the length of the string

if (strTest.length >= 10){

//tell the user they are only allowed 10 chars

xfa.host.messageBox("Only 10 digits allowed...");

//truncate the string to 10 chars

this.rawValue = strTest.substr(0,9);

}

Avatar

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile
_Marechal_Micha
Level 2

11-02-2009

I thought of this method but I prefer to check every user input, I find it easier for the user.



But if there is no more solution, I will have to take this solution.



Thanks

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

11-02-2009

Then simply substr the value they add beyond 10 in your test (like I did in my example).

Avatar

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile
_Marechal_Micha
Level 2

12-02-2009

Hi,



I'm sorry but I have always the same problem.

I tested the code given by Paul, but I don't understand why but it doesn't work. If I try to show the value of strTest.length, it's 0.



Why the length of the value is 0? and why the code doesn't work with me? 😞



Thanks

Michaël

Avatar

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile

Avatar
Boost 500
Level 10
pguerett
Level 10

Likes

612 likes

Total Posts

7,689 posts

Correct Reply

692 solutions
Top badges earned
Boost 500
Boost 50
Boost 5
Boost 3
Boost 250
View profile
pguerett
Level 10

12-02-2009

send your form to livecycle8@gmail.com and I will take a look. Please include a description of the issue

Avatar

Avatar
Affirm 3
Level 2
JohnBrinkman
Level 2

Likes

0 likes

Total Posts

20 posts

Correct Reply

3 solutions
Top badges earned
Affirm 3
Affirm 1
View profile

Avatar
Affirm 3
Level 2
JohnBrinkman
Level 2

Likes

0 likes

Total Posts

20 posts

Correct Reply

3 solutions
Top badges earned
Affirm 3
Affirm 1
View profile
JohnBrinkman
Level 2

25-02-2009

If you want to swallow all keystrokes after you've reached 10 characters, then clear the xfa.event.change property:



if (xfa.event.newText.length > 10)

xfa.event.change = "";



John Brinkman

http://blogs.adobe.com/formfeed

Avatar

02-03-2009

You could use:



if(xfa.event.newText > 9999999999 || xfa.event.newText < -9999999999) { xfa.event.change = "";}



This will allow the field to fill to 10 characters and then disallow further entries. Is this what you're looking for?



Dave

Avatar

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile

Avatar
Level 2
_Marechal_Micha
Level 2

Likes

0 likes

Total Posts

18 posts

Correct Reply

0 solutions
View profile
_Marechal_Micha
Level 2

03-03-2009

Thank you very much, John and David, for your solutions.

It works very well !!!



Have a good day.



Regards,

Michael