Javascript Date Format Change on exit

Avatar

Avatar

brianmjohnnies

Avatar

brianmjohnnies

brianmjohnnies

07-12-2017

My date field has MM/DD/YYYY format which would show 08/03/2017 for example. If I copy a date from a website as 8/3/2017 and paste into the field I would like the date field to recognize that format and change to 08/03/2017 and not throw up a validation error. I looked at various ways to this but can't figure it out through the patterns (to accept the 8/3/2017 format) or through javascript in the exit event.

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar

CodeSpeedy

Avatar

CodeSpeedy

CodeSpeedy

11-11-2018

break the date string first then take the month as an integer.

example.
Compare with 12. If it is greater than 12 then it must be a date, not a month.
Then just change the format as per your need
See how to change the date format

https://www.codespeedy.com/format-javascript-date-to-yyyy-mm-dd/ 

But in your case, you can take multiple date pattern so that any date pattern will be valid to pass the validation check.

Avatar

Avatar

radzmar

MVP

Avatar

radzmar

MVP

radzmar
MVP

07-12-2017

You can combine multiple patterns when setting up the edit pattern to allow several different ways for entering a date.

Edit pattern to allow 08/03/2017 and 8/3/2017

date{MM/DD/YYYY}|date{M/D/YYYY}