나는 이것을 해결하는 방법에 대해 내 머리를 이해할 수 없다. 다음 코드가 있습니다.
:userinfo
set U=U
set /p EmployeeID=Please enter Employee ID:
for /f "tokens=1* delims=0123456789XC" %%a in ("A0%EmployeeID:"=%") do if not "%%b"=="" echo Only numbers, except X and C, case sensitive! && goto userinfo
잘 작동하지만 입력 문자를 7 자로 제한하고 싶습니다. 최대 7자가 아닌 7 자 여야 함을 의미합니다.
나는 시도 if not "!EmployeeID:~7! == "" echo 7 characters required. & goto userinfo
했지만 작동하지 않습니다.
고칠 수있는 '간단한'일이라고 확신합니다 ..
문자열이 7 자 이하인 경우 조건 if "!EmployeeID:~7!"==""
은 참 으로 평가됩니다 ( 때문에 지연된 확장 이 활성화 된 경우 !!
).
당신의 작업을 해결하려면 두 번째 조건을 적용 if not "!EmployeeID:~6!"==""
입니다 진정한 문자열이 적어도 7 자입니다 경우.
그런 다음 두 조건을 연결합니다.
:userinfo
set /p EmployeeID="Please enter Employee ID: "
for /f "tokens=1* delims=0123456789XC" %%a in ("A0%EmployeeID:"=%") do (
if not "%%b"=="" (
echo Only numbers, except X and C, case sensitive^^!
goto userinfo
)
)
if "!EmployeeID:~7!"=="" if not "!EmployeeID:~6!"=="" (
rem Both conditions fulfilled, so continue
goto continue
) else (
echo 7 characters required.
goto userinfo
)
:continue
다른 방법은를 사용 findstr
하는 것입니다. 다음과 같이 문자 집합과 길이를 모두 확인할 수 있습니다.
:userinfo
set "EmployeeID="
set /p EmployeeID="Please enter Employee ID: "
echo(!EmployeeID!|findstr "^[0-9XC][0-9XC][0-9XC][0-9XC][0-9XC][0-9XC][0-9XC]$" 2> nul || (
echo 7 characters, only numbers, X and C, case-sensitive^^!
goto :userinfo
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다