Skip to content

Instantly share code, notes, and snippets.

@IsTheJack
Created June 3, 2015 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IsTheJack/ef7c9ca2ee45c5069b87 to your computer and use it in GitHub Desktop.
Save IsTheJack/ef7c9ca2ee45c5069b87 to your computer and use it in GitHub Desktop.
Regexp in C#
using System;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void OnlyNumbers(TextBox txt)
{
txt.Text = Regex.Replace(txt.Text, @"[^\d]", "");
//txt.Select(txt.Text.Length, 0);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox text = sender as TextBox;
OnlyNumbers(text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment