4

I need to format an asp.net text box in such a way that it accepts the user input only in the form of

### - ### - ### (#:numerics only).

Suggestions or answers please.

4 Answers 4

8

MaskedEdit might be what you're looking for.

Here is an modified example from the link above:

<ajaxToolkit:MaskedEditExtender runat="server"
    TargetControlID="TextBox2" 
    Mask="999-999-9999" />
3
  • Thanks it helped :) How to limit the user from entering only alphabets in the textbox using MaskedEditExtender?
    – Shweta
    Nov 19, 2011 at 16:25
  • If you wanted to change phone numbers Mask="999-9999-9999" to a say validating a U.S. state you would change it to Mask="LL" (2 alphabetic characters). Check out the link some more if you wanted to do more robust validation (e.g. A-C only).
    – Lam Chau
    Nov 19, 2011 at 22:29
  • to ensure user could add alphabets only, you should use <asp:FilteredTextBoxExtender ID="idName" runat="server" Enabled="True" TargetControlID="txtBoxname" FilterType="Custom, UppercaseLetters, LowercaseLetters" ValidChars=""></asp:FilteredTextBoxExtender> This code will ensure user could input alphabets only. Thanks!
    – Nikhil G
    Oct 7, 2014 at 5:19
1

use jquery masked text box Masked Input Plugin 1.2.2

1

You can use MaskedEdit ajax control..

MaskedEdit is an ASP.NET AJAX extender that attaches to a TextBox control to restrict the kind of text that can be entered. MaskedEdit applies a "mask" to the input that permits only certain types of characters/text to be entered. The supported data formats are: Number, Date, Time, and DateTime.

follow this link for details: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx

1

You can either use jQuery as suggested by DeveloperX or use the MaskedEditExtender from AjaxControlToolkit.

Not the answer you're looking for? Browse other questions tagged or ask your own question.