Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How check inputs for current time in 24 hours format

Status
Not open for further replies.

Albert3162

Programmer
Jul 13, 2001
18
0
0
US
Hi,

I'm trying to check what user insert in the input field
as current time user can insert only 4 digits (format like 1239 or 0057, 2355)


 
HI,

I would check for

value.length = 4
and
isNaN(parseInt(value))

I hope that does it for you.
If you need more help post what you've got and I'll fit that in it for you.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Break it down:
first digit must be 0-2
second digit must be 0-9
third digit must be 0-5
fourth digit must be 0-9

Welcome to regular expression land :)
put this in your <head><script>..
Code:
function checkTime(textObj) {
  var str = textObj.value;
  var regex = /^[0-2][0-9][0-5][0-9]$/;
  if (!regex.test(str)) {
    alert(&quot;Please make sure time is in this format 1423&quot;);
    textObj.focus();
  }
}

and then you could use it like so:
Code:
<input type=&quot;text&quot; name=&quot;timeBox1&quot; size=&quot;6&quot; onblur=&quot;checkTime(this);&quot; />

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top