Find number from a string

Bubbly
Posted by Bubbly under C# category on | Views : 1638
Description :
This regular expression will display if a string entered contains a number.

private void btnFindNumber_Click(object sender, System.EventArgs e) 
{
Regex re = new Regex(@"\d+");
Match m = re.Match(txtFindNumber.Text);
if (m.Success)
{
lblResults.Text = string.Format("RegEx found " + m.Value + " at position " + m.Index.ToString());
}
else
{
lblResults.Text = "You didn't enter a string containing a number!";
}
}

Comments or Responses

Login to post response