正则表达式数据验证
1 // 判断是否为邮编 2 public static bool IsPostalcode(string strPostcode) 3 { 4 if (strPostcode == null) return false; 5 else return Regex.IsMatch(strPostcode, @"^\d{6}$"); 6 }
1 /// <summary> 2 /// 判断邮箱是否有效 3 /// </summary> 4 /// <param name="cardNum">邮箱地址</param> 5 /// <returns></returns> 6 public static bool CheckCardMail(string cardNum) 7 { 8 var cardExp = new Regex(@"^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)$"); 9 10 return cardExp.Match(cardNum).Success; 11 }