dienjd
9th March 2006 19:30 UTC
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?
kichik
9th March 2006 19:37 UTC
Let InstallOptions validate it for you, use the ONLY_NUMBERS flag.
dienjd
9th March 2006 19:42 UTC
oops, missed that flag when viewing the readme. Thanks!
galil
14th March 2006 06:27 UTC
what about negative numbers? it seems ONLY_NUMBERS flag allows only positive (doesn't accept sign that is).
Afrow UK
14th March 2006 10:04 UTC
In which case you can use one of these functions:
http://nsis.sourceforge.net/StrCSpn%...for_characters
-Stu
galil
14th March 2006 21:09 UTC
ooh, ok thanks :)