正则验证数字

      /// <summary>
        /// 使用指定正则进行验证(只能输入数字)
        /// </summary>
        /// <param name="regex">正则表达式</param>
        /// <param name="validateString">待验证字符</param>
        /// <returns></returns>
        public static bool RegexValidate(string regexString, string validateString)
        {
            Regex regex = new Regex(regexString);
            return regex.IsMatch(validateString.Trim());
        }    

   if ( RegexValidate("^[0-9]*$", msgphone) == true) //"^[0-9]*$"
       { }
     else
      {
                    MessageBox.Show("格式不正确!");
                    return;
     }

posted on 2012-12-27 18:34  奋进中的╭★  阅读(117)  评论(0)    收藏  举报