Click here to Skip to main content
11,581,186 members (69,070 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I have a textbox that is handled by a keypress. I want the textbox must accept only alphabet, numbers and allowing him to press the backspace.

my regular expression is ([^a-zA-Z0-9])

but the backspace does not work

thanks for any fast reply

THANKS
Posted 28-Sep-10 17:32pm
Comments
aspdotnetdev at 29-Sep-10 0:59am
   
Show us your code... e.g., which event you are using and how you are passing the key to the regular expression.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Backspace generally works for any regex validation as reg validation is invoked for the string.

You can try
http://www.siteexperts.com/tips/functions/ts23/page1.asp[^]

for entire regex list.

Rose | [Rose]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try by changing this Regex from

[^a-zA-Z0-9]

to

^[a-zA-Z0-9[\b]]

Hope this will work.

Please vote and Accept Answer if it Helped.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I hope you can accept an answer from a vb.net user.

private void TextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
 
    if (char.IsLetter(Strings.ChrW(e.KeyCode)) | Information.IsNumeric(Strings.ChrW(e.KeyValue)) | char.IsControl(Strings.ChrW(e.KeyValue))) {
 
    } else {
        e.SuppressKeyPress = true;
 
    }
 
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 250
1 Frankie-C 185
2 Sergey Alexandrovich Kryukov 85
3 Dave Kreskowiak 83
4 F-ES Sitecore 80
0 OriginalGriff 1,183
1 Sergey Alexandrovich Kryukov 825
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 29 Dec 2012
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