1

I want to format my textbox to have 4 numerical integers at all times. Example 90 would equal 0090. I also do not want letters to be entered. Any help would be greatly appreciated

1
  • 3
    Is this WinForms or Web?
    – Decker97
    Commented Sep 6, 2011 at 21:22

1 Answer 1

5

You mean like a Masked Textbox? You can use a mask of "0000" to ensure only numbers can be entered, and that you need four of them.

If it's for asp.net you could look at a MaskedEdit or a jQuery solution.

2
  • textBox1.Text = string.Format("{0:0000}", someNumber); This is the way I have it I am new to C# a huge leap for me from Visual Basic Commented Sep 6, 2011 at 21:24
  • Is one of the rare occasions where a masked textbox is useful (often, it is too limited). Commented Sep 7, 2011 at 7:51

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