Asp C# Regex for alphabet and numeric characters only

In this article I will show you how to accept only alphabet and numeric characters in asp .net c# using regex. Here is a label which contains alphanumric and special characters.

 

 

 

Now to use Regex in asp .net we need to add Namespace

using System.Text.RegularExpressions;

Using asp c# code behind
        //==== Create Regex object and pass pattern.
        Regex reg = new Regex(@"[^a-zA-Z0-9]");

        //===== Read Label value and replace all non alphabet and numeric characters with '-'
        string str = reg.Replace(lblValue.Text, "-");

        //==== Show output.
        Response.Write(str);

 

Output :

 Regex for alphabets and numbers asp c#

 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024 CodingFusion
50+ C# Programs for beginners to practice