473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to Validate the Data while entering Data into textbox only for numeric values

Hi

I would like to validate the while entering the data in a textbox for numeric values.
it means . i would like to throw an error message when the user enters a character value. validation should happen while entering it self .

I am looking for the piece of code in VB.NET. Please do help me

Thanks
Dec 7 '07 #1
6 2760
dip_developer
648 Expert 512MB
Hi

I would like to validate the while entering the data in a textbox for numeric values.
it means . i would like to throw an error message when the user enters a character value. validation should happen while entering it self .

I am looking for the piece of code in VB.NET. Please do help me

Thanks
just write a function like the following

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Function checkForNumericInput(ByVal e As System.Windows.Forms.KeyPressEventArgs)
  3. If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) ) Then
  4. e.Handled = True
  5. MsgBox("Please Input Numbers Only", MsgBoxStyle.Critical)
  6. End If
  7. End Function
  8.  
Dec 7 '07 #2
Hi Thanks for ur code .. I can enter "." also . so i modified the code to allow "." But now i am able to enter "." multiple times .. its an amount field and "." should be entered only once.
Dec 7 '07 #3
debasisdas
8,127 Expert 4TB
Hi Thanks for ur code .. I can enter "." also . so i modified the code to allow "." But now i am able to enter "." multiple times .. its an amount field and "." should be entered only once.
Try to solve that yourself refering the sample provided by our expert in the previous post.
Dec 7 '07 #4
dip_developer
648 Expert 512MB
rightly said by debasisdas...please try it yourself for your betterment......i hope you can do....its fairly easy to validate multiple dots....put your brain....
Dec 7 '07 #5
Thanks for the replies . I solved it my self . I publish my questions here as i started learning .NET newly. Sorry if you people think , i am asking very much basic doubts. I'm learning it on my own. i dont know much in VB.NET.
Dec 8 '07 #6
Private Sub MyTextbox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If Char.IsDigit(e.KeyChar) = True Or e.KeyChar = Chr(Keys.Back) Then
Exit Sub
Else
e.Handled = True
MessageBox.Show("PLEASE ENTER ONLY NUMERIC VALUE.")
End If
End Sub
Dec 10 '07 #7

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

Similar topics

2
by: sp | last post by:
Hello Everybody, How can I restrict the user entering non-numeric data in textbox control on server side using asp.net. Any Code sample or suggestions are appreciated. Thanks in advance sp
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I am converting Excel data into a Dataset in C#. There are around 24 columns in the Excel Sheet. First I tried to insert one row with correct values in the Excel sheet. i.e. for text columns...
5
tolkienarda
by: tolkienarda | last post by:
hi all i am trying to stop people from entering anything but numbers into a textbox. i have the code to make sure they have entered a number on each keypress event and now a msgbox appears if they...
0
by: PerumalSamy | last post by:
Hi In my project i need to validate a multiline textbox rowcount after entering the data. For Ex: They need to enter 3 line as address(in which 2 line feed is compulsory). How can i check...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.