Navigation

7/15/2015

Validating user input from batch file

To prevent blank input:



:askQuestion
set /p UserName=   What is your CUA user ID? || Set UserName=NothingChosen

If "%UserName%"=="NothingChosen" goto :sub_error
:sub_error
echo Error:   Please type in CUA user ID
echo(
echo(

goto:askQuestion


To use regular expression:


:loop
    SET /P "UserName=What is your CUA user ID?: "
    echo("%UserName:"= %"|findstr /r /C:"""[0-9][0-9][a-zA-Z]*""" >nul || ( echo Error:   CUA user ID starts with 2 digits & ECHO( & goto loop )

No comments:

Post a Comment