JavaScript to control dd/mm/aaaa

P

Paulo

Hi, maybe you have used it on your web apps:

Do you know any function to control if the user typed some incorrect date
value on edit box? I need "dd/mm/aaaa" format check.

if types: 32/01/2009 don't submit because don't have 32 days
if types: 30/13/2009 don't submit because don't have month 13
if types: 29/02/2009 don't submit because don't have day 29 on February
and go on... ...

Thank you very much!
 
H

Hal Rosser

Paulo said:
Hi, maybe you have used it on your web apps:

Do you know any function to control if the user typed some incorrect date
value on edit box? I need "dd/mm/aaaa" format check.

if types: 32/01/2009 don't submit because don't have 32 days
if types: 30/13/2009 don't submit because don't have month 13
if types: 29/02/2009 don't submit because don't have day 29 on February
and go on... ...

Thank you very much!
I would use the split function to separate the date parts, then create a new
string with the pieces arranged like a date, then use the isDate function to
see if its a valid date. (in VB)
 
E

Evertjan.

Hal Rosser wrote on 04 feb 2009 in
microsoft.public.inetserver.asp.general:
I would use the split function to separate the date parts, then create
a new string with the pieces arranged like a date, then use the isDate
function to see if its a valid date. (in VB)

However the OQ subject says javascript.

[And 'before submitting' means clietnside, being off topic.]

Try:

function goodDate(d) { // (d)d/(m)m/yyyy
d = d.split('/');
var t = new Date(d[2],d[1]-1,d[0]);
return t.getDate()==d[0] &&
t.getMonth()==d[1]-1 &&
t.getYear()==d[2];
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top