Date Validation

  • Thread starter Dr J R Stockton
  • Start date
D

Dr J R Stockton

Much has been written here on Date Validation; but I don't recall seeing
the following method.

Frequently, a page which calls for date input will also call for one
particular form of date output, which should be provided by a Method or
a Function rather than by in-line code. If that form is acceptable to
new Date, perhaps after simple RegExp modification such as converting
DMY to FFF, then one can validate by, in effect,

D = read S1 ; S2 = write D ; OK = S1 == S2

function DoubleConv(S) {
return new Date(S.replace(/-/g, "/")).ISOlocaldateStr() == S }
// given that ISOlocaldateStr has been added to Date

OK = DoubleConv(S) // Test whether S is Y-mm-dd

Clearly, the method can be modified to return, say, either the Date
Object or NaN; and to use other date formats.
 

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

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top