def b_validate(A='', fail_empty=True):
    """
    Validate that a given string contains only 0s and 1s.
    
    This will return True if the string is valid, otherwise it returns False.
    
    E.g. b_validate() returns False
         b_validate('') returns False
         b_validate('', fail_empty=False) returns True
         b_validate('01010101') returns True
         b_validate('010120101') returns False
         b_validate('0101 0101') returns False
    """
    t = True
    if t and not type(A) is str:
        t = False
    if t and fail_empty and not len(A) > 0:
        t = False
    if t:
        from re import compile as re_compile
        pattern = re_compile('[^01]')
        t = not bool(pattern.search(A))
        del re_compile, pattern
    return t
