我有一个文本框离开事件,以防止用户输入字母。它可以在任何地方工作,但是我有一个清除按钮可以清除文本框,它可以清除它,但是当文本框带有字母时,将无法清除它,单击清除按钮时我如何失去焦点,然后单击按钮,它将显示文本框包含字母时设置的错误消息
Private Sub InputNumberTextBox_Leave(sender As Object, e As EventArgs) Handles InputNumberTextBox.Leave
Dim Regex As String = "[a-zA-Z ]"
Dim Number As New Regex(Regex)
If Number.IsMatch(InputNumberTextBox.Text) Then
MsgBox("Cause - Please Enter Number Only" & vbCrLf & "Focus - Can't enter space" & vbCrLf &
"Clear - Do Not have space space when delete", vbExclamation, "Error For Alphabet and Space Bar")
InputNumberTextBox.Focus()
Name = False
Else
Name = True
End If
End Sub
Private Sub ClearNumberButton_Click(sender As Object, e As EventArgs) Handles ClearNumberButton.Click
Dim clear As MsgBoxResult
If Not InputNumberTextBox.Lines.Count = 0 Then
clear = MsgBox("Sure Want To delete All?", MsgBoxStyle.YesNo, "Delete Message")
If clear = MsgBoxResult.Yes Then
InputNumberTextBox.Text = ""
End If
Else
MsgBox("No Number To Clear", vbExclamation)
End If
End Sub
答案 0 :(得分:0)
而不是
async function findUserById(id: string) {
const sql = `
SELECT
user_id,
user_nme
FROM users WHERE user_id = ?;
`
return db('users').raw(sql, [id]);
}
写
InputNumberTextBox.Text = ""
或者您更改您的
InputNumberTextBox.Text = "0"
至
If Number.IsMatch(InputNumberTextBox.Text) Then
因此,在第一种情况下,存在一个中性数,并且验证事件未找到不匹配项。 在第二种情况下,您仅在文本框中确实有文本时才给出消息框
答案 1 :(得分:0)
假设我输入了“ 74”?它会通过您的正则表达式测试,但不是有效数字。正则表达式有一个地方,但是当您检查数字时,请使用适当的.TryParse
每个数字类型都有此方法。我随意选择了Integer数据类型。
由于将选择文本,因此不需要清除按钮。远程熟悉Windows的任何人都将知道Delete键,或者任何键都将删除现有文本。确保有一个将.CausesValidation
设置为false的退出按钮,否则您的用户将永远无法逃脱。
Private Sub InputNumberTextBox_Validating(sender As Object, e As CancelEventArgs) Handles InputNumberTextBox.Validating
Dim myInteger As Integer
If Not Integer.TryParse(InputNumberTextBox.Text, myInteger) Then
MessageBox.Show("Please enter a number")
e.Cancel = True
InputNumberTextBox.SelectAll()
Return
End If
'Continue processing the input
MessageBox.Show(myInteger.ToString)
End Sub