Add validation and trim utilities and tests