Using Masks and Custom Characters

Using Masks and Custom Characters

When creating a Masked Text Box, you can specify a mask to indicate the format of the expected input. Masks are made up of literal characters and special characters, which define placeholders for input values. Literal characters in a mask are displayed as they are, while special characters represent specific input requirements.

Some of the most common special characters for creating masks are:

0: Specifies a digit. Only accepts numbers from 0 to 9.

9: Specifies a digit or a space. Allows empty spaces, but it will not display them.

#: Specifies a digit or a space. Allows empty spaces, and it will display them.

L: Specifies a letter. Only accepts letters from A to Z, in uppercase or lowercase.

?: Specifies a letter or a space. Allows empty spaces, but it will not display them.

&: Specifies any character. Accepts any keyboard input.

C: Specifies any character or space. Allows empty spaces, and it will display them.

You can also define custom characters to create masks with specific requirements. For example, you can use the \ character to escape special characters and treat them as literal characters, or the . character to specify the position of the decimal separator in a number.

Here’s an example of a mask that accepts a phone number in the format (123) 456-7890:

<asp:MaskedEditExtender ID=”MaskedEditExtender1″ runat=”server”

    TargetControlID=”txtPhoneNumber”

    Mask=”(999) 999-9999″

    PromptCharacter=”_”

    ClearMaskOnLostFocus=”false” />

<asp:TextBox ID=”txtPhoneNumber” runat=”server”></asp:TextBox> In this example, the MaskedEditExtender control is used to attach the mask to a TextBox control. The Mask property specifies the mask format, while the PromptCharacter property defines the character to display as a placeholder for empty spaces. The ClearMaskOnLostFocus property indicates whether to clear the mask when the TextBox loses focus.

Apply for ASP.NET Certification Now!!

https://www.vskills.in/certification/certified-aspnet-programmer

Back to Tutorial

Creating a Masked Input
Choosing Dates with a Calendar

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?