Remove the duplication by extracting this validator into a shared component.