Solved Restrict input with max characters and numbers and dot only

April 27, 2012 at 21:35:35
Specs: Windows 7
can you help me on programming a batch?

im trying to make an ip checker input.

what i want to make is

ask what is their ip
then the scree would show "so is this your ip?"

i cant make it. i want to restict input to numbers only and (.) dot only with restricted numbers of input (i i mean how to set max character)

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

from: http://www.computing.net/answers/pr...

and mix it with this

set /P firstname=Type Firstname: %=%
set "test=%firstname%"
for %%a in (1 2 3 4 5 6 7 8 9 0 .) do if defined test call set "test=%%test:%%a=%%"
if defined test (

i want to restrict the input to numbers and period with max character limit. pls help
echo The input contained characters that are not contained in a-z
)


See More: Restrict input with max characters and numbers and dot only

Report •


#1
June 3, 2012 at 09:56:47
✔ Best Answer
::please test before use(it worked in xp without problems on many different entries
::this was to solve the ip entering issues. it theoretically will only accept numbers and .'s
::WORKING ON THE SECOND HALF
cls
@echo off
:BEGINS
ECHO PLEASE ENTER IP ADDRESS WITHOUT LEADING 0'S (press y and enter to exit)
::exit sequence
set /p ipad="please enter ip address: : "
if %ipad% equ y goto ends
if %ipad% equ Y goto ends
echo %ipad%>c:\dostemp\testip.txt
for /f "tokens=1,2,3,4 delims=." %%A IN (c:\dostemp\testip.txt) DO set one=%%A && set two=%%B && set three=%%C && set four=%%D
SET /A ONE=%one%
SET /A TWO=%two%
SET /A THREE=%three%
SET /A FOUR=%four%

FOR /L %%G IN (1,1,999) DO IF %ONE% equ %%G goto next1
goto fault
:next1
FOR /L %%H IN (1,1,999) DO IF %TWO% equ %%H goto next2
goto fault
:next2
FOR /L %%J IN (1,1,999) DO IF %THREE% equ %%J goto next3
goto fault
:next3
FOR /L %%K IN (1,1,999) DO IF %FOUR% equ %%K goto next4
:fault
cls
ECHO THERE IS AN ERROR IN YOUR ADDRESS PLEASE REENTER
goto BEGINS
pause
:next4
echo if this is not the correct ip address press n to reset else press anything?
echo %ONE%.%TWO%.%THREE%.%FOUR%
set /p ipcheck=" :"
if %ipcheck% equ n goto BEGINS
if %ipcheck% equ n goto BEGINS
pause
::REST OF SCRIPT
:ends

:: mike


Report •

#2
June 3, 2012 at 10:02:47
Did you want to restrict the name to numbers and periods? or was that just for the ip address?

:: mike


Report •

Related Solutions


Ask Question