更新时间:2023-02-19 12:36:16
尝试以下方法:
public static Boolean isAlphaNumeric(string strToCheck)
{
Regex rg = new Regex(@"^[a-zA-Z0-9\s,]*$");
return rg.IsMatch(strToCheck);
}
如果您在正则表达式中指定字符串应包含的内容,而不是必须包含的内容,则更难以理解.
It's more undestandable, if you specify in regex, what your string SHOULD contain, and not what it MUST NOT.
在上面的示例中: