These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Limit value for text field

Wesley_A
Registered: Mar 6 2008
Posts: 5

Hi,

Is there a way to limit maximum value user can type into text field using java script in Adobe Acrobat 8.1?

For example how can I format and validate text field to only accept values in range from 1 to 22?

Any help will be appreciated.

Thank you

My Product Information:
Acrobat Pro 8.1.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
In Acrobat 8 Professional, look at the "Validation" tab for the field.

George Kaiser

Wesley_A
Registered: Mar 6 2008
Posts: 5
Thank you for your assistance.

Would you please provide short validation script? I would like to provide dialog box if the number entered is outside the range.

Thank you.
MrFlow
Registered: Sep 7 2006
Posts: 13
Limit length of field to 2. Add a Validation Script Message on the Value tab. Type in the following code into the validate event of the field:

this.isNull || (!isNaN(this.rawValue) && this.rawValue > 0 && this.rawValue < 23)Ciao
Jens
MrFlow
Registered: Sep 7 2006
Posts: 13
In the solution above you can type in values like "1." or ".3". A more secure solution is:

Limit length of field to 2. Add a Script Object called FormScript. Copy the function:

function isValid(text, field_name)
{
var returnWert;
var thisRegExp = new RegExp();

returnWert = true;

//set regular expression
thisRegExp.compile("^[0-9]{0,2}$","i");

if ((text != null) && ((thisRegExp.test(text) == false) || (text < 1 || text > 22)))
{
xfa.host.messageBox("Field invalid!", "Exception", 0);
xfa.resolveNode(field_name).rawValue = null;
xfa.host.setFocus(field_name);
returnWert = false;
}

return returnWert;
}

Now call the function from the validate event of the field
FormScript.isValid(this.rawValue, this.somExpression);

Ciao
Jens