I had used Regex string:
versionPattern = @"^\d+(.\d+){3}$"
to check format of string with 4 number have hyphen is .
xxx.xxx.xxx.xxx or x.x.x.x ...
But it return true with string:
1.0.0.123
and return false with string:
1.0.0.4
My code for this:
if (Regex.IsMatch(svnShopLoorTable.Rows[i].ItemArray[2].ToString(), versionPattern))
{
//MessageBox.Show("OK");
}
else
{
//MessageBox.Show("Should be: x.x.x.x");
s += "\r\nProgram " + svnShopLoorTable.Rows[i].ItemArray[1].ToString() + " of SHOPFLOOR has wrong version format: "
+ svnShopLoorTable.Rows[i].ItemArray[2].ToString() + " should be formated as: " + "x.x.x.x";
Console.WriteLine(s);
}
When svnShopLoorTable.Rows[i].ItemArray[1].ToString() is 1.0.0.123 it's ok, not display s. But when svnShopLoorTable.Rows[i].ItemArray[1].ToString() is 1.0.0.4, it's display log in console:
Program SetupSheet of SHOPFLOOR has wrong version format: 1.0.0.4 should be formated as: x.x.x.x
I don't know why this problem occur. Please help me to explain and solve this. Appreciate any help!
mmodifer@"(?m)regex".for both good practice and to make sure it's validating an actual dot (otherwise it means any character - except newline).1.0.0.4,if so ,you can remove^$and try