have you tried the MaskedEdit control of the asp.net ajax toolkit? it does what you've described

http://ajax.asp.net/ajaxtoolkit/MaskedEdit/MaskedEdit.aspx