def range_check(val, lb, ub):
    """
    Data range validation.

    'val' should have attribute __lt__ and __gt__.
    'lb', 'ub' should be of the same type as 'val'.
    'lb' means lowerbound and 'ub' means upperbound.
    """
    return True if hasattr(val, '__lt__') and hasattr(val, '__gt__') and \
                   type(val) == type(lb) and type(val) == type(ub) and \
                   lb <= val <= ub else False