| View previous topic :: View next topic |
| Author |
Message |
cildor666 Advanced Cheater
Reputation: 0
Joined: 08 Mar 2008 Posts: 95
|
Posted: Wed Sep 24, 2008 10:31 am Post subject: Way to only allow numbers in a text box? |
|
|
I'm using Visual Basic 2008 Express.
Is there a way to only allow numbers in a text box, so if i click a button it pops up saying 'Not numeric!" when there is text typed into the box.
Thanks for any help.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Wed Sep 24, 2008 11:15 am Post subject: |
|
|
you can start a timer / thread and set it to 1 (ms) and check if one of the chars in the text field isn't numberic
_________________
Stylo |
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Wed Sep 24, 2008 11:29 am Post subject: |
|
|
| 1qaz wrote: | | you can start a timer / thread and set it to 1 (ms) and check if one of the chars in the text field isn't numberic | Or, put a the check in the TextChanged event.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
cildor666 Advanced Cheater
Reputation: 0
Joined: 08 Mar 2008 Posts: 95
|
Posted: Wed Sep 24, 2008 12:06 pm Post subject: |
|
|
Thanks for the help guys but i figured out a different way.
| Code: | Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim allowedChars As String = "0123456789"
If allowedChars.IndexOf(e.KeyChar) = -1 Then
MsgBox("Only numbers are allowed.", MsgBoxStyle.Information)
e.Handled = True
End If |
Is there any way to allow backspace in the 'Dim allowedChars As String = "0123456789" ??
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Wed Sep 24, 2008 3:30 pm Post subject: |
|
|
| Code: | Private Sub Text1_Change()
If IsNumeric(Text1.Text) = False Then
MsgBox "Numbers only"
End If
End Sub |
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
|