g.pickardou
g.pickardou

Reputation: 35873

JavaScript Date (and Date Time) validation using format parameter

I found many custom format validation questions and answers, however all's format was a specific hardcoded format. I would like to allow to set date and datetime format as (runtime) "setting" in my web application so it will dynamic at runtime. I would like to validate the user input against this setting:

isValidDate(userInput, currentSetting)

the content for currentSetting variable could be for example: mm/dd/yyyy

or yyyy.MM.dd HH:mm:ss (for date time)

I do not want reinvent the wheel, but I did not found such an universal parse/validate method. Missed I something?

Upvotes: 0

Views: 657

Answers (1)

jad-panda
jad-panda

Reputation: 2547

You can use momentjs. it provides all kind of time/date related functions

http://momentjs.com/

Upvotes: 1

Related Questions