Praveen Maurya

Praveen Maurya

  • NA
  • 146
  • 26.8k

validating a textbox for 10 digit mob no.

Apr 14 2018 3:13 PM
i have created a textbox validation for 10 digit mob number but this is not working am i wrong anywhere
 
 
private void Validatemobnum(string Mobile)
{
Regex rx1 = new Regex("^[1-9]{10}");
if (rx1.IsMatch(Mobile))
{
throw new Exception("Only Numbers without decimal value are allowed");
}
}
 
 
i have creatted a method and calling at textbox leave event  
 
 
private void addsuppliermob_Leave(object sender, EventArgs e)
{
try
{
Validatemobnum(addsuppliermob.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Please Check Mob ", MessageBoxButtons.OK, MessageBoxIcon.Error);
addsuppliermob.Text = "";
addsuppliermob.Focus();
return;
}
}
 

Answers (2)