0

I would like to enquire if I could write a JavaScript that is to verify a varchar field so that it must fit this format YYYY/MM/DD? My page is coded in ASP classic.

field :trdate varchar 

On the page, it was indicated with a remark yyyy/mm/dd. See attached.

varchar date field

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Yeong
  • 1
  • 1
    Possible duplicate of [How to validate date with format "mm/dd/yyyy" in JavaScript?](https://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript) – Robby Cornelissen Jun 11 '18 at 09:41
  • Possible duplicate of [Where can I find documentation on formatting a date in JavaScript?](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Heretic Monkey Jun 11 '18 at 13:36

1 Answers1

0

Use a Regex pattern the following pattern covers that format and some variations

/^((0[1-9]|1[012]|[1-9])[- /.](0[1-9]|[12][0-9]|3[01]|[1-9])[- /.](19|20)\d\d|(19|20)\d\d[- /.](0[1-9]|1[012]|[1-9])[- /.](0[1-9]|[12][0-9]|3[01]|[1-9]))$/

Jose Munoz
  • 558
  • 2
  • 12