如果首先只取小数,我想验证一个文本框。没有0或任何数字(例如:.5不是0.5)请帮助我。提前致谢
答案 0 :(得分:0)
我拿了一个名为TextBox1的文本框,一个名为Button1的按钮在Button1的click事件上编写了以下代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim getstr As String = TextBox1.Text.Substring(0, 1)
If getstr = "." Then
MsgBox("Your input's first place is a '.' - validated.")
End If
End Sub
答案 1 :(得分:0)
这个功能怎么样......
Private Function do_validate(ByRef curr_textbox As TextBox) As Boolean
Dim to_return As Boolean = False
Try
Dim curr_input_text As String = curr_textbox.Text
If (Len(curr_input_text > 0)) Then
Dim left_most As String = Mid(curr_input_text, 1, 1)
If left_most = "." Then
to_return = True
End If
End If
Catch
Finally
Select Case to_return
Case True
curr_textbox.BackColor = Color.LightGreen
Case False
curr_textbox.BackColor = Color.LightPink
End Select
End Try
Return to_return
End Function
然后可以从TextBox.TextChanged事件调用它,就像这个do_validate(txt_input)一样。它也可以从提交按钮调用,作为验证序列的一部分。