jQuery validation plugin: validate custom date format

前端 未结 2 1958
醉梦人生
醉梦人生 2021-01-22 07:04

I am using jQuery Validate plugin to validate my form, how can i validate a custom date with this date format DD-MMM-YYY (23-Mar-2012).

2条回答
  •  走了就别回头了
    2021-01-22 07:24

    Look at http://www.intelligrape.com/blog/2010/03/31/client-side-date-validation-using-jquery-plugins/

    jQuery.validator.addMethod("customDateValidator", function(value, element) {
            // parseDate throws exception if the value is invalid
            try{jQuery.datepicker.parseDate( 'm/dd/yy', value);return true;}
            catch(e){return false;}
        },
        "Please enter a valid date"
    );
    

    Check also referenced post: Custom date format with jQuery validation plugin

    Also: Validate two dates of this "dd-MMM-yyyy" format in javascript

提交回复
热议问题