I searched internet and even followed the documentation of RegEx but unable to solve the issue. I want to validate single digit or double digit number. It should only accept
Use Case1: string sDate= ",01,23,05,1,28,25";
Use Case1: string sDate= ",01,23,05,1,28,25,";
Use Case1: string sDate= "01,23,05,1,28,25,";
Use Case1: string sDate= "01,23,05,1,28,25";
It should not accept anything i.e. no decimal, characters, special character except comma. I have written a code in C#
string stDate= ",01,23,05,1,28,25";
if (!string.IsNullOrEmpty(sDate))
{
Regex r = new Regex(@"^(\d+[,]\d*|\d*[,]\d+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (r.IsMatch(sDate))
{
business logic
}
}
else
{
//business logic
}
I need to know where I"m going wrong. When I'm entering a alphabet in the string it is accepting it even. Any help would be highly appreciated. enter code here enter code here