PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/
__________________________________________________________________
Mark,
I just worked on a time sheet form that allows the user to enter "in"
and "out" times in military-time or 12-hour-time format. I realize that
what I did is at least slightly different from what you want to do, but
maybe some of this code will be applicable.
I used the following routine as the "Custom Keystroke Script" to
validate the characters as entered:
function TimeChar()
{
// This function allow only valid characters for only valid characters
for Time-In and Time-Out (numeric, period, colon, P, p, A, a, M, or m).
(46, 58, 65, 77, 80, 97, 109, 112)
// If Acrobat version 4 or later
if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0)
// If keystroke is not Backspace, Enter, Tab, Home, End, Delete,
etc.
if (event.change.charCodeAt(0) > 13)
{
// If keystroke is valid
if ((event.change.charCodeAt(0) >= 48 &&
event.change.charCodeAt(0) <= 57) || event.change.charCodeAt(0) == 46 ||
event.change.charCodeAt(0) == 58 || event.change.charCodeAt(0) == 65 ||
event.change.charCodeAt(0) == 77 || event.change.charCodeAt(0) == 80 ||
event.change.charCodeAt(0) == 97 || event.change.charCodeAt(0) == 109 ||
event.change.charCodeAt(0) == 112)
// Dummy statement because a statement is
apparently required
var cDummy;
// Else if keystroke is not valid
else
{app.alert("Invalid character: Time In/Out must
be formatted as military or 12-hour time.")
event.rc = false;}
}
}
Here's the logic to call the above function for each time field:
// Allow only valid characters for Time-In and Time-Out (numeric,
period, colon, P, p, A, a, M, or m).
TimeChar();
I used the following routine to validate the final entry for each time
field:
function TimeInOut()
{
// This function validates the entry for Time-In and Time-Out:
// 1. Entry must contain a colon.
// 2. Minutes must be "00", "15", "30", or "45".
// 3. If AM or PM, Hours must be between 1 and 12, else Hours must be
between 0 and 23.
// 4. Entry may not contain both an "A" and a "P".
// Eliminate spaces from the entry.
event.value = Trim (event.value, true, true);
// If the entry is not blank
if (event.value != "")
{
// If Time entry contains no colon (:)
if (event.value.toUpperCase().indexOf(":") < 0)
{app.alert('Invalid Entry: Time entry must contain a
colon (":").')
event.rc = false;}
// If Time entry contains a colon (:)
else
{
// Separate Time into hours and minutes (Time array for
the number before and after the colon).
var aTimeArray = event.value.split(":");
// Time Hours
var nHours = Number (aTimeArray[0]);
// Time Minutes
var nMinutes = parseInt (aTimeArray[1]);
// If 12-hour time (AM or PM)
if (event.value.toUpperCase().indexOf("A") >= 0 ||
event.value.toUpperCase().indexOf("P") >= 0)
{
// If 12-hour-time Hours is not between 1 and 12
if (nHours < 1 || nHours > 12)
{app.alert('Invalid Hours: Hours for
12-hour time must be between "1" and "12".')
event.rc = false;}
}
// If both an "A" and a "P"
if (event.value.toUpperCase().indexOf("A") >= 0
& event.value.toUpperCase().indexOf("P") >= 0)
{app.alert('Invalid Entry: 12-Hour Time
must be either "AM" or "PM".')
event.rc = false;}
// Else if military time (not AM or PM)
else
{
// If military Hours is not between 0 and 23
(Note: "Hours" can't be negative, because "-" is an invalid character
for Time.)
if (nHours > 23)
{app.alert('Invalid Hours: Hours for
military time must be between "00" and "23".')
event.rc = false;}
}
// If "Minutes" entry is not "00", "15", "30", or "45"
if (nMinutes != 0 & nMinutes != 15 & nMinutes != 30 &
nMinutes != 45)
{app.alert('Invalid Minutes: Minutes must be
"00", "15", "30", or "45".')
event.rc = false;}
}
}
}
Here's the logic to call the above function for each time field:
// Validate the entry for Time-In or Time-Out.
TimeInOut();
I'll send you the form itself separately, because everyone won't want to
receive a large PDF document.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Lauterbach.Mark
Sent: Wednesday, January 21, 2004 10:20 AM
To: [EMAIL PROTECTED]
Subject: [PDF-Forms] format time
PDF-Forms is a service provided by PDFzone.com | http://www.pdfzone.com/
__________________________________________________________________
I have a field that I would like to make into a 12hour time field but
not have "am" or "pm" displayed (Acrobat default).
I've tried to write my own custom format script using util.printf,
printd, and printx, but I can't seem to get it to work.
Anybody have any suggestions?
To change your subscription:
http://www.pdfzone.com/discussions/lists-pdfforms.html
To change your subscription:
http://www.pdfzone.com/discussions/lists-pdfforms.html