Add isvalid function which returns True/False