Click to See Complete Forum and Search --> : Isnumeric and several decimal points
Terrorke
01-30-2007, 06:14 AM
Hello,
I have a strange case.
When you have a variable with the value "5.5.5.5.5" and you check this with the isnumeric function it passes.
Is there a way to check if the value has only 1 decimal point? Or do I have to use a workaround?
Thnx
russell
01-30-2007, 10:30 AM
ahh the old isNumeric() function. It seems buggy, but in reality, it tries to account for different numeric formats -- thus, giving unexpected results.
should use regular expressions, or string parsing methods instead.
here's the easy string parsing method
Response.Write isNumber("5.5.5.5.5") & "<br>"
Response.Write isNumber(123.456) & "<br>"
Response.Write isNumber("0.0.") & "<br>"
Function isNumber(n)
Dim i
Dim dotCount
Dim tmp
Dim strValidNumbers
strValidNumbers = ".0123456789"
dotCount = 0
For i = 0 To Len(n)-1
tmp = Mid(n, i+1, 1)
If tmp = "." Then dotCount = dotCount + 1
If instr(strValidNumbers, tmp) = 0 Then
isNumber = False
Exit Function
End If
Next
If dotCount < 2 Then
isNumber = True
Else
isNumber = False
End If
End Function
Terrorke
01-31-2007, 01:53 AM
Thanks Russell
As always, perfect! :)
Grtz