使用Char.IsSymbol()方法防止符号,不包括数学运算符 [英] Prevent symbols using Char.IsSymbol() Method excluding mathematical operators

查看:207
本文介绍了使用Char.IsSymbol()方法防止符号,不包括数学运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望找到一种方法来防止我的vb.net windows窗体应用程序中的符号使用带有Char.IsSymbol()方法的datagridview,但是我希望仍然允许用户输入数学运算符到datagridview的。有没有办法阻止除数学运算符之外的所有符号?这是我到目前为止,它阻止所有符号,数学运算符,下标和上标。但是我希望在允许数学运算符的同时有一种简单的方法来阻止符号。感谢您提供的任何帮助或建议。



I'm hoping to find a way to prevent symbols in my vb.net windows forms application using a datagridview with the Char.IsSymbol() method, however I'm hoping to still allow the user to input mathmatical operators into the datagridview. Is there a way to prevent all symbols except mathmatical operators? Here is what I have so far, which prevents all symbols, math operators, subscripts and superscripts. However I'm hoping there is a simple way of preventing symbols while allowing math operators. Thanks for any help or suggestions you may offer.

If(columnindex = 0) Then ' checking value for column 1 only
Dim cellString = DataGridView1.Rows(rowindex).Cells(columnindex).value

If Char.IsSymbol(cellString)
MessageBox.Show("Special Characters Not Allowed")
End If
End If

推荐答案

无法改变IsSymbol的行为。



所以,你将不得不编写自己的方法确定什么是可接受的,什么不是。而不是黑名单已知字符,而是使用白名单。只接受你想要的字符,而不是试图过滤掉你不想要的所有字符。
There's no way to change the behavior of IsSymbol.

So, you're going to have to write your own method to determine what's acceptable and what's not. Instead of black-listing known characters, use a white-list instead. Accept only the characters you want instead of trying to filter out all the characters you don't.


这篇关于使用Char.IsSymbol()方法防止符号,不包括数学运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆