The condition being this value must be single or integer; spaces should be handled; no need to check empty spaces at the start of end of the string; "12.6" or "12.6," are both not accepted.
This should work (code by les patter)
string pattern = @"\d+(\.\d)?(\s|\,)\s*\d+(\.\d)?";
string[] tests = {
"12.6, 3",
"12.6 3",
"12.6",
"12.6,",
", 3",
" 4",
"1, 2.3",
"123, 456",
};
foreach (string test in tests)
Console.WriteLine("{0}: {1}", Regex.IsMatch(test, pattern), test);
}
No comments:
Post a Comment