I need to check if a parameter that is passed to a Windows Batch file is a numeric value or not. It would be good for the check to also works for variables.
I found a
if errorlevel
accepts only numeric values which can be used for a checks:
set test_var=001
(
(if errorlevel %test_var% break ) 2>nul
)&&(
echo %test_var% is numeric
)||(
echo %test_var% is NOT numeric
)
set test_var=001X
(
(if errorlevel %test_var% break ) 2>nul
)&&(
echo %test_var% is numeric
)||(
echo %test_var% is NOT numeric
)
the first check will pass, the second not.
Though the script above would not handle unary +
- if you want to handle this case too check - isInteger.bat