Click here to Skip to main content
12,621,423 members (29,609 online)
Rate this:
 
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 18:32pm
Comments
aspdotnetdev 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:
  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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161128.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2016
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