I need to determine if a string contains Invalid chars. The criteria is that it should only have [a-z], [A-Z], [0-9] and [/,.-\] characters and anything else is invalid. Also, chars followed by space followed by / followed by space followed by chars is valid. The regex I have below takes care of the first criteria but I am struggling with the second. I have tried many combinations, something like these, but no success.
public bool ContainsInvalidChars(string s)
{
return new Regex(@"[^a-zA-Z0-9/,.-][@"\s/\s"]).IsMatch(s);
}
Examples of input strings:
below is Valid
CSU,USD,6230.67,705RA0 / 2YKMP,5/11/2020,5/11/2020,VM
below is invalid
CSU,USD,6230.67,705RA0 /2YKMP,5/11/2020,5/11/2020,VM
below is invalid
CSU, USD,6230.67,705RA0 / 2YKMP,5/11/2020,5/11/2020,VM
Any help is greatly appreciated. Thanks.
return Regex.IsMatch(s, @"pattern_here");.return Regex.IsMatch(s, @"(?!\s/\s)(?<!\s/(?=\s))[^a-zA-Z0-9/,.-]");