This should be simple, but bear with me here please. What is it that I’m overlooking? All I’m trying to do is take in a value that is part of a SQL query and I want to check to make sure it has integers as its value. If it is, then I allow it to be passed to SQL Server. I’m getting a notification that my Regex method has invalid arguments. Thanks in advance for shedding some light on where I’m erring.
string valid2Regex = @"\d{4}"; // regex to check for 4 integers
Regex rgx = new Regex(valid2Regex);
string idCheck = id;
if (rgx.Matches(idCheck, rgx))
{
parameters.Add(DataAccess.CreateParameter("@YEAR", SqlDbType.NVarChar, HttpContext.Request.QueryString.Get("Year")));
}
This constrains it to just 4 digits. Otherwise any 4 digits together within a string would work with yours.
Also, there is no instance overload which takes those 2 parameters, instead use IsMatch: