silverlight 文本框只能输入数字

void mobile_KeyUp(object sender, KeyEventArgs e)
        {
            Regex rg = new Regex("^[0-9]{1,11}$");
            Regex rg1 = new Regex("\b");
            if (!rg.IsMatch(mobile.Text) && !rg1.IsMatch(e.Key.ToString()))
            {
                if (mobile.Text.Length > 0)
                {
                    mobile.Text = mobile.Text.Substring(0, mobile.Text.Length - 1);
                    mobile.SelectionStart = mobile.Text.Length;
                }
                else
                {
                    mobile.Text = "";
                }
            }
        }
View Code

 

posted @ 2014-04-29 15:46  银河系上的地球  阅读(259)  评论(0编辑  收藏  举报