@echo off
:loop
set /p "userinput=Input: "
echo %userinput%|findstr /r "^[0-9][0-9][0-9][0-9][0-9][0-9]$" >nul || (
echo invalid input
goto :loop
)
set "nofives=%userinput:5=%0123456"
set /a fives=%nofives:~6,1%
echo %userinput% has %fives% fives.
if %fives% == 3 goto :three
goto :loop
:three
echo insert your payload here
findstr
checks, if the input consists of exactly 6 numbers.
set nofives...
removes any 5
and adds a counter string
%nofives:~6,1%
gets the seventh character (counting is zero-based!) which is the count of fives.
As this effectively counts the number of fives (expandable to an input of max nine numbers 1)), you are free to handle "exactly three" (if %fives% == 3
) or "minimum three" (if %fives% geq 3
) or whatever you want.
To show how it works, let's assume %userinput%
is abcdef
(just to not confuse it with the counter string)
If we remove nothing from %userinput%
and add the counter string, it looks like:
abcdef0123456
^ this char is the count (seventh char)
If we remove one char (abcdef -> abcdf) and add the counter string, it looks like:
abcdf0123456
^ this char is the count (seventh char)
and so on until "remove six chars (for you that would be an user input of 555555
). then it looks like:
0123456
^ this char is the count (seventh char)
1) with two slight changes expandable up to 15 numbers (using a hexadecimal counter string):
set "nofives=%userinput:5=%0123456789ABCDEF"
set /a fives=0x%nofives:~6,1%