Please refer this
Enter Text:
<asp:TextBox ID="txtText" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" OnClick="Validate_AlphanumericOrNumeric"
Text="Validate" />
C#
protected void Validate_AlphanumericOrNumeric(object sender, EventArgs e)
{
System.Text.RegularExpressions.Regex numeric = new System.Text.RegularExpressions.Regex("^[0-9]+$");
System.Text.RegularExpressions.Regex alphanemeric = new System.Text.RegularExpressions.Regex("^[a-zA-Z0-9]*$");
System.Text.RegularExpressions.Regex alphabets = new System.Text.RegularExpressions.Regex("^[A-z]+$");
string IsAlphaNumericOrNumeric = string.Empty;
if (numeric.IsMatch(txtText.Text))
{
isAlphanumericOrNumeric = "Numeric only";
}
else
{
if (alphabets.IsMatch(txtText.Text))
{
isAlphanumericOrNumeric = "Alphabet only";
}
else if (alphanemeric.IsMatch(txtText.Text))
{
isAlphanumericOrNumeric = "Alphanumeric";
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(' Entered text is " + isAlphanumericOrNumeric + "')", true);
}