| re: Control the format
JRS: In article <dshtkp$59j$1@hefestos.uned.es>, dated Fri, 10 Feb 2006
11:34:18 remote, seen in news:comp.lang.javascript, Daviso
<dhernande7@alumno.uned.es> posted :[color=blue]
>I have an <input> into a html page. In this box, the user must introduce the
>hour by hand. I want to control that the format is correct, for example:
>10.35
>22:50
>etc... (just, one of them)
>I have been looking for code to do this, but I can't find.[/color]
You should not try to control the format as it is being constructed;
it's better to check that the field is valid before it is used. See
<URL:http://www.merlyn.demon.co.uk/js-valid.htm> and use something like
OK = /^\d\d[:\.]\d\d$/.test(S)
If those are times, maybe /^[0-2]\d[:\.][0-5]\d$/ - it's scarcely worth
bothering to rule out hours 24..29.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. |