Click here to Skip to main content
15,909,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want validate code for using space key in textbox ,It can not accept the the entring space only
Posted
Updated 15-Nov-21 8:48am
Comments
OriginalGriff 3-May-12 3:01am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Maciej Los 3-May-12 3:07am    
Soiraian, please don't repost! Here is your previous - the same - question.

VB
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
 
Share this answer
 
Comments
Maciej Los 4-May-12 4:33am    
Good answer. My 5!
Use The Following Code :
VB
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

Or Else If you Just don't want to allow to enter Single Space in TextBox Use this one :
VB
IF Trim(TextBox1.Text)="" Then
    MessageBox.Show("Please Enter Data Here!")
Else
   'Else Code Goes Here
End If

I Hope It Will Help You!:)
 
Share this answer
 
Comments
Prasad_Kulkarni 4-May-12 2:14am    
Good one Manoj!
+5!
Manoj K Bhoir 4-May-12 23:58pm    
Thank You Prasad!
VJ Reddy 4-May-12 4:10am    
Good answer. 5!
Manoj K Bhoir 4-May-12 23:59pm    
Thank You VJ Reddy!
Maciej Los 4-May-12 4:34am    
Good answer. My 5!
Regular expression to accept only characters and spaces

regular expression=/^[a-zA-Z ]+$/
 
Share this answer
 
Comments
Maciej Los 3-May-12 3:58am    
Soiraian wrote: "not accept the the entring space". I think it means: without spaces ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900