Refactor valid-number directive