Common Function to Validate Decimal Numbers in Text Box (Dot should be appear once in the text box)

Posted by Chikul under VB.NET category on | Views : 5251
'Usage : On KeyPress Event we Can call the function to Validate the Text Box.
'Parameter : Textbox & KeyPressEventArgs
'Output : It Handels when Dot entered 2 time in the text box

    Shared Sub ChkDot(ByVal ctxt As TextBox, ByVal x As System.Windows.Forms.KeyPressEventArgs)
If (Char.IsControl(x.KeyChar) Or Char.IsDigit(x.KeyChar) = True) Or x.KeyChar = "." Then
If ctxt.Text.IndexOf(".") <> -1 And x.KeyChar = "." Then
x.Handled = True
End If
x.Handled = True
End If
End Sub

Comments or Responses

Login to post response