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

Help Please-Validate User Input is Specific Number

Diverdown
Registered: Jan 19 2011
Posts: 5
Answered

I have a fillable form where users can input a single digit numeric value that corresponds to an event. I need to verify that the number the user has input is valid. If not window needs to pop up that states Input value is not correct and then provide example of valid choices. If numbers were sequential this would be easy but they are not.
 
Valid user input values would be 0,1,4 or 7.
 
Can someone please provide script that would validate user input using values provided above?

My Product Information:
Acrobat Pro 9.0, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
if (event.value==0 || event.value==1 || event.value==4 || event.value==7) {
// all is well
} else {
app.alert("Invalid value.");
event.rc = false; // prevent the user from entering this value
}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Diverdown
Registered: Jan 19 2011
Posts: 5
try67, thanks for the help. It worked perfectly. I had been attempting to do same with if else statements and could not get syntax correct. This is much easier. Is there a guide somewhere that can provide a list of commands and their function for future reference?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You could also use the not operator and the and operator:

if (event.value != 0 & event.value != 1 & event.value != 4 & event.value != 7) {
app.alert("Invalid value.");
event.rc = false; // prevent the user from entering this value
}

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
I like this tutorial: http://www.w3schools.com/js/default.asp

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

lmontee
Registered: Jul 21 2011
Posts: 9
Hello All,
I found this post which is accomplishing something like I'm trying to do.
I have multiple if statements for a user filled textfield, which then populates two fields.

if (xfa.event.newText.toUpperCase() == "00")

{TextField_1.rawValue = "Value1"

{TextField_Left.rawValue = "00"
}
}

if (xfa.event.newText.toUpperCase() == "01")

{TextField_1.rawValue = "Value2"

I have if statements from a value of "00" through "99". We don't use "21" for instance. I have maybe 30 instances of numbers we don't use. Is there a way, app.alert or something similar, that would display a message
"Not Applicable" for any user input that I haven't made an if statement for, or do I have to list them indidually as shown here? Preferably, I would like to display "Not Applicable" in Textfield1.

Thanks in advance
Larry Montee

{TextField_Left.rawValue = "01"
}
}

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
I would look at using the switch statement. Evaluates an expression, matching the expression's value to a case label, and executes statements associated with that case. Anything unprocessed gets the 'default' processing block of code.switch((xfa.event.newText.toUpperCase()) {
case "00":
TextField_1.rawValue = "Value1"
TextField_Left.rawValue = "00"
break; // end 00
case "01":
TextField_1.rawValue = "Value2"
TextField_Left.rawValue = "01"
break; // end 01
// all other case values for newText to be processed
case "99":
TextField_1.rawValue = "Value100"
TextField_Left.rawValue = "98"
break; // end 99

default:
// any values not already processed end up here
xfa.host.messageBox(Concat("Uknown newText value: ",xfa.event.newText), "Unknown Value", 1, 0)
TextField_1.rawValue = "Not Applicable"
break; // end all others values not porcessed
} // end switch

George Kaiser

lmontee
Registered: Jul 21 2011
Posts: 9
Thanks for your help George,

I neglected to mention that the textfield this is in has an autotab command first and this is most likely
causing this not to work. Most likely a syntax error on my part, ( I'm very new at this and unexperienced.)
Here is my actual code with your suggestion entered:

Thanks again for your help. Note I'm using LiveCycle ES2 if that makes a difference?

form1.#subform[0].TextField_GG::change - (JavaScript, client)



var temp = xfa.event.newText;

if (temp.length == 2){

xfa.host.setFocus("TextField_H")

}


switch((xfa.event.newText.toUpperCase()) {

case "00":
TextField_Pumper_Outlets.rawValue = "4 Inch NST Thread"
GG_Left.rawValue = "00"
break; // end 00

case "01":
TextField_Pumper_Outlets.rawValue = "4.5 Inch NST Thread"
GG_Left.rawValue = "01"
break; // end 01

default:
// any values not already processed end up here
xfa.host.messageBox(Concat("Uknown newText value: ",xfa.event.newText), "Unknown Value", 1, 0)
TextField_Pumper_Outlets.rawValue = "Not Applicable"
break; // end all others values not porcessed
} // end switch