Checks if string has only numbers - CSharp System

CSharp examples for System:String Number

Description

Checks if string has only numbers

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*  ww w.  j a v a  2s  . co  m*/

public class Main{
        //Checks if string has only numbers
        //12453 -> True
        //234d3 -> False
        public static bool IsNumeric(string input)
        {
            for (int i = 0; i < input.Length; i++)
            {
                if (!(Convert.ToInt32(input[i]) >= 48 && Convert.ToInt32(input[i]) <= 57))
                {
                    //Not integer value
                    return false;
                }
            }
            return true;
        }
}

Related Tutorials