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

FormCalc script to ensure field is a number

Q-ball
Registered: Jan 25 2011
Posts: 4

I have a time entry field where I have set my display pattern and edit pattern correctly to solve most cases of time that are entered. This along with the following exit code (with the help from radzmar):
 
if (Len($) == 3 or Len($) == 1) then
$ = Concat(0, $)
elseif (Len($) == 2 and $ >= 24) then
$ = null
endif
 
I can solve all of these types of entries: 623, 0623, 6:23, and 6. However, if someone decides to enter 6:23AM, my summation script can still solve it but the calculation is wrong. What code can I place in the above if statement that ensures the field has numeric values only (along with the colon)? Would this be a good opportunity for a regular expression? If so, how?

My Product Information:
LiveCycle Designer, Windows
DaveyB
Registered: Dec 10 2010
Posts: 70
You can actually do this with the "object > value > field validation" property, where you can set the required inputs for the field and even create custom error messages to display in order to guide the user into entering the desired format.An alternate methodology would be to read the substring (javascript INSTR()) for the presence of [AM, am, a.m.] and the PM variants, and add (or not) 12 hours based on the result.

I have to admit, I had an easier time with this particular problem in my own projects since all of my users are accustomed to using military time, so I simply made the input field numeric only, and changed the display to automatically provide the colon.

Hope that helps!

DaveyB

LiveCycle Designer 8.0
"Genius is one percent inspiration, ninety-nine percent perspiration." ~~ Thomas Edison
"If at first you don't succeed, get a bigger hammer." ~~ Alan Lewis
"If the conventional doesn't work, try the unconventional" ~~ DaveyB