Highlighted

Limit the input in a numeric field

_Marechal_Micha

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

Highlighted

pguerett

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);

}
Highlighted

_Marechal_Micha

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
Highlighted

_Marechal_Micha

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
Highlighted
Highlighted

JohnBrinkman

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
Highlighted

Avatar

Guest

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
Highlighted