验证文本框以避免字母和其他字符 [英] Validation for Textbox to avoid alphabets and other characters

查看:86
本文介绍了验证文本框以避免字母和其他字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi frnds,

如何用数字验证文本框.用户不应输入字母或其他字符...只能输入$数字编号.

用户只能输入4位数字作为2010.

所以,我们该怎么做,您有想法吗,请给我一个好的解决方案.

谢谢.

hi frnds,

how to validate the Textbox with numbers. User should not enter alphabets or other characters...ONLY HE SHOULD ENTER $ DIGIT NUMBER.

user must enter only 4 digits as 2010.

So, how can we do this, do u have idea, please give me a good solution.

Thanks.

推荐答案

数字编号.

用户只能输入4位数字作为2010.

所以,我们该怎么做,您有想法吗,请给我一个好的解决方案.

谢谢.
DIGIT NUMBER.

user must enter only 4 digits as 2010.

So, how can we do this, do u have idea, please give me a good solution.

Thanks.


尝试一下:
Try this:
void CharacterValidation(object sender, KeyPressEventArgs e)
       {
           if ((e.KeyChar >= 65 && e.KeyChar <= 90) || (e.KeyChar >= 97 && e.KeyChar <= 122) || e.KeyChar == 32 || e.KeyChar == 8 || e.Keychar != 36)
           {
               e.Handled = false;
           }
           else
           {
               e.Handled = true;
           }
       }



用户只能输入4位数字作为2010.
您需要设置textBox1.MaxLength = 4;



user must enter only 4 digits as 2010.
You need to set textBox1.MaxLength = 4;


这篇关于验证文本框以避免字母和其他字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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