如何使用VB.NET在文本框中键入仅数字和仅一个十进制 [英] How can I type Numbers only and One Decimal Only in textbox using VB.NET

查看:80
本文介绍了如何使用VB.NET在文本框中键入仅数字和仅一个十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助!



我只想让我的文本框仅接受数字和仅接受一个小数点..当然Backspace和Delete按钮也应该有效。



这是我的代码





Please Help!

I just want my textbox to accept Numbers only and ONE Decimal point only.. of course Backspace and Delete button should working too.

here is my code


Private Sub txtCost_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCost.KeyPress
      If e.KeyChar <> ControlChars.Back Then
          e.Handled = Not (Char.IsDigit(e.KeyChar) Or e.KeyChar = ".")
      End If
  End Sub







请帮帮我..谢谢!




Please Help me.. thanks!

推荐答案

这样写......



Write like this..

e.Handled = Not (Char.IsDigit(e.KeyChar) OR e.KeyChar=".")





参考:

1)如何只允许在textbox vb.net中使用数字和点

2)常规表达(正则表达式)允许两位小数以及整数和正则表达式允许任何十进制数


得到了答案!







https://www.youtube.com/观看?v = Zr_p9GTVRfw [ ^ ] < br $>






谢谢大家!
got the answer from this!



https://www.youtube.com/watch?v=Zr_p9GTVRfw[^]



Thank you everyone!


这篇关于如何使用VB.NET在文本框中键入仅数字和仅一个十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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