Here is some code which can show you how to do this for phone numbers of the format
(xxx) xxx-xxxx. Only numbers are allowed to be entered, with the brackets and dash being automatically applied. You can adapt the code to any other format desired.
https://www.wixcodebank.com/dynamically-format-user-input
Hope this helps!
Absilutely pissed. No code was provided but they DID ask me for my email and then when you want the code you need to pay. BEWARE! Loss of time.