Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

WIN Become a member Login Post Ask Question

  TECHNOLOGIES ANSWERS LEARN NEWS BLOGS VIDEOS INTERVIEW PREP BOOKS EVENTS CAREER MEMBERS JOBS C# Corner Search

LATEST BLOGS
Allowing only Alphanumeric Characters on a TextBox How Is UDP Server Di erent From TCP Server

Hemant Srivastava Updated date Nov 18, 2013 63.4k 8 3 Experimental Co-authoring for Power Apps Studio

How to become an author

Download Free .NET & JAVA O ce Files API Try Free File Format APIs for Word/Excel/PDF Basic Knowledge On Generics

If you don't want to allow any other characters entry except for the alphanumeric characters in a TextBox, then you can do this on the KeyPress
Azure - New Restrictions To Azurewebsites.net
Domain
event of a TextBox.

Di erence Between Azure SQL Geo Replication and


In the KeyPress Event, you need to check whether the entered character is either a Letter or a Digit.
Azure SQL Failover
 Char.IsLetterOrDigit(e.KeyChar)
Generate User Mapping For Sharegate Migration
Using PnP PowerShell
If yes, then allow the Key pressing by setting

Creating SPO Site Using Powershell


"e.Handled = false"

Referencing File Names In Power Automate


Otherwise, don't allow the Key pressing by setting "e.Handled = true"
Programmatically Fetching Files/Folders From Azure
In addition to the alphanumeric characters, generally one should allow the backspace character too along with the alphanumeric characters so Files
that the user can remove any wrong character if he entered by mistake.
View All

In order to do that, you need to add one more condition in the if block as

private void textBox_KeyPress(object sender, KeyPressEventArgs e)


{
    if (Char.IsLetterOrDigit(e.KeyChar)     // Allowing only any letter OR Digit
            ||e.KeyChar == '\b')                 // Allowing BackSpace character
    {
        e.Handled = false;
    }
    else
    {
        e.Handled = true;
    }
}

Allowing only Alphanumeric characters on a TextBox

Next Recommended Reading


Allow only Character to textbox

Hemant Srivastava 319 4.6m 2

http://hemant-srivastava.blogspot.com

3 8

Type your comment here and press Enter Key (Minimum 10 characters)

Very Helping Thanks..


Ammar Shaukat Aug 04, 2015
535 4k 852.8k 1 0 Reply

I don't get any working solution to restrict textbox to alphanumeric only in windows phone 8.1 app from the past 7
days. Can you suggest me any method to handle this. Thanks for the previous help.
Harshit Chauhan Jul 22, 2015
NA 0 0 1 0 Reply

How to add defenition of KeyChar in Windows. UI.Xaml.Input.KeyRoutedEventArgs or any other directive is to be


used... I am working on windows phone 8.1 project
Harshit Chauhan Jul 18, 2015
NA 0 0 1 1 Reply

I have no idea how it will be handled on Windows Phone project.


Hemant Srivastava Jul 20, 2015
319 7.3k 4.6m 1

How to restrict a user not to copy-paste text into the textbox


Harshit Chauhan Jul 18, 2015
NA 0 0 1 1 Reply

Generally this kind of validation I prefer to do on when you exit from the textbox (through validate event
on TextBox)
Hemant Srivastava Jul 20, 2015
319 7.3k 4.6m 1

how to use this method? mean to say where from to call this method . Which arguments i've to pass into the
function ?
Ammar Hassan Mar 30, 2015
NA 0 584 2 1 Reply

You need to attach an event handler "Key Press" on the TextBox in your Winform. Then you need to use
the above code in that event handler.
Hemant Srivastava Mar 31, 2015
319 7.3k 4.6m 1

About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners

C# Tutorials Common Interview Questions Stories Consultants Ideas Certi cations


©2021 C# Corner. All contents are copyright of their authors.

You might also like