Shovan Saha

Shovan Saha

  • NA
  • 321
  • 91.9k

C# text box 11 digit only

Apr 28 2017 10:06 AM
private void txtReceiverContact_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(txtReceiverContact.Text, " ^ [0-9]"))
{
txtReceiverContact.Text = "";
}
}
private void txtReceiverContact_KeyPress(object sender, KeyPressEventArgs e)
{
string senderText = (sender as TextBox).Text;
string senderName = (sender as TextBox).Name;
int cursorPosition = (sender as TextBox).SelectionStart;
if (!char.IsControl(e.KeyChar)
&& !char.IsNumber(e.KeyChar))
{
e.Handled = true;
}
}
== When I will press any letter, message box will appear and show "Input Digit Only!" 
== Digt will not be more than 11 (Eleven) 

Answers (4)