开发者

jquery date validation on multiple fields

开发者 https://www.devze.com 2022-12-31 17:21 出处:网络
I am attempting to use jquery to validate a date that is broken up into MM DD YYYY fie开发者_运维知识库lds.

I am attempting to use jquery to validate a date that is broken up into MM DD YYYY fie开发者_运维知识库lds.

<form name="dateform" id="dateform">
<input type="text" name="month"/>
<input type="text" name="day"/>
<input type="text" name="year"/>
</form>

I can only find examples that use a single field, which is not what I want.

<form name="dateform" id="dateform">
<input type="text" name="date"/>
</form>

Any examples I can follow?


You might try assembling your individual fields into a javascript date object.

var $form = $('form#dateform');
var dateToCheck = new Date( 
   $form.find('input[name=year]').val(), 
   $form.find('input[name=month]').val(),
   $form.find('input[name=day]').val() );

Then apply whatever validation you need to dateToCheck. If you'd like to use the validate plugin, one approach would be to store/update the assembled full date in a hidden field, and validate that field.

0

精彩评论

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

关注公众号