Click here to Skip to main content
12,826,621 members (22,126 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB6 VB VB.NET
Sample codings to restrict special characters in vb6 &
Posted 1-May-10 5:47am
Updated 1-May-10 6:11am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

They are not the only way, one od the ways to do them...

VB6: Use Ascii values the way you want! Ex:
Option Explicit

'This will only accepts the alphabets and no other key is allowed.
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If Not KeyAscii >= 65 And KeyAscii < 90 Then
        KeyAscii = 0
    End If
End Sub

VB.NET: Use KeyPressed for validation...
'Textbox KeyPress
' Allow number 0-9 plus backspace, Del + Home + End will be accepted also
Dim ValidInputChar = "0123456789." + vbBack
If not ValidInputChar.Contains(e.KeyChar) then
End If
IndrajitDasgupat 1-Mar-11 8:32am
But does not allow to paste
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This function restrict user from inserting special characters

if ((!char.IsLetterOrDigit(e.KeyChar))&&(!(e.KeyChar==(char)Keys.Back)))
e.Handled = true;

e.Handled = false;


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 3 Sep 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100