Click to See Complete Forum and Search --> : Masking Time Format


Lynkster
07-17-2002, 08:32 AM
I have been stuck on this one for 3 weeks and unable to locate anyone who
can help. I have a time field in an HTML form table. I am having trouble
with illegal time formats. The Database only accepts 00:00 format (Can not
be masked) and the front-end webpage appears as a textbox so I am getting
everything from 3:33 to 3 30 to 330. Can the field be masked in the html
page to military time. Please help!!

Kris Eiben
07-17-2002, 10:29 AM
To do an actual "mask" of the field you'll need to write a Javascript
validation routine that checks the format onblur of the textbox. This
script (below) that checks for all numerics (taken from the Javascript
FAQs at www.irt.org) should get you started -- use onblur instead of
onchange and also check the length and whether the 3rd position has a
colon. If you want to be more accurate, split up the string and check
for 0-23 for first 2 chars, ":" for 3rd, and 0-59 for 4th-5th chars.

Or, if you can manipulate the data server-side before it is sent to the
database, check it there and reformat as necessary.

BTW you might also want to include an example of correct military time
format within the form itself.
<script language="JavaScript"><!--
function validate(string) {
if (!string) return false;
var Chars = "0123456789";

for (var i = 0; i < string.length; i++) {
if (Chars.indexOf(string.charAt(i)) == -1)
return false;
}
return true;
}
//--></script>

<form>
<input type="text" onChange="if (!validate(this.value)) alert('Not
Valid')">
</form>

"Lynkster" <tlynk@sympatico.ca> wrote in message
news:3d3563ca$1@10.1.10.29...> > I have been stuck on this one for 3
weeks and unable to locate anyone who> can help. I have a time field in
an HTML form table. I am having trouble> with illegal time formats. The
Database only accepts 00:00 format (Can not> be masked) and the
front-end webpage appears as a textbox so I am getting> everything from
3:33 to 3 30 to 330. Can the field be masked in the html> page to
military time. Please help!!