Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 :)
************************

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

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?

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

Checking the string can be simplified a little more....
if not "%firstname:~8%"=="" ( echo. ERROR: Name cannot be more than 8 chars goto :LOOP1 )

Thanks Judago, Works fine.
I'm getting well happy with this batch file now :P
Thanks to all who commentedMatt
***************************
Need BatchFile Help ?
Msg me :)
***************************

![]() |
Null in reg_multi_sz
|
search excel and word fil...
|

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