2011-09-05 4 views

답변

0

이 질문은 다소 모호하지만 나는 당신이 무엇을 요구하고 있는지 이해하고 있다고 생각합니다. 숫자 만 허용하려면 KeyPress 이벤트 당신이 입력되어 있는지 데이터를 만들기 위해 어떤 점에서 상자를 유효성을 검사 할 가정

private void TextBox_KeyPress(object sender, KeyPressEventArgs e) 
{ 
    if (Char.IsDigit(e.KeyChar)) 
    { 
    e.Handled = true; 
    } 
    else 
    { 
    MessageBox.Show("Textbox must be numeric only!"); 
    } 
} 

을 사용할 수 있습니다. 이렇게하려면 다음과 같은 것을 사용하십시오 :

private bool CheckTextBox(TextBox tb) 
{ 
    if(string.IsNullOrEmpty(tb.Text)) 
    { 
    MessageBox.Show("Textbox can't be empty!"); 
    return false; 
    } 

    return true; 
} 
+0

도와 줘서 정말 고마워. –

2

ASP.NET의 경우 RegularExpressionValidatorRequiredFieldValidator 컨트롤을 사용하여 다시 게시시 입력을 확인합니다. e so.

<asp:TextBox ID="numericTextBox" runat="server"></asp:TextBox> 
<asp:RegularExpressionValidator ID="regularExpressionValidator" runat="server" ControlToValidate="numericTextBox" ValidationExpression="[0-9]+" ErrorMessage="Please enter a valid numeric value"></asp:RegularExpressionValidator> 
<asp:RequiredFieldValidator ID="requiredFieldValidator" runat="server" ControlToValidate="numericTextBox" ErrorMessage="Please enter a numeric value"></asp:RequiredFieldValidator> 

윈폼를 들어 당신은 NumericUpDown 컨트롤의 사용은 숫자 값 입력을 constain 할 수 있습니다.

관련 문제