Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Validate input to a textbox by only allowing 0-9, ...
Author:
Randy Wable
E-mail:
Click to e-mail author
Website:
http://randy.onet.net
Submitted:
2/15/2002
Version:
VB4, VB5, V
Compatibility:
VB4, VB5, VB6, VB.NET
Category:
Miscellaneous
Views:
15425
Validate input to a textbox by only allowing 0-9, a-z, and A-Z to be entered into it. All other characters are discarded.
Declarations:
'Create a Textbox named Text1
Code:
Private Sub text1_KeyPress(KeyAscii As Integer) If KeyAscii > 47 And KeyAscii <= 57 Then 'good Allow Numbers ElseIf KeyAscii > 64 And KeyAscii < 91 Then 'good Allow Capital Letters ElseIf KeyAscii > 96 And KeyAscii <= 122 Then 'good Allow lowercase Letters ElseIf KeyAscii = 8 Then 'good Allow user to use backspace Else 'not good KeyAscii = 0 MsgBox ("Invalid Character." & chr(13) & _ "Please enter 0-9, a-z, or A-Z") End If End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement