Question Restrict numbers entered into textbox

kieran82

Member
Joined
Feb 21, 2010
Messages
19
Programming Experience
Beginner
I have a appointments program and the user must be over 18. I was wondering is there a way to restrict the numbers entered into a textbox to be from 18 to 100. can this be done with e.keychar
 
You could use this to restrict numbers:

VB.NET:
'Put under event "KeyPress"

Dim AllowedChars As String
AllowedChars = "0123456789_-qwertyuioplkjhgfdsazxcvbnm"
' If the character they have entered isn't in our list...
If InStr(AllowedChars, e.KeyChar.ToString) = 0 Then
	'Cancel the character
	e.Handled = True
End If

if this works for you
 
Back
Top