验证代码以在文本框中使用空格键 [英] validate code for using space key in textbox
本文介绍了验证代码以在文本框中使用空格键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要验证文本框中使用空格键的代码,它不能仅接受输入空格
I want validate code for using space key in textbox ,It can not accept the the entring space only
推荐答案
Private Sub txtTExtBoxName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtItemCode.KeyPress
If Asc(e.KeyChar) = Keys.Space Then
MessageBox.Show("Add some stuff here")
End If
End Sub
使用以下代码:
Use The Following Code :
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar)
Case 32 '32-KeyChar Of Space
e.Handled = True
MessageBox.Show("You Can Not Enter Space Here!")
Case Else
'Else Code Goes Here
End Select
End Sub
否则,如果您只是不想允许在TextBox中输入单个空格,请使用此空格:
Or Else If you Just don''t want to allow to enter Single Space in TextBox Use this one :
IF Trim(TextBox1.Text)="" Then
MessageBox.Show("Please Enter Data Here!")
Else
'Else Code Goes Here
End If
希望对您有所帮助!:)
I Hope It Will Help You!:)
正则表达式仅接受字符和空格
正则表达式=/^ [a-zA-Z] +
Regular expression to accept only characters and spaces
regular expression=/^[a-zA-Z ]+
这篇关于验证代码以在文本框中使用空格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文