본문 바로가기

Web_Application/C#

[c#][winform] textbox 숫자만 입력 받기



private void textbox1_TextChanged(object sender, EventArgs e)
{
// 소숫점(.), 자리수(,)는 허용하고 기타 문자가 있으면 입력 초기화. 다른 특수문자를 허용하려면 숫자 뒤에 붙이기
if (Regex.IsMatch(textbox1.Text, "[^0-9.,]")){
textbox1.Text = "";
}
}