Make sure a variable starts with a specific character
Posted: 17 Sep 2010 17:20
To simplify what I am trying to do is prompt the user for the name of a computer on our network. All of our computers will start with the letter n, be an IP Address, or start with a \ (as in \\192.168.1.2). This means the variable must start with a 'n' a number, or a '\'.
Here is the code I am working with. The part I can't figure out is the if statements...
:start
set /p compname=Enter the IP Address or computer name:
IF %compname% starts with a 'n' goto nextstep
IF %compname% starts with a number goto nextstep
IF %compname% starts with a '\' goto nextstep
IF %compname% does not match one of those go back to start
:nextstep
REM Cool stuff happens here...
If anyone has any suggestions it would help out so much!
Here is the code I am working with. The part I can't figure out is the if statements...
:start
set /p compname=Enter the IP Address or computer name:
IF %compname% starts with a 'n' goto nextstep
IF %compname% starts with a number goto nextstep
IF %compname% starts with a '\' goto nextstep
IF %compname% does not match one of those go back to start
:nextstep
REM Cool stuff happens here...
If anyone has any suggestions it would help out so much!