using System.Text.RegularExpressions; public static bool IsValidData( string strData) ... { 正则表达式#region 正则表达式 // ^d+$ //匹配非负整数(正整数 + 0) //^[0-9]*[1-9][0-9]*$ //匹配正整数 //^((-d+) ¦(0+))$ //匹配非正整数(负整数 + 0) //^-[0-9]*[1-9][0-9]*$ //匹配负整数 //^-?d+$ //匹配整数 //^d+(.d+)?$ //匹配非负浮点数(正浮点数 + 0) //^(([0-9]+.[0-9]*[1-9][0-9]*) ¦([0-9]*[1-9][0-9]*.[0-9]+) ¦([0-9]*[1-9][0-9]*))$ //匹配正浮点数 //^((-d+(.d+)?) ¦(0+(.0+)?))$ //匹配非正浮点数(负浮点数 + 0) //^(-(([0-9]+.[0-9]*[1-9][0-9]*) ¦([0-9]*[1-9][0-9]*.[0-9]+) ¦([0-9]*[1-9][0-9]*)))$ //匹配负浮点数 //^(-?d+)(.d+)?$ //匹配浮点数 //^[A-Za-z]+$ //匹配由26个英文字母组成的字符串 //^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串 //^[a-z]+$ //匹配由26个英文字母的小写组成的字符串 //^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串 //^w+$ //匹配由数字、26个英文字母或者下划线组成的字符串 //^[w-]+(.[w-]+)*@[w-]+(.[w-]+)+$ //匹配email地址 //^[a-zA-z]+://匹配(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$ //匹配url #endregion strRegex = "^(-?d+)(.d+)?$"; // 匹配浮点数 return Regex.IsMatch(strData, strRegex); }