Created
June 3, 2015 01:24
-
-
Save IsTheJack/ef7c9ca2ee45c5069b87 to your computer and use it in GitHub Desktop.
Regexp in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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