What you are looking for is a masked input.
This[
^] javascript library has helped me in the past and seems reasonably solid for that purpose.
If you have multiple different formats specified by a dropdown that then need to be applied to a text input, then you'll just have to change the mask on the fly and re-validate the textual content.