Using regex to check if input is valid