A little info about IsNumeric
I got an interesting call from a friend yesterday that was in a bit of jam. Very simply, he wanted to check that value in a textbox was not a number and was using something like
If Not IsNumeric(Textbox1.Text) Then
…
End If
The funny thing though was that if he put “R1†into the textbox the expression would result to false and not execute the enclosed code when it should have done; using “r1†would work normally!?
The reason for this is because if you set your machine’s localization to South Africa the capital ‘R’ is seen as a currency symbol (Rands, for my foreign friends reading this) so R1 is 1 Rand and is seen as a numeric.
The answer my friend found was to use TryParse and set the culture specific information to recognize this
Dim MyCultureInfo As New System.Globalization.CultureInfo(“en-ZA”)
If Double.TryParse(MyValue, System.Globalization.NumberStyles.Integer, MyCultureInfo, Nothing) Then
…
End If
I have to point out that this was only detected when their system went live (this is part of a web app) because the developer’s and dev machines were using the default Windows settings and the live environment had been setup with the South African localization.
It’s not something you come across every day so I’d thought I’d mention it.


