Introduction

This ASP.NET control can be used to input bank account or credit card numbers or other kinds of formatted text.

Background

We needed a way to easily input many bank account numbers in the same page, a quick "paste'n go" approach but also with full format and validation support. The page should also load as fast as possible so the control instances are initialized only when they got the focus and the HTML is not bloated with JavaScript snippets.

Many thanks to Diego Perini (dperini@nwbox.com) who helped me with his samples to get right some caret JavaScript.

Using the Code

If you look in default.aspx, the page that uses the control, pay attention to the following global variable...

<scripttype="text/javascript">var mtb;</script>

... that is shared by the control instances and it gets initialized every time one receives the focus.

I gave you a 4 - but primarily to compensate for original harsh vote of 1. While the article probably should be better, I was interested about what you do and how. I did implement masking controls throughout my carrier on different environments. Seems like every developer has to do it at some point. But this day and age? Any framework you stick with offers a masking control: Ajax CTP, jQuery, ExtJS, you name it. Why one more?

My apologies for the short article and thanks for the 4! I never really read full articles myself, I look at the picture and I try the code. I will make it longer with the next update.I did this code about one year ago; somehow when I googled this subject I haven't really found what I needed and also we don't use various libraries in our intranet "specialist" application that used to run .Net 1.1 till about one month ago. And I enjoy a lot more to code them if I can.