Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些文本框映射到数据库中的主键字段,我不希望用户使用除英语或数字以外的任何语言进行书写,即使使用手动将输入语言切换为其他语言也是如此。我怎样才能达到同样的效果。我在 .net 2.0 上,所以没有花哨的东西。请帮忙。
您可以使用 . 检查您的输入Regex。此模式将匹配任何英文字母[a-zA-Z]
Regex
[a-zA-Z]
例如俄语 ю 将不匹配
Match m = Regex.Match("ю", "[a-zA-Z]");
处理 KeyPress 事件以实现所需的功能
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = !Regex.Match(e.KeyChar.ToString(), "[a-zA-Z]").Success; }