Solved

numeric string

Posted on 2006-07-15
3
285 Views
Last Modified: 2010-04-16
Hi experts ..

string numeric = "2002901036";

Is There A Built-In Function That Check if a string is numeric or not ???
0
Comment
Question by:DrAske
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
mnasman earned 250 total points
Comment Utility
Hello,

There's no build in one for C#(there's one with vb.net)

but you could build one easily, look at this method


public bool IsNumber(string s)
            {
                  try
                  {
                        Double.Parse(s);
                        return true;
                  }
                  catch
                  {
                        return false;
                  }
            }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  if (IsNumber(textBox1.Text))
                        MessageBox.Show("Valid Number");
             else
                        MessageBox.Show("Not Valid Number");
            
            }

HTH,

Regards,
Mohammed Nasman
0
 
LVL 9

Author Comment

by:DrAske
Comment Utility
I made something similar ..
if(TxtCardNumber.Text == "" || checkNumeric(TxtCardNumber.Text) || TxtCardNumber.TextLength<16)
{
      MessageBox.Show("Enter The Valid Card Number .","Valid Number",MessageBoxButtons.OK);
      TxtCardNumber.ResetText();
      TxtCardNumber.Focus();
}

private bool checkNumeric(string check)
{
      foreach(char x in check)
      {
      if(!Char.IsNumber(x))
            return true;
      }
               return false;
}

But I think using try .. catch is better ..
Thanx Mohammad ;o)
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
You are welcome DrAske,

Glad to help you :o)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now