Determining if a string can be converted to an integer or not?

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 1478
Write below code:-
public bool IsNumeric(string Text)
{
System.Text.RegularExpressions.Regex regularExpression = new System.Text.RegularExpressions.Regex("^-[0-9]+$|^[0-]+$");
return regularExpression.Match(Text).Success;
}

if (IsNumeric("1"))
Response.Write("Yes it's Numeric");
else
Response.Write("No it's a String");
Response.Write("<br/>");

if (IsNumeric("baba"))
Response.Write("Yes it's Numeric");
else
Response.Write("No it's a String");
Response.Write("<br/>");

Yes it's Numeric
No it's a String

Comments or Responses

Login to post response