Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

numeric string

Posted on 2006-07-15
3
Medium Priority
?
292 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
[X]
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
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

688 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