should be numeric only

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sivaram.nv
Posts: 4
Joined: 30 Aug 2007 02:29

should be numeric only

#1 Post by sivaram.nv » 30 Aug 2007 03:04

I Want to check the string only numeric

for example

Port=1111 (which i want)

port=wjke111 (which i dont want)

how do i check above condition..

Thnaks & regards

Sivaram Nv

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

isNumeric function

#2 Post by jeb » 30 Aug 2007 15:13

Hi Sivaram,

this should solve it.

@echo off

set myNum=%1

call :isNumeric %myNum% result
echo %result%
goto :eof


::************************
:isnumeric
setlocal
set rest=_
for /f "delims=0123456789" %%a in ("%~1") do set rest=_%%a
set return=false
if "%rest%"=="_" set return=true
( endlocal
if "%~2" NEQ "" set %~2=%return%
goto:eof
)

Post Reply