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

How to limit numeric field to SPECIFIC numbers

jrd1mra
Registered: Jan 21 2008
Posts: 2
Answered

Hi,
Newbie in Livecycle here.
 
I want to have a numeric field which only accepts specific numbers i.e only numbers 95,96,98,99, and 100 are acceptable input. so anything <95 will give an error or anything >100 will give an error.
 
I can not see how to do it using simple or complex validation patterns.
 
Again, I am a newbie so be gentle

My Product Information:
LiveCycle Designer, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Have you considered using a drop-down list or list box instead?
jonom
Registered: Jan 31 2008
Posts: 133
You can't do it with validation patterns you have to do it with scripting.

As George mentioned, a dropdown list or list box might be easier for what you want.

Here's a quicky script - it's javascript placed on the exit event of the field:

//if the field value is less than 95 or greater than 100
if (this.rawValue < 95 || this.rawValue > 100)
{
//popup a warning
xfa.host.messageBox("Number must be between 95 and 100");

//blank the field
this.rawValue = "";

//put the user back into the field
//you will need to change the name to your field's name
xfa.host.setFocus(NumericField1);
}

pforms
Registered: Nov 17 2009
Posts: 87
Third or fourth option: java script on a change event:

if(!/^[95969899100]?$/.test(xfa.event.newText))
xfa.event.change = "";

the numbers in the bracket are the options - won't allow the entry of any other #
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Just another method you can use.

Put this FormCalc script into the exit:event of the numeric field.
  1. if (Within($, 95, 100) eq 1) then
  2. $ = $
  3. else
  4. xfa.host.messageBox("Please insert a value between 95 and 100")
  5. $ = null
  6. endif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

jrd1mra
Registered: Jan 21 2008
Posts: 2
radzmar - that formcalc function works great, only one thing which I neglected to mention in the initial question. How would I modify that script to also allow null and zero as acceptable?
Thanks
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Accepted Answer
No problem...

  1. if (Within($, 95, 100) eq 1 or $ eq 0 or $ eq null) then
  2. $ = $
  3. else
  4. xfa.host.messageBox("Please insert a value between 95 and 100")
  5. $ = null
  6. endif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

Jamesone
Registered: Jul 31 2011
Posts: 15
Hi can anyone convert the above to work with Acrobat 10.1.?????