Textbox Validation

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2007
Posts: 72
Reputation: geetajlo is an unknown quantity at this point 
Solved Threads: 0
geetajlo geetajlo is offline Offline
Junior Poster in Training

Textbox Validation

 
0
  #1
Jun 2nd, 2008
Hi i want to prevent the user from entering number and special charaters in a textbox and another textbox from entering alphabets and specials characters .....

Need it quickly coz 2moro have to submit my project...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Textbox Validation

 
3
  #2
Jun 2nd, 2008
This following code just allowed you to entered numbers only (No alphabetics or any special characters) :
  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2. If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
  3. Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
  4. e.Handled = True
  5. End If
  6. If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
  7. e.Handled = False
  8. End If
  9. End Sub

This following code just allowed you to entered strings / alphabetics only (no numbers or any special characters):
  1. Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
  2. If (Microsoft.VisualBasic.Asc(e.KeyChar) < 65) _
  3. Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 90) _
  4. And (Microsoft.VisualBasic.Asc(e.KeyChar) < 97) _
  5. Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 122) Then
  6. 'Allowed space
  7. If (Microsoft.VisualBasic.Asc(e.KeyChar) <> 32) Then
  8. e.Handled = True
  9. End If
  10. End If
  11. ' Allowed backspace
  12. If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
  13. e.Handled = False
  14. End If
  15. End Sub
Last edited by Jx_Man; Jun 2nd, 2008 at 8:33 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: Textbox Validation

 
0
  #3
Jun 3rd, 2008
To make text box to accept only numbers, in key press event of that textbox u can code like this


If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
MsgBox("Please enter valid number ")
End If


i think u can mannage other one..
Last edited by Pgmer; Jun 3rd, 2008 at 3:24 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: sabeerpasha is an unknown quantity at this point 
Solved Threads: 0
sabeerpasha sabeerpasha is offline Offline
Newbie Poster

Re: Textbox Validation

 
0
  #4
Mar 2nd, 2009
Originally Posted by geetajlo View Post
Hi i want to prevent the user from entering number and special charaters in a textbox and another textbox from entering alphabets and specials characters .....

Need it quickly coz 2moro have to submit my project...
--------
Use the following code..
#Region "TextBox Events"

Private Sub txtFinRefNo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFinRefNo.KeyPress
Try
If Char.IsLetterOrDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
End If
Catch ex As Exception
ShowException(ex.Message, MESSAGEBOX_TITLE, ex)
End Try
End Sub
#End Region

sabeer pasha.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC