Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

numeric string

Posted on 2006-07-15
3
288 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:
Mohammed Nasman earned 250 total points
ID: 17113810
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
ID: 17113830
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:Mohammed Nasman
ID: 17113835
You are welcome DrAske,

Glad to help you :o)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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