Click here to Skip to main content
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 278
1 Maciej Los 205
2 DamithSL 193
3 Nguyen.H.H.Dang 190
4 arvind mepani 187


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid