Batch File input validation - Make sure user entered an integer

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

    This is more of a user friendly way.

    if %userinput%==0 (
    cls
    goto (put place here)
    )
    if %userinput%==1 (
    cls
    goto (put place here)
    )
    if %userinput%==2 (
    cls
    goto (put place here)
    )
    if %userinput%==3 (
    cls
    goto (put place here)
    )
    if %userinput%==4 (
    cls
    goto (put place here)
    )
    if %userinput%==5 (
    cls
    goto (put place here)
    )if %userinput%==6 (
    cls
    goto (put place here)
    )if %userinput%==7 (
    cls
    goto (put place here)
    )
    if %userinput%==8 (
    cls
    goto (put place here)
    )
    if %userinput%==9 (
    cls
    goto (put place here)
    )
    

    This can be used for any type of user input.

提交回复
热议问题