JRS: In article <Xn************ ********@194.10 9.133.29>, dated Thu, 2
Sep 2004 17:12:43, seen in news:comp.lang. javascript, Evertjan.
<ex************ **@interxnl.net > posted :
Abby Lee wrote on 02 sep 2004 in comp.lang.javas cript: I ask the user to enter a time in the formatio 12:30 PM.
function checkTime(patte rn){
if (/^\d{1,2}:\d{2}[ap]m$/i.test(pattern) )
if (/^\d{1,2}:\d{2} [ap]m$/i.test(pattern) ) // to be exact
if (/^[01]?\d:\d{2} [ap]m$/i.test(pattern) ) // hours 0-9,00-19
if (/^([1-9]|1[012]):\d{2} [ap]m$/i.test(pattern) ) // hours 1-12
The minutes field can be checked with, instead of \d{2}, [0-5]\d - then
we have an expression that allows only well-formed alien times (ISTM).
In the last form above, one can insert either 0 or 0? before the first [
..
Part-tested.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.