C#验证整数

         /// <summary>
        
/// 验证是否是整数
        
/// </summary>
        
/// <param name="lstr">string</param>
        
/// <returns>bool</returns>

         public   static   bool  isNumberR( string  lstr) 
        

            
string pat = @"^(d{1,9}$)";
            Regex r
=new Regex(pat,RegexOptions.Compiled);
            Match m
=r.Match(lstr);

            
if(!m.Success)
            
{
                
return false;
            }

            
return true;
        }
    


        
/// <summary>
        
///验证是否是整数
        
/// </summary>
        
/// <param name="str">string</param>        
        
/// <returns>bool</returns>

         public   static   bool  IsNum( string  str)
        
{
            
bool flag = true;
            
try
            
{
                Int32.Parse(str);                
            }

            
catch(FormatException)
            
{
                flag 
= false;
            }

            
return flag;
        }

 

你可能感兴趣的:(String,C#,regex)