Regular Expression For Alphanumeric

Regular Expression For Alphanumeric

Alphanumeric pattern Its very simple using regular expression to find specified pattern of string.
Here we will see how to validate string against alphanumeric pattern.

Lets see the code.

protected void Button4_Click(object sender, EventArgs e)
{
string pattern = "^[A-Za-z0-9]";
string input = "This is string  containing special character ! ";
Regex re = new Regex(pattern);
if(!re.IsMatch(input))        
Response.Write(string.Format(" {0} Is valid Alphanumeric string", input ));
else
Response.Write(string.Format(" {0} Is not valid Alphanumeric string", input ));
}

Description:
The input string contains “!” as a special character.
Pattern "^[A-Za-z0-9]" is used for validating string.

using System.Text.RegularExpressions; 

Above namespace is used for Regular expression pattern validation.

Instance of Regex constructor accepts the required pattern of expression.
IsMatch is instance method verifies whether string  contains pattern match or not.

You can also see how to get matched email string pattern by clicking on below link.

http://revenmerchantservices.com/post/Check-Email-Address.aspx

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5