Archive: validate input is numeric


validate input is numeric
I need to validate that user input in a text field is numeric. I didn't find any examples in a search of the forums, so I did this:


!insertmacro MUI_INSTALLOPTIONS_READ $1 "inifile.ini" "Field 1" "State" #text field
IntOp $R0 $1 / $1

This seems to work. If $1 is a non-numeral it returns $R0 as 0. If $1 is a numeral, $R0 is 1.

Is there a more reliable method of doing this? Am I overlooking a case where this would fail?

Let InstallOptions validate it for you, use the ONLY_NUMBERS flag.


oops, missed that flag when viewing the readme. Thanks!


what about negative numbers? it seems ONLY_NUMBERS flag allows only positive (doesn't accept sign that is).


In which case you can use one of these functions:
http://nsis.sourceforge.net/StrCSpn%...for_characters

-Stu


ooh, ok thanks :)