I'd suggest to use
validate
event with
ErrorProvider
and
Regex
.
Here is a complete example:
Control.Validating Event (System.Windows.Forms) | Microsoft Docs[
^]
string[] somestrings = {"Ads20.e", "MG20.9", "BT3,5.0", "mt29.00", "32TG,5.99", "58BM5.11"};
string pattern = @"[[M|G|B|T|][0-9]|\.\,]|[[0-9][M|G|B|T|]|\.\,]";
foreach(string s in somestrings)
{
Console.WriteLine("{0} => {1}", s, Regex.IsMatch(s, pattern));
}
Result:
Ads20.e => False
MG20.9 => True
BT3,5.0 => True
mt29.00 => False
32TG,5.99 => True
58BM5.11 => True