silverlight 文本框只能输入数字

时间:2014-04-30 13:32:53   收藏:0   阅读:409
bubuko.com,布布扣
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

 

silverlight 文本框只能输入数字,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!