hi
u can limit textbox max length to 4, then use keypress event to validate entry:

private void [textbox]_keypress(object sender,keypressventArgs e)
{
   if((!Char.IsControl(e.char))&&(!Char.Isdigit(e.char)))
        e.handled = true;
}

then use keyup event to catch enter pressed to add controls

private void [textbox]_keyup(object snder, keyeventargs e)
{
  if (e.KeyCode == Keys.Enter)
            this.Controls.Add(label);
}

Recommended Answers

All 5 Replies

You can limit textbox's maximum length by settings its attribute length/max length to 4 in the Properties panel.

Member Avatar for saravind84

As jugosoft mentioned set the max length property of the textbox to 4. You can do that using the properties panel or in the code as shown below.

private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.MaxLength = 4;
        }

I want help....restrict to user enter only 10 number in textbox if user not enter 10 number curser do not go to another control........reply soon

I want help....restrict to user enter only 10 number in textbox if user not enter 10 number curser do not go to another control using c#........reply soon

use javascript for validating asp.net textbox values

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.