Batch File input validation - Make sure user entered an integer

前端 未结 16 2406
抹茶落季
抹茶落季 2020-12-03 14:33

I\'m experimenting with a Windows batch file to perform a simple operation which requires the user to enter a non-negative integer. I\'m using simple batch-file techniques t

16条回答
  •  生来不讨喜
    2020-12-03 15:10

    Try this:

    set /p numeric=enter a number
    
    ( 
      (if errorlevel %numeric% break ) 2>nul
    )&&(
      echo %numeric% is numeric
    )||(
      echo %numeric% is NOT numeric
    )
    

提交回复
热议问题