How to check if a parameter (or variable) is a number in a Batch script

后端 未结 10 544
南方客
南方客 2020-12-01 08:02

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

10条回答
  •  伪装坚强ぢ
    2020-12-01 08:38

    SET "var="&for /f "delims=0123456789" %%i in ("%1") do set var=%%i
    if defined var (echo %1 NOT numeric) else (echo %1 numeric)
    

    Replace %1 with %yourvarname% as appropriate

提交回复
热议问题