WPF 输入框正则效验

1.

if (!TelphoneHelper2.IsTelphone(mobile)
{
MessageBox.Show("请录入正确的手机号!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}

2.TelphoneHelper2.cs

 public class TelphoneHelper2
    {
        public static bool IsTelphone(string tel)
        {
            String strExp = @"[0-9][0-9][0-9]{9}";
            Regex r = new Regex(strExp);
            Match m = r.Match(tel);
            return m.Success;
        }
    }

  

posted @ 2020-03-23 13:19  MrKing&  阅读(588)  评论(0编辑  收藏  举报