Batch File Input limit

June 17, 2009 at 02:44:59
Specs: Microsoft Windows XP Home Edition, 2.793 GHz / 502 MB
Ok.
So, i have my input restriction, where i can only enter numbers or letters.

But it's still possible for someones Name to be 999999 letters long lmao!

Anyone know how i can restrict this limit on an input variable so it restricts to only 8 characters or something.

Heres my code.

:LOOP1 [Letters Only]
set firstname=
set /P firstname=Type Firstname: %=%
echo.%firstname% | findstr /R /C:[0-9] > nul
if not ErrorLevel 1 (
echo. ERROR: Name cannot contain numbers.
goto :LOOP1
)

Restricting numbers, i need to add restricting the number of characters the user can input...

Either the user can only type up to for example 8 characters then it will stop. Or the user can type as many as he/she wants but if it's more than 8 characters it will Goto error.

Thanks
Matt


************************
BatchFile Help ?
Msg me :)
************************


See More: Batch File Input limit

Report •


#1
June 17, 2009 at 03:58:02
It is not possible (or almost easy) to stop the user when he/she tries to type more characters than allowed, but the max lenght can be restricted by coding

  set NameCheck=%firstname:~0,8%
  if not "%NameCheck%"=="%firstname%" (
    echo. ERROR: Name cannot be more than 8 chars
   goto :LOOP1
  )

Be aware your input restrictions do not stop to enter special synbols that may be harmful (as & or %).

Report •

#2
June 17, 2009 at 05:28:21
my post do not solve your problem. but i am just curious, is user going to run your batch file, if so, its pretty easy to bypass your restriction isn't it?

GNU win32 packages | Gawk


Report •

#3
June 17, 2009 at 16:35:40
IVO.
Thanks for the reply, i will try adding the code tomorow.

Ghostdog.
This batch file won't be used by other people. It's basically being created for my knowledge. & boredom lol.
i may share it with others. but it's mainly just being created to see how big i can get it. I like creating batch files & i'll keep adding to this until it is massive. It's just that ive never done this bit before thats why i ask you guys as your much better than me.

Thanks for replies!
Matt

***************************
Need BatchFile Help ?
Msg me :)
***************************


Report •

Related Solutions

#4
June 17, 2009 at 17:17:33
Checking the string can be simplified a little more....

if not "%firstname:~8%"=="" (
    echo. ERROR: Name cannot be more than 8 chars
    goto :LOOP1
)


Report •

#5
June 18, 2009 at 06:14:31
Thanks Judago, Works fine.
I'm getting well happy with this batch file now :P
Thanks to all who commented

Matt

***************************
Need BatchFile Help ?
Msg me :)
***************************


Report •


Ask Question