Skip to content

Instantly share code, notes, and snippets.

@davidruhmann
Created December 6, 2012 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidruhmann/4229480 to your computer and use it in GitHub Desktop.
Save davidruhmann/4229480 to your computer and use it in GitHub Desktop.
[Batch] Numeric validation methods.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsDecimal <xReturn> <xInput> [xDelims]
:: Return true if the input is a decimal 10.0 number, else return false.
:::: Only allows for period seperator unless specified by xDelims. ,[tab][space]
call :IsNumber %1 %2 %3
goto :eof
:: by David Ruhmann
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:IsNumber <xReturn> <xInput> [xDelims]
:: Return true if the input is a base 10 number, else return false.
:::: Does not allow any seperators unless specified by xDelims. ,.[tab][space]
setlocal
if not "%~2"=="" set "xResult=true"
for /f "tokens=1 delims=1234567890%~3" %%n in ("%~2") do set xResult=false
endlocal & if not "%~1"=="" set "%~1=%xResult%"
goto :eof
:: by David Ruhmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment