C#窗口中的文本框验证 [英] Textbox Validation in C# windows

查看:64
本文介绍了C#窗口中的文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我应该验证文本框,以便在输入字母数字值后,如果最后一个值是数字,则不应将其视为char值.

例如如果我在123之后的文本框中输入abcd123,则它不应采用任何char值,而只能在末尾采用数字.文本框的KeyPress 事件,以下代码将允许您仅输入数字


if (char.IsDigit(e.KeyChar))
    e.Handled = false;
 else
    e.Handled = true;



只需添加一些计数器或Flag的逻辑,以检查char是否输入.
输入数字后,设置标志并仅允许数字值

Hi

I should Validation Textbox such that after entering alphanumeric values if last value is number it should not consider a char value.

For e.g. if I enter abcd123 in textbox after 123 it should not take any char value but it must take numbers only at the end.

解决方案

You can check it on KeyPress event of Textbox, following code will allow you to enter only numbers


if (char.IsDigit(e.KeyChar))
    e.Handled = false;
 else
    e.Handled = true;



Just add some logic of counter or Flag to check if char''s enter.
Once number entered set flag and allow only numeric values


这篇关于C#窗口中的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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