1.

Solve : check user input is x characters or specific forma?

Answer»

Hi,

hope you can all help me, I am new around these PARTS

I have created batch files to rebuild systems in dos via ghost and ghostwalker

, however when the user enters the COMPUTER name :-

Set /P compname=Please enter computer name:

I want to ensure they are using the correct format and characters ie nt0x00000

any tips?Aidy,

You can check each character one by one or you can check whole sub-strings, i.e.

[edit]setlocal ENABLEDELAYEDEXPANSION
if "!compname:~0,4!" NEQ "nt0x" goto:ERROR
for /l %%n in (4,1,8) do (
    if "!compname:~%%n,1!" LSS "0" goto:ERROR
    if "!compname:~%%n,1!" GTR "9" goto:ERROR
)
endlocal
echo.name is good
goto:EOF

:ERROR
echo.name is bad
goto:EOF[/edit]
DOS IT HELP?  I think the EASIEST and quickest way would be to USE the regular expression syntax of FINDSTR.  What is the correct format?  It looks like you are using nt0x#####, where "nt0x" is static, and # is any DIGIT?  If so,  you can use:
Code: [Select]:EnterCompName
set /p compname=Please enter computer name:
echo %compname%|findstr /r /x "nt0x[0-9][0-9][0-9][0-9][0-9]"
if errorlevel 1 echo Incorrect format&goto :EnterCompName
echo Name is goodNice GuruGary!!!  Much better!Thanks!thanks that did the trick, hopefully they might start making the machines with the right names now



Discussion

No Comment Found