Hi.
You can try also
public static bool IsOnlyDigits1(string text)
{
foreach (char ch in text)
{
if (!char.IsDigit(ch))
return false;
}
return true;
}
public static bool IsOnlyDigits2(string text)
{
for (int nIndex = 0; nIndex < text.Length; nIndex++)
{
if (!char.IsDigit(text, nIndex))
return false;
}
return true;
}
using System.Globalization;
public static bool IsOnlyDigits3(string text)
{
Int32 nTest
if (!Int32.TryParse(text, NumberStyles.None, CultureInfo.InvariantCulture,
out nTest))
return false;
return true;
}
The two functions using char.IsDigit should be the lightest possible.
The third ensures no decimal point or sign being accepted.
Regards,
Daniele.