Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Javascript Date Format Change on exit

brianmjohnnies
Level 2
Level 2

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.

2 Replies
radzmar
Level 10
Level 10

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}

CodeSpeedy
Level 1
Level 1

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.