Check whether variable value is Numeric or not.

Tripati.patro
Posted by Tripati.patro under C# category on | Points: 40 | Views : 2807
private void NumericCheckMethod()
{
var inputString = "DotNetFunda";
if (!IsNumeric(inputString))
{
MessageBox.Show("Valid WebSite.");
}
var fundaUserId = "12345";
if (IsNumeric(fundaUserId))
{
MessageBox.Show("Valid User.");
}
}

/// <summary>
/// Check whether a provided input is numeric or not.
/// </summary>
/// <param name="input"></param>
/// <returns>True: if input is numeric</returns>
private bool IsNumeric(object input)
{
var isNumeric = false;
int actualValue;
if (input != null && int.TryParse(input.ToString(), out actualValue))
{
isNumeric = true;
}

return isNumeric;
}

Comments or Responses

Login to post response