How to use HTML5 to validate a date range?

前端 未结 5 1044
清酒与你
清酒与你 2021-01-12 17:15

Alternatively, is it possible to validate against another field\'s value with html5?

A common example would be selecting a date range where \"from\" date sh

5条回答
  •  情歌与酒
    2021-01-12 17:35

    It's possible to utilize html5 validation mechanism with some javascript to dynamically update min/max attributes:

    //in this case a single input restriction is sufficient to validate the form:
    
    $('#from, #to').on('change', function(){
        $('#to').attr('min', $('#from').val());
    });
    

    Fiddled. Both min and max could be applied to the respective fields for enhanced UX if browser implementation of a datepicker respects range limitations (by disabling dates outside of the desired range)

提交回复
热议问题