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.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Shweta
  • 129
  • 1
  • 3
  • 10

4 Answers4

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" />
Derek Wade
  • 697
  • 8
  • 11
Lam Chau
  • 842
  • 5
  • 14
  • Thanks it helped :) How to limit the user from entering only alphabets in the textbox using MaskedEditExtender? – Shweta Nov 19 '11 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 '11 at 22:29
  • to ensure user could add alphabets only, you should use `` This code will ensure user could input alphabets only. Thanks! – Nikhil G Oct 07 '14 at 05:19
1

use jquery masked text box Masked Input Plugin 1.2.2

DeveloperX
  • 4,633
  • 17
  • 22
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

Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
1

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

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108