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

实现效果:

知识运用:

 

实现代码:

        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}$");
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/9977306.html
今日推荐