this is not an issue with the bit of code you showed.
This is a namespace issue at the very top of your file.
The solution should be https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main ()
{
var isNumeric1 = IsNumeric("1");
Console.WriteLine(isNumeric1);
var isNumeric2 = IsNumeric("HelloWorld");
Console.WriteLine(isNumeric2);
//call IsNumeric with the value of this.txtIdGrupo.Text like this
//var isNumeric = IsNumeric(this.txtIdGrupo.Text);
}
private static bool IsNumeric(string str)
{
string id = str;
if (!Regex.IsMatch(id, @"^\d+$"))
return false;
return true;
}
}
See it in action:
https://dotnetfiddle.net/I7cAKs
notice the “using System.Text.RegularExpressions”
Using tools like Resharper and similar will definitely give you hints and will improve your day to day !
1
solved C# – How do I put the Function Regex working? [closed]