IsNumeric?

I want to know if an entire column of a text box are numbers or if there is a mix of text and numbers.
The problem is how do you tell if all the characters in a string are in the string “1234567890.±,”
So is there a method like str.IsNumeric?

DIM moo As Integer = Integer.FromText(myText)

http://developer.xojo.com/integer$FromText

[quote]Exceptions
BadDataException
When theText contains anything other than an integer (including when it is empty). Use Parse if you need to parse text that might contain non-numeric data or might be empty.[/quote]
If you get the BadDataException than you know it contains more than numbers… Doesn’t handle the separator characters though…

Thanks shao…

I suppose that would work, It seems odd to not be able to parse something without using an exception to figure something went wrong. Like usinging dic.HasKey(key) vs dic.Value(key) and catching the exception for not found.

euh ?

http://developer.xojo.com/isnumeric

Dim b As Boolean b = IsNumeric("3.1416")

Vous n’tes pas srieux!?
Merci

You might want to mark Jean-Yves’ answer as the answer, incase someone else is looking for the same thing…

Just a note that the two answers in this thread are for different frameworks.

IsNumeric is classic framework and Integer.FromText is the new framework.

[quote=352732:@Tim Parnell]Just a note that the two answers in this thread are for different frameworks.

IsNumeric[/code] is classic framework and [code]Integer.FromText

Integer.FromText wont work for the example specified by Brian though as he mentions decimal points and signs all of which error when passed to FromText so technically the only real answer in this case is IsNumeric :slight_smile:

Sure, that was the point.

And if you want complete control over it, there’s always RegEx…

Because, IsNumeric might also allow “1e9”, and maybe you do not like to allow that.

The regex pattern for your example would be “[±]?\d+\.?\d*”, I think (not actually tested). That would translate to: May start with either a + or -, then followed by digits, and optionally a period and more digits.

To test this pattern, you’d call the Regex.Search function and see if you get a match.

Also, if you want to test user input this way, keep in mind that some countries uses different decimal point chars. E.g, in Germany, the decimal point is a comma, so English 1.2 is 1,2 in German input. I am not sure if IsNumeric considers locales. Even if you read from spreadsheets, it may be that Excel uses the comma on a German locale system. It’s a mess. Just be aware of it.