c# 正则表达式

1. 验证邮件的正则表达式
public static bool isEmail(string inputEmail)
{
inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}

2.验证输入的是否数字的方法
其实用正则表达式也可以 
static bool IsNumeric(string str) 
  { 
   if (str==null || str.Length==0) 
    return false; 
   foreach(char c in str) 
   { 
    if (!Char.IsNumber(c)) 
    { 
     return false; 
    } 
   } 
   return true; 
  } 

正则表达的写法是: 


static bool IsNumeric(string str)  
{   
   System.Text.RegularExpressions.Regex reg1  
       = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");   
   return reg1.IsMatch(str);  
}  
posted @ 2007-02-01 10:19  '.Elvis.'  阅读(172)  评论(0编辑  收藏  举报