C
ChrisB4024
Guest
Hello Everyone:
I have a set of text boxes that should only accept the following characters and conditions:
1) NUMBERS (0-9).
2) NEGATIVE SIGN (-), AND ONLY AS THE INITIAL INPUT. IF THEY DON'T START WITH IT ("-2" OR "-.5), THEN THEY CAN'T USE IT AT ALL (OBVIOUSLY SOMETHING LIKE "-4-2" ISN'T VALID).
3) DECIMAL POINT (ONLY ONE, ANYWHERE). IF IT'S THE FIRST POSITION, AUTOMATICALLY INSERT ZERO "0" IN FRONT.
Here's where the KEYPRESS code is at right now:
Private Sub txtE_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtE.KeyPress
'97 - 122 = Ascii codes for simple letters
'65 - 90 = Ascii codes for capital letters
'48 - 57 = Ascii codes for numbers
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back AndAlso _
e.KeyChar <> "-" Then
e.Handled = True
End If
End Sub
Tried a few things, but got nowhere. Insight would be great! Thanks.
Continue reading...
I have a set of text boxes that should only accept the following characters and conditions:
1) NUMBERS (0-9).
2) NEGATIVE SIGN (-), AND ONLY AS THE INITIAL INPUT. IF THEY DON'T START WITH IT ("-2" OR "-.5), THEN THEY CAN'T USE IT AT ALL (OBVIOUSLY SOMETHING LIKE "-4-2" ISN'T VALID).
3) DECIMAL POINT (ONLY ONE, ANYWHERE). IF IT'S THE FIRST POSITION, AUTOMATICALLY INSERT ZERO "0" IN FRONT.
Here's where the KEYPRESS code is at right now:
Private Sub txtE_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtE.KeyPress
'97 - 122 = Ascii codes for simple letters
'65 - 90 = Ascii codes for capital letters
'48 - 57 = Ascii codes for numbers
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back AndAlso _
e.KeyChar <> "-" Then
e.Handled = True
End If
End Sub
Tried a few things, but got nowhere. Insight would be great! Thanks.
Continue reading...