C#中文本框中的Custome输入格式 [英] Custome input format in textbox in C#

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

问题描述

大家好

如何制作一个接受前4个字母的文本框,之后7个数字另外给用户一个错误



i不知道该怎么办请把我放在正确的方向



我尝试过的事情:



i试图使用蒙面文本框,但它不起作用



if(!System.Text.RegularExpressions.Regex.IsMatch(e .KeyChar.ToString(),\\\\ +))

e.Handled = true;

解决方案

仅限你的正则表达式适用于数字,并不关心有多少,只要字符串中至少有一个。

试试这个:

 ^ [A-ZA-Z] {4} \d {7} 


 if(txtContainerNo.TextLength< 4)
{
e.Handled =!(char.IsUpper(e.KeyChar)|| e.KeyChar ==(char)Keys.Back) ;


}

其他
{
e.Handled =!(char.IsDigit(e.KeyChar)|| e.KeyChar ==(char)Keys.Back);
}


Hi Everyone
How can i Make a textbox that accepts at first 4 letters and after that 7 digits otherwise give the user an error

i have no idea what to do please put me on the right direction

What I have tried:

i tried to use masked textbox but it didn't work

if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
e.Handled = true;

解决方案

Your regex only works for digits, and doesn't care how many there are ,provided there is at least one somewhere in the string.
Try this:

^[a-zA-Z]{4}\d{7}



if (txtContainerNo.TextLength < 4)
         {
             e.Handled = !(char.IsUpper(e.KeyChar) || e.KeyChar == (char)Keys.Back);


         }

         else
         {
             e.Handled = !(char.IsDigit(e.KeyChar) || e.KeyChar == (char)Keys.Back);
         }


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

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