# Use of [isNumeric]

When I test a string variable to see if it is numeric, I have one case where the answer is wrong (at least at what I am doing - it could be right under other circumstances).

var tstr as boolean
var acctNo as string = “1234A567”

tstr = isNumeric(acctNo)
Returns “FALSE”.

var acctNo as string = “1234E567”
Returns “TRUE”.

I know what is happening - the “E” is interpreted as engineering notation. Other than cycling through the variable to check the ASCII value of each character, how can I determine if the variable includes only the numbers 0 to 9?

I just cycle through the characters and check each one. I’m sure there’s a RegEx you can use as well.

``````var rx as new RegEx
rx.SearchPattern = "\D"

if rx.Search( myVar ) isa RegExMatch then
// myVar contains something that is NOT a digit
end if
``````
1 Like

Kem - many, many thanks. I didn’t know w hat a RegEx was but tried your code and played with it substituting search pattern commands. What a powerful tool!

Thanks again!

Just for the sake of general information, a floating-point number is compound of 2 parts (like 1234e567), a Significand (or Mantissa) part (as 1234) and the Exponent part (as 567, that means x10⁵⁶⁷). So the “E” is the divider sign showing the “here starts the Exponent”. This kind of notation is called Scientific Notation.

A fast oneliner hack to handle this case could be:

``````var tstr as boolean

var acctNo as string = “1234E567”
tstr = acctNo.Replace("E", "?").IsNumeric  // Now it is False
``````

IsNumeric() acts only in numbers in US/English notation, as Val().

Are there other cases that IsNumeric() could end with unexpected results?

Yes. Some Xojo notations are valid numbers, as “&h10”, and it’s Val() is 16.

1 Like

Alberto - I hadn’t considered other notations such as “&” which, like “E”, would appear as numeric to the [isNumeric] function. Thanks for the info - the RegEx option solved my problem as suggested by Ken Tekinay. It’s amazing how many things I don’t know!