实现效果:

使用正则表达是验证邮政编码

知识运用:

 使用正则表达是验证邮政编码

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {   
            //三目运算判断
            object bl = IsValidate(textBox1.Text.ToString()) == true ?
                MessageBox.Show("验证通过") : MessageBox.Show("验证失败");
        }
            //验证方法
        public bool IsValidate(string str_code) 
        {
            return System.Text.RegularExpressions.Regex.
                IsMatch(str_code,@"^\d{6}$");
        }

 

相关文章: