正则表达式集锦

 if (Regex.IsMatch(string input , string pattern )) 

   string phone= @"^(13[0-9]|15[0-9]|18[0|2|5|6|7|8|9])\d{8}$"; //手机号码
        string email = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";//E_mail
        string cardID1s = @"^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$";//15位身份证号
        string CardID2 = @"^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}[0-9]|X$"; //18位身份证号

 public s Boolean IsDate(String text)  //验证日期合法性
    {
        try
        {
            Boolean valid = false;
            valid = Regex.IsMatch(text, @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29))$");
            return valid;
        }
        catch (Exception ex)
        {
            throw new ApplicationException("Utility.Validator.IsDate:" + ex.Message);
        }
    }

posted on 2011-08-03 14:41  缘来  阅读(152)  评论(0)    收藏  举报

导航