private string pattern = @"^[0-9]*$"; private string param = ""; private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { Match m = Regex.Match(this.textBox1.Text, pattern); if (!m.Success) { this.textBox1.Text = param; this.textBox1.SelectionStart = this.textBox1.Text.Length; } else { param = this.textBox1.Text; } }