I want to match comma separate integer list using Regex. I have used bellow pattern but it doesn’t work for me.
if (!Regex.IsMatch(textBox_ImportRowsList.Text, @"^([0-9]+(,[0-9]+))*"))
{
errorProvider1.SetError(label_ListRowPosttext, "Row Count invalid!");
}
Valid Inputs:
1
1,2
1,4,6,10
Invalid Inputs:
1,
1.1
1,A
2,/,1
,1,3
You’ve got the asterisk in the wrong place. Instead of this:
…use this:
Additionally, you should anchor the end like you did the beginning, and don’t really need the outermost set of parentheses: