473,508 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to validate textbox accept only negative float numbers in .net

21 New Member
Hi,

Iam developing windows application using vb.net with c#.net.In this i want to validate textbox accept only negative float numbers like -2.3 etc....
please help me.
Aug 20 '08 #1
6 5290
r035198x
13,262 MVP
What have you tried so far?
Aug 20 '08 #2
madankarmukta
308 Contributor
HI,
You can use regular expression for this.. This is very effective to validate the any input from the user.

Thanks!
Aug 20 '08 #3
cloud255
427 Recognized Expert Contributor
A try catch statement trying to parse the input to a float will allow you to check if the number is a float. Then just multiply by -1 and see if the result is less than 0.
Aug 20 '08 #4
jodi
5 New Member
is this a windows app?

if it is, then you need to do something like this in the OnTextChanged event:

decimal dec;

decimal.TryParse(this.Text, out dec);

if (dec < 0)
Ok
else
whatever

if you want to put a mask on your textbox, you can try several there are in the net to be downloaded

tried google and the first seems to do what you want
http://www.csharphelp.com/archives2/archive305.html

cya
Aug 20 '08 #5
Plater
7,872 Recognized Expert Expert
It would probably be overkill, but there is a MaskedTextBox class in .NET for windows applications that could be used.
Aug 20 '08 #6
Curtis Rutland
3,256 Recognized Expert Specialist
How do you develop an app using "vb.net with C#.net"?
Aug 20 '08 #7

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

Similar topics

10
2973
by: KathyB | last post by:
Hi, I just can't get this quite right. I use the following function to validate a user entry. I need to allow negative numbers including those with decimals (e.g., -.5). The following allows the...
6
11332
by: Nobody | last post by:
How does one round a float? ie... 4.4 returns 4, while 4.5 returns 5. I see the floor and ceiling functions, but that floor would take 4.4 and return 4 and ceiling would return 5. I guess I could...
4
24189
by: tamilkumaran | last post by:
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?
4
8922
by: buntyindia | last post by:
Hi, I have a calculator with seven textBox to add Float numbers upto 2 decimal: I have created following function in js: function total_expenses() { // reteriving all the values from...
2
1539
by: danon | last post by:
Hi to you all I am a new to programming and i am looking to build a programme for my own garage. can any one help me please. 1 Can any one tell how i can programme a textbox to accept only...
1
3228
by: jennLovingmomof5 | last post by:
I need to validate a packslip using a mask. In the past I have validated that all characters are numbers and that the first one is not zero. Now they want to be able to set a mask, such as 9XX99999XX...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7061
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
5637
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,...
1
5057
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...
0
3208
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
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.