470,624 Members | 2,393 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,624 developers. It's quick & easy.

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


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 5117
13,262 8TB
What have you tried so far?
Aug 20 '08 #2
308 256MB
You can use regular expression for this.. This is very effective to validate the any input from the user.

Aug 20 '08 #3
427 Expert 256MB
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
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)

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

Aug 20 '08 #5
7,872 Expert 4TB
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 Expert 2GB
How do you develop an app using "vb.net with C#.net"?
Aug 20 '08 #7

Post your reply

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

Similar topics

6 posts views Thread by Nobody | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.