I've been going through solutions from here and dotnetperls to try and find a way to format my textbox to only allow numeric characters. I'm either just not getting it, or really don't understand the code to do what I want.
I have a form that changes depending on which button was pressed in another form, and I need the Age box to only allow numerical characters up to 99 (So the user can enter an age in the range of 1-99. I've looked into Regex methods and masked text boxes but just don't get it.
Would someone be able to point me in the direction of what I would use to achieve this?
My code reads as:
private void AddItem_Load(object sender, EventArgs e)
{
if (formName == "customer")
{
this.Text = "Add Customer";
lblZero.Text = "ID:";
lblOne.Text = "Customer Name:";
lblTwo.Text = "Address Line 1:";
lblThree.Text = "Address Line 2:";
lblFour.Text = "Town:";
lblFive.Text = "Postcode:";
lblSix.Text = "Age:";
txtID.Text = Convert.ToString(customerList.NewID());
txtID.Enabled = false;
}
else
{
this.Text = "Add Product";
lblZero.Text = "Product ID:";
lblOne.Text = "Product Code:";
lblTwo.Text = "Product Name:";
lblThree.Text = "Product Description:";
lblFour.Text = "Price:";
lblFive.Text = " --------- ";
lblSix.Text = " ---------";
txtID.Text = Convert.ToString(productList.NewID());
txtID.Enabled = false;
txtFive.Enabled = false;
txtSix.Enabled = false;
}
}
where the textboxes on the form are labelled txtZero.txt ~ txtSix.txt.
All help is much appreciated :)