简体   繁体   English

Windows形成文本框或c#字符串本机方法,用于检查非字母数字字符

[英]Windows forms textbox or c# string native method for checking non-alphanumeric character

Is there a windows form textbox or c# string native member method that checks if its contents have any non-alphanumeric character? 是否有一个Windows窗体文本框或c#字符串本机成员方法,检查其内容是否有任何非字母数字字符?

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! 编辑:我使用了@Habib的答案并添加了以便检查空格,令我惊讶的是,它有效! 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. 顺便说一句,我从未使用过“lambda”表达式,这就是为什么当我在@Habib的初始答案中添加空白条件时,我对上面的代码感到惊讶的原因。

You can use char.IsLetterOrDigit 您可以使用char.IsLetterOrDigit

Indicates whether a Unicode character is categorized as a letter or a decimal digit. 指示Unicode字符是分类为字母还是十进制数字。

bool result = strVariable.Any(r=> !char.IsLetterOrDigit(r));

您可以创建一个以TextBox为基础的控件,但是目前没有为您执行此操作的属性,您必须在textBox的KeyUp事件上执行此操作并使用正则表达式或类似的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取已知字符串和任何非字母数字字符之间的字符串 - Get string between a known string and any non-alphanumeric character 正则表达式删除字符串末尾的非字母数字字符,该字符也出现在字符串中的其他位置 - Regex to remove a non-alphanumeric character at the end of a string which also appears else where in the string 正则表达式考虑$以外的非字母数字字符 - Regex to consider non-alphanumeric character other than $ 如何在空格和其他非字母数字字符处拆分 - How to Split at Spaces and Other Non-Alphanumeric Character 检查字符串是否包含非字母数字(下划线除外) - Check if string contains non-alphanumeric except underscore 仅从字符串的开头和结尾删除非字母数字字符 - Remove non-alphanumeric characters from start and end of string only Read a non C# Apps textbox using windows API from a C# Windows forms App - Read a non C# Apps textbox using windows API from a C# Windows forms App 在 Windows 窗体中检查文本框 - Checking textBox in Windows Forms 正则表达式,允许用户输入字母数字字符和仅一个非字母数字字符 - Regular expression for allowing a user to enter alphanumeric characters and only one non-alphanumeric character 用于检查C#中的数字的TextBox方法 - TextBox method for checking numerics in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM