using System.Text.RegularExpressions;
// 텍스트박스에 한글만 입력하기
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if((Char.IsPunctuation(e.KeyChar) || Char.IsDigit(e.KeyChar) || Char.IsLetter
(e.KeyChar) || Char.IsSymbol(e.KeyChar)) && e.KeyChar != 8)
{
e.Handled = true;
}
}
// 텍스트 박스에 영문만 입력하기
private void textBox1_Leave(object sender, System.EventArgs e)
{
Regex emailregex = new Regex(@"[a-zA-Z]");
Boolean ismatch = emailregex.IsMatch(textBox1.Text);
if (!ismatch)
{
MessageBox.Show("영문자만 입력해 주세요.");
}
}
// 텍스트 박스에 숫자만 입력하기
// textBox1의 문자 중 숫자를 없앤다.
string str = Regex.Replace(this.textBox1.Text, @"[0-9]", "");
if(str.Length > 0)
MessageBox.Show(“숫자외 문자가 존재합니다.“);
else
MessageBox.Show(“숫자로만 구성되어있습니다.“);
'닷넷 프레임워크' 카테고리의 다른 글
[C#] 실행시간 측정 (0) | 2009.10.20 |
---|---|
MDB에서 쿼리문에 이상이 없는데도 구문 오류가 발생할 경우 (0) | 2009.09.24 |
C# Thread 이야기 (0) | 2009.09.22 |
Creating a splash screen (0) | 2009.07.15 |
DataGridView 소개 (1) | 2009.07.13 |