There is most likely a much better and more efficient way to do this out there. This is just one possible way.
But Here is what I came Up with.
public bool IsInputStringValid(string input)
{
//If there are no Braces then The String is vaild just useless
if(!input.Any(x => x == '{' || x == '}')){return true;}
//Check If There are the Same Number of Open Braces as Close Braces
if(!(input.Count(x => x == '{') == input.Count(x => x == '}'))){return false;}
//Check If Value Between Braces is Numeric
var tempString = input;
while (tempString.Any(x => x == '{'))
{
tempString = tempString.Substring(tempString.IndexOf('{') + 1);
string strnum = tempString.Substring(0, tempString.IndexOf('}'));
int num = -1;
if(!Int32.TryParse(strnum, out num))
{
return false;
}
}
//Passes Validation
return true;
}
Here Is The Fiddle: http://dotnetfiddle.net/3wxU7R