silverlight 文本框只能输入数字
时间:2014-04-30 13:32:53
收藏:0
阅读:409
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 = ""; } } }
评论(0)