使用正则表达式验证手机号码合法性

实现效果:

知识运用:

 

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            if (IsMobile(textBox1.Text.ToString()))
                MessageBox.Show("手机号码正确");
            else
                MessageBox.Show("输入的手机号不正确");
        }
        //验证方法
        public bool IsMobile(string str_mobile) {
            return System.Text.RegularExpressions.
                Regex.IsMatch(str_mobile,@"^[1][3-5,7-8]\d{9}$");
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/9977411.html