且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中检查输入字符串中的特殊字符

更新时间:2023-02-21 10:15:01

)。成功;
}
").Success; }





这种方法是否正确?



Is this method is correct?


你可以简单地检查如下。



只需添加命名空间



使用系统。 linq



int PasswordSpecialChar = txtMonth.Text.Count(p =>!char.IsLetterOrDigit(p));
you can simply check like below.

just add namespace

using system.linq

int PasswordSpecialChar = txtMonth.Text.Count(p => !char.IsLetterOrDigit(p));


没有。

例如,您的解决方案不适用于大写字母。试试这个:

No.
Your solution will not work with upper case, for example. Try this:
return Regex.Match(stringToTest, @"^\W+