I want to validate a string based on a custom format: ___.___ or ___,___, 3 numbers followed by a dot or comma followed by 3 numbers (e.g. 123.456 or 123,456).
Currently, I have following code:
string InputText = "123.456"
bool result, result1, result2;
int test, test2;
result = Int32.TryParse(InputText.Substring(0, 3), out test);
result1 = (InputText[3] == '.' || InputText[3] == ',') ? true : false;
result2 = Int32.TryParse(InputText.Substring(4, 3), out test2);
if (result == false || result1 == false || result2 == false)
{
Console.WriteLine("Error! Wrong format.");
}
This works just fine, however, this seems rather inefficient and unnecessarily complex; is there an alternative to this?

\d{3}[.,]\d{3}