Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / May 2008

Tip: Looking for answers? Try searching our database.

IsNumeric validation Compact Framework 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Malani Czornon - 08 May 2008 15:46 GMT
Hi, are there any function in C# to validate that the value from a textbox
to be numeric ?

Thanks in advance.
Chris Tacke, eMVP - 08 May 2008 16:07 GMT
Depending on your needs, most of the Parse functions would work:

int myval = int.Parse(textBox.Text);
float myval = float.Parse(textBox.Text);

etc.

Signature

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

> Hi, are there any function in C# to validate that the value from a textbox
> to be numeric ?
>
> Thanks in advance.
Malani Czornon - 08 May 2008 17:39 GMT
Thanks Chirs for your reply, but Parse doesn´t return true or false.... it
returns an expection....
I need to get a bool value...

> Depending on your needs, most of the Parse functions would work:
>
[quoted text clipped - 7 lines]
>>
>> Thanks in advance.
Chris Tacke, eMVP - 08 May 2008 17:46 GMT
I see.  That's way more complex then.

public bool IsInt(string value)
{
   try { int.Parse(value); }
   catch { return false; }
   return true;
}

Close to quantum physics.

Signature

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

> Thanks Chirs for your reply, but Parse doesn´t return true or false.... it
> returns an expection....
[quoted text clipped - 11 lines]
>>>
>>> Thanks in advance.
Serge Wautier - 08 May 2008 22:42 GMT
Chris,

Beware of quantum physics. This stuff is way too unstable to be used in a
beginner's program: Catching the exception is somehow measuring it, which
would bring Heisenberg and his uncertainty principle into the game. From
there on, false would no longer be sure whether he's actually as false as
that, which would probably lead to more exceptions being thrown randomly.
You'd probably need to include some statistical physics library into your
program to analyze the spectrum of these exceptions. Monte Carlo would
surely help. And that's where it hurts: Do Monte Carlo implementations
internally use bool results? Better not because they'd start colliding into
these other bools they are evaluating, which might actually lead to a bool
fission reaction. Which by globally destroying the whole binary system would
somehow solve the OP's concern the hard way (lack of any form of computer, I
mean). And all we wanted to do is to know if a string can be converted to an
int. I warned you: Unstable stuff, this quantum physics.

BTW, do you think this could be considered experimental evidence of the
butterfly effect? Someone should give it a try some day.

Serge.
http://www.apptranslator.com

>I see.  That's way more complex then.
>
[quoted text clipped - 22 lines]
>>>>
>>>> Thanks in advance.
Manoj Kumar - 09 May 2008 09:57 GMT
> Hi, are there any function in C# to validate that the value from a textbox
> to be numeric ?
>
> Thanks in advance.

Have you tried int.tryParse

int i = -1;
bool isNumeric = int.tryParse(textBox1.Text, out i);

If isNumeric is true then i holds numeric value.
Serge Wautier - 09 May 2008 10:17 GMT
No TryParse in CF :-(

HTH,

Serge.
http://www.apptranslator.com - Localization tool for your applications

On May 8, 7:46 am, "Malani Czornon" <pus...@aol.com> wrote:
> Hi, are there any function in C# to validate that the value from a textbox
> to be numeric ?
>
> Thanks in advance.

Have you tried int.tryParse

int i = -1;
bool isNumeric = int.tryParse(textBox1.Text, out i);

If isNumeric is true then i holds numeric value.
davebythesea - 09 May 2008 11:21 GMT
Hi,

Maybe creating your own control which inherits from TextBox and only allows
to input a number value or digit?

Dav

> Hi, are there any function in C# to validate that the value from a textbox
> to be numeric ?
>
> Thanks in advance.
Arun - 09 May 2008 19:09 GMT
May be something like this

class NumericTextBox : TextBox
   {
       protected override void OnKeyPress(KeyPressEventArgs e)
       {
           base.OnKeyPress(e);
           if (Char.IsDigit(e.KeyChar) ||
               Char.IsControl(e.KeyChar) ||
               (e.KeyChar == '\b'))
           {
               // Digits/Control commands/backspace are OK
           }
           else
           {
               // Swallow this invalid key
               e.Handled = true;
               return;
           }
       }
   }

or use setinputmode
http://msdn.microsoft.com/en-us/library/microsoft.windowsce.forms.inputmodeedito
r.setinputmode.aspx


Hope this helps,
Cheers,
Arun

On May 9, 3:21 am, davebythesea
<davebythe...@discussions.microsoft.com> wrote:
> Hi,
>
[quoted text clipped - 9 lines]
>
> - Show quoted text -
Arun - 09 May 2008 19:14 GMT
Better use word "Numeric TextBox" and do a google compact framework
group search
http://groups.google.com/advanced_group_search
you will get lots of threads discussed the same topic and few will
really help you.

Cheers,
Arun

> May be something like this
>
[quoted text clipped - 42 lines]
>
> - Show quoted text -
Malani Czornon - 12 May 2008 12:29 GMT
Thanks a lot to all!!
I´ll search the best way to do it.

Better use word "Numeric TextBox" and do a google compact framework
group search
http://groups.google.com/advanced_group_search
you will get lots of threads discussed the same topic and few will
really help you.

Cheers,
Arun

> May be something like this
>
[quoted text clipped - 46 lines]
>
> - Show quoted text -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.