Solved

numeric string

Posted on 2006-07-15
3
291 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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