.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Regular Expressions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

check alphanumeric string using Regular Expression

Posted By:Amit Mehra       Posted Date: November 25, 2008    Points: 10    Category: Regular Expressions    URL: http://www.dotnetspark.com  

Below is method to check whether the string contains alphanumeric value or not.This will be use ful when we dont want to insert Special character in database or we want to avoid special character from a string

Here is the solution use the below method to check the given string is alphanumeric or not

Note: You have to add RegularExpressions namespace to use this method

using System.Text.RegularExpressions;

private static bool CheckAlphaNumeric(string str)


return Regex.Match(str.Trim(), @"^[a-zA-Z0-9]*$").Success;



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend