Is there a windows form textbox or c# string native member method that checks if its contents have any non-alphanumeric character?
or do I have to do it manually?
EDIT: I used @Habib's answer and added so that white spaces are checked as well, and to my surprise, it worked! lol
bool result = strVariable.Any(r=> (!char.IsLetterOrDigit(r) && !char.IsWhiteSpace(r)));
Btw, I've never used the "lambda" expression that's why I'm surprised the code above worked when I added the whitespace condition on @Habib's initial answer.
You can use char.IsLetterOrDigit
Indicates whether a Unicode character is categorized as a letter or a decimal digit.
bool result = strVariable.Any(r=> !char.IsLetterOrDigit(r));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With