Set date format in MVC/.Net Core using unobtrusive js

We will include some js for validation .

@Scripts.Render("~/Scripts/jquery-3.1.1.js")
@Scripts.Render("~/Scripts/jquery.validate.min.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js")
@Scripts.Render("~/Scripts/moment.js")

we need moment.js so we will install or add put moment js file in out solution.

And then we will finally add fix for date format parser in any js call after unobtrusive and page load

$(function () {
    $.validator.methods.date = function (value, element) {
        return this.optional(element) || moment(value, "DD/MMYYYY", true).isValid();
    }});

I have set date format “dd/MM/yyyy”. moment js need date format in upper case so I have use as “DD/MMM/YYYY”.


Comments

Popular posts from this blog

TRIGGER in sql server

What is the importance of EDMX file in Entity Framework

How to add or update query string parameter to current url in Javascript