473,480 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to validate textbox control in vb.net?

1 New Member
i want validate my controls in vb.net for windows application..
what is the code for my text box accept only characters?
and also accept only numbers?
Aug 22 '07 #1
4 24185
sivisr
17 New Member
hi,
Use e.keychar to accept numeric or what ever you want.
Aug 22 '07 #2
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
i want validate my controls in vb.net for windows application..
what is the code for my text box accept only characters?
and also accept only numbers?
please see http://msdn2.microsoft.com/en-us/library/ms229644.aspx
U can use language filter to get it in vb .net :P
Aug 22 '07 #3
bhar
37 New Member
Hi,
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtCr_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCr.TextChanged
  2. If Not IsNumeric(txtCr.Text) And (txtCr.Text <> " ") Then
  3.     MsgBox("Not a Numeric Input! Try Again")
  4.     txtCr.Focus()
  5.     Exit Sub
  6. End If
  7. End Sub
  8.  
The above code checks whether numeric data is entered in the Credit text box control. The default event of the TextBox is the TextChanged Event. A textbox communicates that its contents have changed via the TextChanged event.

validating textbox control in C#.net

Expand|Select|Wrap|Line Numbers
  1. private void txtCr_TextChanged(object sender, EventArgs e)
  2. {
  3.     if (!(IsNumeric(this.txtCr.Text) == true) & (this.txtCr.Text != " "))
  4.     {
  5.         MessageBox.Show("Not a Numeric Input ! Try again");
  6.         txtCr.Focus();
  7.         return;
  8.     }
  9. }
  10.  
  11.  
  12. Or
  13.  
  14. you can try
  15.  
  16. private void txtCr_LostFocus(object sender, EventArgs e)
  17. {
  18.     if (!(IsNumeric(this.txtCr.Text) == true) & (this.txtCr.Text != " "))
  19.    {
  20.            MessageBox.Show("Not a Numeric Input ! Try again");
  21.            txtCr.Focus();
  22.            return;
  23.    }
  24.     else if (Convert.ToDouble(this.txtCr.Text) < 0)
  25.     {
  26.         MessageBox.Show(“Enter positive Amount”);
  27.         txtCr.Focus();
  28.         return;
  29.     }
  30. }
  31.  
The above code checks whether numeric data is entered in the Credit textbox controls. The LostFocus() event occurs when the input focus leaves the control. The Private void txtCr_LostFocus()event occurs when the input focus leaves the debit text box control.
Aug 22 '07 #4
rekhareddy
3 New Member
i want validate my controls in vb.net for windows application..
what is the code for my text box accept only characters?
and also accept only numbers?
hi this rekha
only accepting numbers only
the code is
Expand|Select|Wrap|Line Numbers
  1. If (e.KeyChar > Chr(47) And e.KeyChar < Chr(58)) Or e.KeyChar = Chr(46) Or e.KeyChar = Chr(8) Then
  2.         Else
  3.             e.KeyChar = ChrW(0)
  4.             Beep()
  5.         End If
Aug 25 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2615
by: Jeff Evans | last post by:
I have a custom composite control which has a validator for a textbox. The validator and textbox are declared in the class and created in the CreateChildControls() method Here is the code for the...
4
15668
by: owingruters | last post by:
Hi all, I've created an User control. It's an extension of a textbox wich has some extra properties so that validation becomes a lot faster. The control wordks great if autopostback is on....
11
2103
by: wolf | last post by:
There are three webcontrol on my asp.net form: a TextBox, a submit button and a RegularExpressionValidator. And I had set ControlToValidate property of the RegularExpressionValidator to the...
9
6645
by: B-Dog | last post by:
I have a form that has about 10 text boxes on it, they all have to be filled out before submitting is there a quick way to make sure that none are null or do I have to call out each textbox? Say...
11
11726
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
4
4855
by: Michel Posseth [MCP] | last post by:
I have a problem with the date time picker validate event wich i believe is a bug How to reproduce : throw on a form a date time picker control and a textbox control select the validating...
6
3363
by: Tony Girgenti | last post by:
Hello. Developing a VS2005, SP4, VB, .NET 2.0, ASP.NET 2.0, web site program using a calendar. I tried using the validators to see if i can validate dates using a calendar control. It does...
1
1857
by: satees | last post by:
Hi, I have a textbox control in Footer Template within datagrid. I need to validate the textbox using client side javascript. When trying it, i got an error that the control not exist. I think the...
2
1392
by: Moistly | last post by:
Hi everyone, This is a scenerio for my problem, I have one aspx page with several instances of the same Web User Control (ascx files). I have for example the Web User Control that has a...
1
6289
by: JFKJr | last post by:
Hello everyone, the following Access VBA code opens an excel file and creates textboxes in a given range of cells dynamically. The code attaches "MouseUP" and "Exit" events to the textboxes (using...
0
7054
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6918
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5357
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3008
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1310
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.