我正在使用jQuery validate插件,想知道是否有一种方法可以验证输入到字段中的日期是否为yyyy-mm-dd之类的日期,并且该日期介于2010年11月29日至2010年12月15日之间
我对jQuery非常陌生,因此,如果有答案,请尽量将答案弄糊涂,这样我就可以解决它.非常感谢您提出的所有建议
解决方案如果您想要可重用的函数,则可以扩展Emily和lonesomeday的答案以允许提供参数:
$.validator.addMethod('daterange', function(value, element, arg) { // Same as above var startDate = Date.parse(arg[0]), endDate = Date.parse(arg[1]), enteredDate = Date.parse(value); // Same as below }, $.validator.format("Please specify a date between {0} and {1}."))请参见源 jQuery验证 range 方法作为示例.
Im using the jQuery validate plugin and was wondering if there was a way to validate if the date entered into a field was a date like yyyy-mm-dd AND the the date falls between Nov 29 2010 - Dec 15 2010
Im pretty new to jQuery so if there is an answer please dumb up the answer as much as possible so i can get through it. Thanks a lot for any/all suggestions
解决方案If you want a reusable function, you might extend Emily and lonesomeday's answers to allow an argument to be provided:
$.validator.addMethod('daterange', function(value, element, arg) { // Same as above var startDate = Date.parse(arg[0]), endDate = Date.parse(arg[1]), enteredDate = Date.parse(value); // Same as below }, $.validator.format("Please specify a date between {0} and {1}."))See the source of the jQuery validation range method for an example.
更多推荐
jQuery验证(日期范围)
发布评论