How to set input mask for a custom field
Not in the UI afaik. I would use the validateForm hook in an extension to validate the number of digits? Documentation on the hook is here: https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_validateForm/