限制 TextBox 中的逗号数量 [英] Limit the number of commas in a TextBox
本文介绍了限制 TextBox 中的逗号数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框的小问题.我希望它定价,但问题是我们可以输入多个逗号,这会使一切都不起作用.我想将逗号的数量限制为 1
I have a little problem with a textbox. I want it to take a price but the problem is that we can enter multiple commas which will make everything not work. I want to limit the number of commas to 1
这是我尝试过的:
If ("0123456789,\b".IndexOf(e.KeyChar) = -1) Then
If e.KeyChar <> Convert.ToChar(Keys.Back) Then
If (",".IndexOf(e.KeyChar) = -1) And txtPrix.Text.Contains(",") Then
e.Handled = False
Else
e.Handled = True
End If
End If
推荐答案
最可靠的是使用 Double.TryParse
或 Decimal.TryParse
:
The most reliable would be to use Double.TryParse
or Decimal.TryParse
:
Dim d = Double.MinValue
If Double.TryParse(txt.Text, d)
' it's a number
Else
' it's not a number
End If
这篇关于限制 TextBox 中的逗号数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文