首页 > 代码库 > silverlight 文本框只能输入数字

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