JRS: In article <45***********************@newsspool2.arcor-online.net>,
dated Mon, 9 Oct 2006 18:51:37 remote, seen in
news:comp.lang.javascript, Martin Honnen <ma*******@yahoo.deposted :
>Ike wrote:
>If I am requiring a date be entered as YYYY-MM-DD.....why then....
var validformat=/^\d{4}\[-]\d{2}[-]\d{2}$/ //Basic check for format validity
^^ ^ ^ ^ superfluous
| error
>
I think you want
/^\d{4}\-\d{2}\-\d{2}$/
/^\d{4}-\d\d-\d\d$/ is adequate.
In the past, the newsgroup has accepted
nD = new Date(Y, M-1, D)
OK = (nD.getMonth()+1 == M) && (nD.getDate() == D)
as the (joint?) best way to validate Y M D with a Date Object.
It occurs to me that if one has used Mt = String.match(RegExp) to
check the pattern of the input string, and D = +Mt[3] etc., then one
only needs
OK = nD.getMonth()+1 == M
OK ?
--
© 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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.