Click here to Skip to main content
11,411,097 members (64,408 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB6 VB.NET GimmeCode
Sample codings to restrict special characters in vb6 & vb.net?
Posted 1-May-10 5:47am
Edited 1-May-10 6:11am
v2
Rate this: bad
good
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
    e.KeyChar=Nothing           
End If
  Permalink  
Comments
IndrajitDasgupat at 1-Mar-11 8:32am
   
But does not allow to paste
Rate this: bad
good
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;

}
else
{
e.Handled = false;

}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 204
1 Maciej Los 108
2 OriginalGriff 88
3 Sascha Lefévre 85
4 BillWoodruff 80
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,918
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 3 Sep 2010
Copyright © CodeProject, 1999-2015
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