Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
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.

 
Share this answer
 
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:
 
Share this answer
 
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.
 
Share this answer
 
I hope you can accept an answer from a vb.net user.

C#
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;

    }

}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900