Use Integer.Parse to check : Number : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » Number »

 

Use Integer.Parse to check









    

using System;
using System.Data;
using System.Text.RegularExpressions;

class Class1{
        static void Main(string[] args){
      string IsNotNum = "111west";
      string IsNum = "  +111  ";
      string IsFloat = "  23.11  ";
      string IsExp = "  +23 e+11  ";
      
      Console.WriteLine(IsIntegerRegEx(IsNum));    // True
      Console.WriteLine(IsIntegerRegEx(IsNotNum));  // False
      Console.WriteLine(IsIntegerRegEx(IsFloat));    // False
      Console.WriteLine(IsIntegerRegEx(IsExp));    // False
        }
    public static bool IsIntegerRegEx(string str)
    {
      str = str.Trim();
      return (Regex.IsMatch(str, @"^[\+\-]?\d+$"));
    }

}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» Number