Home » questions » visual basic- how to validate input if alphanumeric and special characters are not allowed?

visual basic- how to validate input if alphanumeric and special characters are not allowed?

2006-08-11 09:03:22, Category: Programming & Design
valid: abcde invalid: 12345 a2c3e ~!@#$

Answers

  1. peekay

    On 2006-08-11 09:16:19


    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.
  2. mlw4428

    On 2006-08-11 09:44:18


    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.
  3. ag_iitkgp

    On 2006-08-11 09:39:32


    On Error GoTo Err: ' Validation Code Exit Sub Err: 'Error handler End Sub.
  4. cmr

    On 2006-08-11 21:32:11


    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.