I trimmed the routine a little, now instead of doing string comparisons on every character I just typecast to an integer and only do string comparions if the value of the int is zero.
Edit2: Added check if string passed contains just a single minus sign "-", reordered nested if's more logically.
Edit3: oop I borked it, fixed now though :p ok ok I quit!
CODE
// isNumeric() checks a given string to see if it IS numeric
// It allows for negative values and floats.
// isNumeric() returns FALSE if the given string isn't numeric
// else it returns TRUE.
// Input (string) ending with a period is considered NON-numeric. (eg: "12.")
integer isNumeric(string sInput)
{
integer nLen = llStringLength(sInput) - 1; // len, zero based
string sChr;
integer nDecimalCount = 0;
integer nLoopCount = 0;
// initially check first char for "-" (negative, ignore (increment loopcounter)
if (llGetSubString(sInput, 0, 0) == "-")
{
nLoopCount = 1;
if (nLoopCount > nLen) return FALSE; // string passed is a single character "-"
}
while (nLoopCount <= nLen)
{
sChr = llGetSubString(sInput, nLoopCount, nLoopCount);
if ((integer)sChr == 0)
{
if (sChr == ".")
{
++nDecimalCount;
// if more than 1 ".", OR last character is a ".", false!
if (nDecimalCount > 1 || nLoopCount == nLen) return FALSE;
}
else if (sChr != "0")
{
return FALSE;
}
}
++nLoopCount;
}
return TRUE; // if we got this far, then it's numeric...
}