Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Mask TextBox ASP.NET Control

0.00/5 (No votes)
1 Apr 2009 1  
An ASP.NET textbox to input bank account or credit card numbers or other kinds of formatted text
maskTextBoxTest_net3 - Click to enlarge image

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...

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

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

Points of Interest

Hopefully I will upload an Ajax version and a Java version soon.

I hope this helps!

History

  • 2nd April, 2009: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here