开发者

Jquery date format

开发者 https://www.devze.com 2023-01-02 07:40 出处:网络
I want to validate my date field in \"mm-dd-yyyy\" format using jquery validation plugin. I want to display message \"Please enter date in mm-dd-yyyy\" if anybody vilates the date formar H开发者_Stac

I want to validate my date field in "mm-dd-yyyy" format using jquery validation plugin. I want to display message "Please enter date in mm-dd-yyyy" if anybody vilates the date formar H开发者_StackOverflow社区ow will i do that ?

Thanks


the dateISO validation method should do what you need.


in your js, after including validator

jQuery.validator.addMethod("datetime", function(value, element) {
    return this.optional(element) || /^\d{4}-\d{1,2}-\d{1,2}( \d{1,2}:\d{1,2}:\d{1,2})?$/.test(value);
    }, "Please enter a valid date (YYYY-MM-DD)"
);

// connect it to a css class
jQuery.validator.addClassRules({
    datetime : { datetime : true }    
});

in your html

<input type='text' class='datetime' />

this actually allows to enter a datetime format for mysql (YYYY-MM-DD HH:MM:SS), but whatever.

$2c, *-pike

0

精彩评论

暂无评论...
验证码 换一张
取 消