C#判断string格式

2008年11月28日星期五

C#判断string格式

using System;
using System.Text.RegularExpressions

public static bool IsNumeric(string value)
{
return Regex.IsMatch(value, @"^[+-]?\d*[.]?\d*$");
}
public static bool IsInt(string value)
{
return Regex.IsMatch(value, @"^[+-]?\d*$");
}
public static bool IsUnsign(string value)
{
return Regex.IsMatch(value, @"^\d*[.]?\d*$");
}
或者
public bool isnumeric(string str)
{
char[] ch=new char[str.Length];
ch=str.ToCharArray();
for(int i=0;i {
if(ch[i]<48 || ch[i]>57)
return false;
}
return true;
}


      0 评论:

      发表评论