refactor(input): wrapped validation logic in helper function