I have a CustomDialog with a text control (created via NSD_CreateText). During installation the user has to enter a valid number. The setup has to make sure it is valid.
Rules are:
3 digits long
only numbers, no characters
beginning with 001
ending with 999
So far i use this code for evaluation. It is the callback function for the PageLeave-Event:
I had to tweak the code and put a 1 in front of the given value, otherwise 008 and 009 would be considered as something else by IntCmp (probably some hex 0x08 value).
Function nsDialogsAZBENPageLeave
ShowWindow $AZBENLabel ${SW_HIDE}
; Check empty string
${If} $AZBENDialogFolder == ""
Abort
${EndIf}
; Check 3 digits
StrLen $0 $AZBENDialogFolder
${If} $0 <> 3
Abort
${EndIf}
; Check numerical
; Bug - all kinds of values are considered valid: abc|12w|1q1|...
IntCmp 1$AZBENDialogFolder 1999 is999 lessthan999 morethan999
is999:
Goto done
lessthan999:
Goto done
morethan999:
Abort
done:
IntCmp 1$AZBENDialogFolder 1000 is0 lessthan0 morethan0
is0:
Abort
lessthan0:
;It cannot be < 1000 !
Goto done2
morethan0:
; Should always be > 1000 !
Goto done2
done2:
; Division by 1 to produce an error if not a number
; Bug - all kinds of values are considered valid: abc|12w|1q1|...
IntOp $0 $AZBENDialogFolder / 1
IfErrors 0 +2
Abort
${NSD_GetText} $AZBENLabel $AZBENLabel_State
ShowWindow $AZBENLabel ${SW_HIDE}
FunctionEnd
Can anyone shed light on this behaviour? Is there a better function than IntCmp, like IsNumeric?
Thanks in advance!
KR, Pascal