i had a batch file that need to input month, day and year my problem is
1.when i input letters still it will accept
2. when i input space still it will accept
please help me to put a restriction that will not accept letters and spaces i need your expertise.
SET /P deyt1=Type the Month ^<MM^> :
if not “%deyt1:~2%”==”” (
echo. ERROR: Name cannot be more than 2 chars
goto START
)
IF NOT DEFINED deyt1 goto START
SET /P deyt2=Type the Day ^<DD^> :
if not “%deyt2:~2%”==”” (
echo. ERROR: Name cannot be more than 2 chars
goto START
)
IF NOT DEFINED deyt2 goto START
SET /P deyt3=Type the Year ^<YYYY^>:
if not “%deyt3:~4%”==”” (
echo. ERROR: Name cannot be more than 4 chars
goto START
)
IF NOT DEFINED deyt3 goto START
:month
cls
set /p month=Type the Month ^<MM^>:
if %month% < 1 goto day
if %month% > 12 goto day
//this will make sure your entry is 1 – 12
goto month
:day
cls
set /p day=Type the Day ^<DD^>:
if %day% < 1 goto day
if %day% > 31 goto day
//this will make sure your entry is 1 – 31
goto year
:year
cls
set /p year=Type the Year ^<YYYY^>:
if %year% < 1980 goto deyt3
if %year% > 2030 goto deyt3
//this will make sure your entry is 1980 – 2030
//you might want to dhange the year range
goto finish
:finish
cls
echo %month%/%day%/%year%
pause >nul
exit
This will let you type in a number then It’ll make sure it’s within a certain range. Then it’ll move on to the next one until the finish room were It’ll display the date.