Function to verify if string is numeric
To all members:
I've searched in this forum and doesn't found. Then I wrote this function to verify is a string is numeric. This is usefull to check serial number during installation.
Enjoy!
;IsNumeric
;
; Verify if the string is numeric
; input, top of stack string
; output, top of stack '1' or '0'
;
; Usage:
; Push $x ;string to verify
; Call IsNumeric
; Pop $x ;result '1' or '0'
;
Function IsNumeric
Exch $R0
Push $R1
Push $R2
Push $R3
StrCpy $R1 0
StrCpy $R3 "0" ;Set result not numeric
loop:
StrCpy $R2 $R0 1 $R1
IntOp $R1 $R1 + 1
StrCmp $R2 "" endLoop
StrCmp $R2 "0" loop
StrCmp $R2 "1" loop
StrCmp $R2 "2" loop
StrCmp $R2 "3" loop
StrCmp $R2 "4" loop
StrCmp $R2 "5" loop
StrCmp $R2 "6" loop
StrCmp $R2 "7" loop
StrCmp $R2 "8" loop
StrCmp $R2 "9" loop
;If char R$2 is not numeric, then just go out,
;because $R0 is already set not numeric
Goto done
endLoop:
;Clean initial result, because the end of string was reached
StrCpy $R3 "1"
done:
StrCpy $R0 $R3
Pop $R3
Pop $R2
Pop $R1
Exch $R0
FunctionEnd