Batch File input validation - Make sure user entered an integer

前端 未结 16 2400
抹茶落季
抹茶落季 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:32

    You may use ReadFormattedLine subroutine for all kind of formatted input. For example, the command below read a number of up to 5 digits:

    call :ReadFormattedLine UserInput="#####" /M "Please Enter a Number: "
    

    This subroutine is written in pure Batch so it does not require any additional program, and it allows several formatted input operations, like read passwords. In previous example, the subroutine reads a number of up to 5 digits. You may download ReadFormattedLine subroutine from Read a line with specific format.

提交回复
热议问题