限制 [英] restriction
本文介绍了限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何限制用户在C#中输入特殊字符,字母和数字?
how can i restrict user from inputting special characters, letters and numbers in C#?
推荐答案
if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8 )
e.Handled = false;
else
e.Handled = true;
使用ASCII表设置要按下哪个键,不按下哪个键,此代码可用于仅输入数字数据并允许使用退格键.
use ASCII Table for set that which key you want to be pressed and whichone not, this code can be used for enter only numeric data and allow the backspace .
看看这个最近的问题和答案.这将为您提供帮助,因为显示了许多替代方案.
我应如何检查字母是A到Z还是A到Z [
Have a look at this recent question and the answers. This should help you since a lot of alternatives are shown.
how shall i check the letter is a to z or A to Z[^]
这篇关于限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文