QA.TechInterviews.com - your tech questions answered
Visual Basic- How To Validate Input If Alphanumeric And Special Characters Are Not Allowed?

valid: abcde
invalid: 12345
a2c3e
~!@#$
Each and every character has its own unique ascii number.
I assume that you are using a text box to input the values.
Furthermore You do not want any Numbers. You can use the code below as well.It is written in key press event

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii <= 48 or KeyAscii >= 57) Then
Text1.Locked = False
Else
Text1.Locked = True
End If
End Sub

The number 0 has an ascii value of 48
1 has 49 and so on till 9 has 57.
Hence the above code

In case you want to know the ascii of any character
Use the following code in the keypress event


Private Sub Text1_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub

This will display the ascii of whatever key you have pressed.
alphanumerical?

if neither alphabetical (a-z), numerical (0-9), AND special characters (!£$#) are allowed - then what characters ARE allowed?

your question can't be answered until it is more clear unless i'm missing something.
I use Visual Studio .NET 2005 (.NET Framework 2.0), to do what you're asking is easy. I'd use a masked inputbox. I believe all VB have it. If not, at the very least I'd upgrade to .NET 2005.
On Error GoTo Err:

' Validation Code

Exit Sub

Err:

'Error handler

End Sub.
Each and every character has its own unique ascii number.
I assume that you are using a text box to input the values.
Furthermore You do not want any Numbers. You can use the code below as well.It is written in key press event

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii <= 48 or KeyAscii >= 57) Then
Text1.Locked = False
Else
Text1.Locked = True
End If
End Sub

The number 0 has an ascii value of 48
1 has 49 and so on till 9 has 57.
Hence the above code

In case you want to know the ascii of any character
Use the following code in the keypress event


Private Sub Text1_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub

This will display the ascii of whatever key you have pressed.

Back to QA. TechInterviews.com. Powered by Yahoo! Answers and TechInterviews.com community.