如何验证变量是批处理文件中的数字?
1, 2, 4, 5, 10934, 495832945, 4395893428 -> true
Apple, Orange, Animal, Red, Sky, Leaf -> false
答案 0 :(得分:1)
echo %variable%| FINDSTR /R /X " *[0-9]* *" >nul 2>&1 && echo IT IS A NUMBER
echo %variable%| FINDSTR /R /X " *[0-9]* *" >nul 2>&1 || echo IT IS NOT A NUMBER
答案 1 :(得分:1)
在StackOverflow.com上找到答案
set /p Input1=Enter number:
set /a Input2=%Input1% * 1
if "%Input2%"=="0" echo It is not a number.
它不适用于0到0.9的数字。
答案 2 :(得分:1)
来自http://www.robvanderwoude.com/sourcecode.php?src=isnumber_nt [ Alt Link ]
:: Positive decimal
SET RC=10
FOR /F "tokens=1 delims=0123456789" %%A IN ("%Value%") DO SET RC=0
IF %RC% EQU 10 EXIT /B 10