| | |
Textbox Validation
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
This following code just allowed you to entered numbers only (No alphabetics or any special characters) :
This following code just allowed you to entered strings / alphabetics only (no numbers or any special characters):
vb.net Syntax (Toggle Plain Text)
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then e.Handled = True End If If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If End Sub
This following code just allowed you to entered strings / alphabetics only (no numbers or any special characters):
vb.net Syntax (Toggle Plain Text)
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress If (Microsoft.VisualBasic.Asc(e.KeyChar) < 65) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 90) _ And (Microsoft.VisualBasic.Asc(e.KeyChar) < 97) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 122) Then 'Allowed space If (Microsoft.VisualBasic.Asc(e.KeyChar) <> 32) Then e.Handled = True End If End If ' Allowed backspace If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If 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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Apr 2008
Posts: 54
Reputation:
Solved Threads: 5
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..
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.
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- Validation help (Visual Basic 4 / 5 / 6)
- for validation - text box and drop down menu (JavaScript / DHTML / AJAX)
- Validation difficulties *sigh* (ASP.NET)
- Validation function (Visual Basic 4 / 5 / 6)
- validating a textbox without using validation control (ASP.NET)
- Javascript, Form fields validation and submit (JavaScript / DHTML / AJAX)
Other Threads in the VB.NET Forum
- Previous Thread: VB.NET and Excel
- Next Thread: Insert from DataGridView
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons c# center check checkbox code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp google hardcopy image images inline insert listview login math memory mobile ms navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problemwithinstallation project reports" save savedialog searchbox serial server soap sql string table tcp text textbox timer toolbox trim update updown upload usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf






