Hi
Try like this
bool Valid = false;
private void button1_Click(object sender, EventArgs e)
{
Regex rx = new Regex("^[0-9]*$");
if (!string.IsNullOrEmpty(TxtTelphone.Text))
{
if (rx.IsMatch(TxtTelphone.Text))
{
Valid = true;
}
else
{
MessageBox.Show("characters not allowed.");
TxtTelphone.Clear();
TxtTelphone.Focus();
return;
}
}
else
{
MessageBox.Show("Please enter a Telphone no and click Ok.");
TxtTelphone.Focus();
return;
}
}
And allow only for 5 digits use this code
private void TxtTelphone_KeyPress(object sender, KeyPressEventArgs e)
{
if (TxtTelphone.Text.IndexOf(' ') == TxtTelphone.Text.Length - 6)
e.Handled = true;
}