def validate_range(low=None, high=None):
    """
    Validate the range of a field with either low, high, or equal.
    Should work with anything that supports '>' and '<' operators.

    :param low: Smallest value required.
    :param high: Longest value required.
    :raises: ``ValidationError('range_low')``
    :raises: ``ValidationError('range_high')``
    :raises: ``ValidationError('range_between')``
    """
    def range_validator(field, data):
        if field.value is None:
            return
        if low is not None and field.value < low:
            key = 'range_low' if high is None else 'range_between'
            raise ValidationError(key, low=low, high=high)
        if high is not None and field.value > high:
            key = 'range_high' if high is None else 'range_between'
            raise ValidationError(key, low=low, high=high)
    return range_validator