A predicate or validator function would factor this.