10 replies
by brianmilke Accepted solution
by brianmilke Accepted solution
heres the code I am using to validate the TextBox.Text Input...
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
' Determines if input is number, or if it is a correct value 1 - 100
If Not IsNumeric(TextBox1.Text) Or Val(TextBox1.Text) < 0 Or Val(TextBox1.Text) > 100 Then
MessageBox.Show("Only use numbers 0 or 1 - 100", "Input Error")
'Selects the whole string as highlighted for deletion when next input is given
TextBox1.SelectionStart = 0
TextBox1.SelectionLength = TextBox1.Text.Length
' Determines if the cursor should return to the textbox for input change
e.Cancel = True
Else : e.Cancel = False
End If
End Sub
by whittle1gh Accepted solution
Private Sub BtnEnterDiesel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnterDiesel.Click
If Me.TxtUnitpriceDiesel.Text <> "" Then
If Me.TxtQtyDiesel.Text <> "" Then
If IsNumeric(Me.TxtQtyDiesel.Text) And IsNumeric(Me.TxtUnitpriceDiesel.Text) Then
Call addtankreadings()
Else : MsgBox("Must be in digits")
End If
Else : MsgBox("Quantity cannot be empty")
End If
Else : MsgBox("Enter the Unit Price")
End If
End Sub
by arvind.lnct Accepted solution
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) )
{
alert("Numeric Only");
return false;
}
return true;
}
on code-behind:
Textbox1.Attributes.Add("onkeypress", "return isNumberKey(event)")
by vaduganathanmaster Accepted solution
Why don't you valid the keys on KeyPress event with the help of IsDegit function to validate the current key is Numeric or not.
With the help of the decision you made either you can allow the key to proceed or not.
I hope this will resolve your requirement. However, if not, please do reply.
I will be glad to assist you.
by 93961 Accepted solution
by carl_batch2003 Accepted solution
Private Sub txtNotNumeric_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNotNumeric.KeyPress
If IsNumeric(e.KeyChar) Then
e.Handled = True
End If
End Sub
by 93961 Accepted solution
by 93961 Accepted solution
by tony hopkinson Accepted solution
This discussion is closed to new replies.
Trending Desktop posts
Sort by Trending