Validnumber( and nan( functions not acting the way I expect

I am trying to test to see if a user entered a valid number into a text editor. (Should be a dollar amount.) The procedure that is triggered is using nan( to check. But virtually everything I enter returns false. A string of text returns false.

Can someone explain what is going on? A bug or I am misunderstanding something? Is there a better to test if an entry is a valid number?

nan is actually a floating point value. Functions like sqr(, log(, arcsin(, and arccos(, which are undefined for certain arguments, will return a nan value when given one of those arguments. The nan( function is looking for a value of nan or inf (infinity.) It will return true() for either of those two floating point values, and false() for everything else.

Thanks for the explanation. Any suggestion on how to test an entry to see if it is a valid number?

The val( function will return 0 if it can’t interpret the string as a number. If 0 is an acceptable entry, you may need to add a specific test for that. Maybe something like

?(val(theNumber)≠0 or theNumber BeginsWith "0",true(),false())

You can use a regular expression for this. Assume that VALUE is a variable containing text. If you want to find out if the text is a valid integer, use this formula:

_VALUE_ regexmatch {^(\+|-)?\d+$}

If you want to find out if the text is a valid floating point number, you could use this:

_VALUE_ regexmatch {^[+-]?\d*(\}+info("decimalseparator")+{)?(\d+)?[ ]*([Ee][+-]?\d+)?$}

The documentation says validnumber( is the opposite function to nan(. It returns true if the value is valid, false if it is invalid.

Don’t spend a lot of effort here now. Data Input Validation is listed under 10.2’s coming attractions in the online help.

Thanks to everybody for the various suggestions and comments.