So... You want VALID input to consist only of numbers, correct?
The following will only accept a response between a valid min and max number (note you can't have min and max clause beyond +/- 147 Million. with this code and 0 and -1 are not valid options so you might prefer to just use a set of p[ositive integers in the range 1 to + )
This code will validate that a value between your min and max was entered, it will allow leading 0s to be entered, and ignore them.
Any other character used will result in a failure, and print the menu and ask for the choice again.
From -147,483,647 to +147,483,647 (excluding 0 and -1)
@( setlocal Enabledelayedexpansion
Echo off
Set /A "Min_Num=-147483647", "Max_Num=147483647", "_CONSTANT_INVALID_CHOICE_A=0", "_CONSTANT_INVALID_CHOICE_B=-1"
)
CALL :Main
( endlocal
Exit /B
)
:Main
:1_Main
CALL :Menu
Choice /M "Test Choice Again?"
GOTO :%ERRORLEVEL%_Main
:2_Main
GOTO :EOF
:Menu
CLS
SET "_Input="
SET "tNum="
ECHO.
ECHO.Output Menu Options here.
ECHO.
Set /p "_Input=Please enter a number between %Min_Num% and %Max_Num%: "
SET /A "tNum= (1%_Input%) - ( (2%_Input%) - (1%_input%) )" || (
GOTO :Menu )
FOR %%A IN ( %_CONSTANT_INVALID_CHOICE_A% %_CONSTANT_INVALID_CHOICE_B%
) DO (
IF %tNum% EQU %%A GOTO :Menu )
IF %tNum% LEQ %Max_Num% (
ECHO=%tNum% LEQ %Max_Num%
IF %tNum% GEQ %Min_Num% (
ECHO.VALID CHOICE %tNum%
CALL :Choice_%tNum%
GOTO :EOF
)
)
GOTO :Menu
GOTO :EOF
:Choice_-2
ECHO=Choice -2
GOTO :EOF
:Choice_1
ECHO=Choice 1
GOTO :EOF
:Choice_2
ECHO=Choice 1
GOTO :EOF
ECHO=Choice 1
:Choice_3
ECHO=Choice 1
GOTO :EOF
From 1 to +147,483,647
@( setlocal Enabledelayedexpansion
Echo off
Set /A "Min_Num=1", "Max_Num=147483647",
)
CALL :Main
( endlocal
Exit /B
)
:Main
:1_Main
CALL :Menu
Choice /M "Test Choice Again?"
GOTO :%ERRORLEVEL%_Main
:2_Main
GOTO :EOF
:Menu
CLS
SET "_Input="
SET "tNum="
ECHO.
ECHO.Output Menu Options here.
ECHO.
Set /p "_Input=Please enter a number between %Min_Num% and %Max_Num%: "
SET /A "tNum= (1%_Input%) - ( (2%_Input%) - (1%_input%) )" || (
GOTO :Menu )
IF %tNum% LEQ %Max_Num% (
ECHO=%tNum% LEQ %Max_Num%
IF %tNum% GEQ %Min_Num% (
ECHO.VALID CHOICE %tNum%
CALL :Choice_%tNum%
GOTO :EOF
)
)
GOTO :Menu
GOTO :EOF
:Choice_1
ECHO=Choice 1
GOTO :EOF
:Choice_2
ECHO=Choice 1
GOTO :EOF
ECHO=Choice 1
:Choice_3
ECHO=Choice 1
GOTO :EOF