Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

numeric string

Posted on 2006-07-15
3
Medium Priority
?
294 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 1000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

885 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