Computing.Net > Forums > Programming > Batch File Input limit

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Input limit

Reply to Message Icon

Name: Matt (by Mattio)
Date: June 17, 2009 at 02:44:59 Pacific
OS: Microsoft Windows XP Home Edition
CPU/Ram: 2.793 GHz / 502 MB
Subcategory: Batch
Comment:

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 :)
************************



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 17, 2009 at 03:58:02 Pacific
Reply:

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 %).

0

Response Number 2
Name: ghostdog
Date: June 17, 2009 at 05:28:21 Pacific
Reply:

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


0

Response Number 3
Name: Matt (by Mattio)
Date: June 17, 2009 at 16:35:40 Pacific
Reply:

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 :)
***************************


0

Response Number 4
Name: Judago
Date: June 17, 2009 at 17:17:33 Pacific
Reply:

Checking the string can be simplified a little more....

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


0

Response Number 5
Name: Matt (by Mattio)
Date: June 18, 2009 at 06:14:31 Pacific
Reply:

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 :)
***************************


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Null in reg_multi_sz search excel and word fil...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Input limit

Batch file input for logevent.exe www.computing.net/answers/programming/batch-file-input-for-logeventexe/15380.html

batch file input www.computing.net/answers/programming/batch-file-input/11258.html

Batch File|Input from txt file www.computing.net/answers/programming/batch-fileinput-from-txt-file-/17293.html