如何验证Windows应用程序中的金额文本框 [英] How to validate amount textbox in windows application

查看:123
本文介绍了如何验证Windows应用程序中的金额文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows应用程序中。我有数量的文本框字段。它将接受总共11个小数点后2位。如果我没有输入小数位,它应该只允许8个位置。这将允许11个地方。如何写这个验证。我是新鲜的唐我有任何想法尝试。

请帮我这个。

提前致谢。



我尝试了什么:



我很新鲜,不知道尝试。

请帮助我。

提前谢谢。

In my windows application. I have amount textbox field.It will accept total 11 with 2 decimal places.If i didn't enter decimal places it should allow only 8 places.else It will allow 11 places.how to write validation for this.I'm fresher don't get any idea to try.
Please help me on this.
Thanks in advance.

What I have tried:

I'm fresher don't get any idea to try.
Please help me on this.
Thanks in advance.

推荐答案

你可以使用正则表达式验证,短搜索或阅读< a href =https://msdn.microsoft.com/en-us/library/ms996428.aspx>这个 [ ^ ]应该让你进入它。使用正则表达式匹配,您可以轻松实现检查并确保只放入数字。



另一方面,您可以通过验证插入的字符串来检查自己使用子字符串或包含。



例如检查字符串是否超过8个字符,然后检查字符串是否在第8(9)位包含'。' 。
You could use a regex validation on that, a short googling or reading of this[^] should get you into it. With a regex matching you could easily implement your check and make sure only numbers are put in.

On the other hand you could check by your self by validating the inserted string with substring or contains.

For example check if the string is longer than 8 chars and then check if the string contains a '.' at the 8th (9th) place.


private void txtamount_KeyPress(object sender, KeyPressEventArgs e)
       {
            string[] arr = txtamount.Text.Split('.');

           if (arr.Length == 1)
           {
               if (txtamount.Text.Length > 7 && e.KeyChar != '.' && e.KeyChar != (char)Keys.Back)
               {
                   e.Handled = true;
               }

           }
       }


这篇关于如何验证Windows应用程序中的金额文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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