Click here to Skip to main content
15,896,348 members
Articles / Web Development / ASP.NET

Mask TextBox ASP.NET Control

Rate me:
Please Sign up or sign in to vote.
4.84/5 (22 votes)
1 Apr 2009CPOL 96.3K   6.6K   15  
An ASP.NET textbox to input bank account or credit card numbers or other kinds of formatted text
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="True" Inherits="Mtb.Default" %>
<%@ Register TagPrefix="uc1" TagName="MaskTextBox" Src="maskTextBox/MaskTextBox.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>default</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<script type="text/javascript" src="maskTextBox/js/maskTextBox.js"></script>
		<script type="text/javascript">var mtb;</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<TABLE id="Table1" style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 8px" cellSpacing="0"
				cellPadding="0" width="100%" border="0" height="100%">
				<TR>
					<TD height="10"></TD>
				</TR>
				<TR>
					<TD vAlign="top" height="100%">
						<TABLE id="Table2" cellSpacing="0" cellPadding="0" width="100%" border="0">
							<TR>
								<TD style="WIDTH: 93px" height="150"></TD>
								<TD height="150">
									<UL>
										<li>
										Type or paste in the account (e.g. "22-4444-7777777-333" or "2244447777777333" 
										or "22 4444 7777777 333" or partial as "22444" or "22 444" and so on...).
										<li>
										After pasting or when you leave the textbox its content your input gets 
										formatted.
										<li>
											When you click Submit your input is validated (e.g. try to submit a shorter 
											account; for the current input mask "NA-ANNA-NNNANNN-NAN" the valid input will 
											be something like "2a-444b-777c777-3d3")</li></UL>
								</TD>
							</TR>
							<TR>
								<TD>Bank Account:</TD>
								<TD>
									<uc1:MaskTextBox id="maskTextBox" runat="server" InputMask="NA-ANNA-NNNANNN-NAN"></uc1:MaskTextBox>
								</TD>
							</TR>
							<TR>
								<TD>&nbsp;</TD>
								<TD></TD>
							</TR>
							<TR>
								<TD>Credit Card:</TD>
								<TD>
									<uc1:MaskTextBox id="maskTextBox1" runat="server"></uc1:MaskTextBox>
								</TD>
							</TR>
							<TR>
								<TD>&nbsp;</TD>
								<TD></TD>
							</TR>
							<TR>
								<TD></TD>
								<TD>
									<asp:Button id="btnSubmit" runat="server" Text="Submit"></asp:Button>
								</TD>
							</TR>
						</TABLE>
					</TD>
				</TR>
				<TR>
					<TD height="100"></TD>
				</TR>
			</TABLE>
		</form>
	</body>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
New Zealand New Zealand
Coder

Comments and Discussions