Refactor validate(String) to use separate input stream handling