You can use multiple string to validate user input with findstr
:
echo/%codename% |%__APPDIR__%findstr.exe "Candy Sugar Lollipop" >nul && goto :Next
1) echo/%codename%
(string-input) to findstr
(find string),
2) Use /i
case-insensitive if you need, if not, remove /i
3) If matched, goto :next
label... if not, will execute next line…
4) Echo/your message and a timeout show up to user, waiting for user to press any key
5) goto :EOF
(end of file), same as exit/abort/quit your bat.
@echo off & setlocal
set /p codename="Please enter the codename! "
echo/%codename% |%__APPDIR__%findstr.exe "Candy Sugar Lollipop" >nul && goto :Next
echo/The code you entered is not available^!! & %__APPDIR__%timeout -1 & goto :EOF
:Next
rem :: your code continue here...`
- Obs. If user input only enter, you can limit this in:
if !_cnt! equ 3
@echo off & setlocal EnableDelayedExpansion
:loop
set /p codename="Please enter the codename! "
set /a "_cnt+=1+0"
if !_cnt! equ 3 (
echo/Maximum number of attempts allowed exceeded^!!
goto :Error ) else if "!codename!"=="" goto :loop
echo/!codename! |%__APPDIR__%findstr.exe "Candy Sugar Lollipop" >nul && goto :Next
:Error
echo/The code you entered is not available^!! & %__APPDIR__%timeout -1
endlocal & goto :EOF
:Next
rem :: your code continue here...