how to prompt for numeric in command line

January 27, 2011 at 04:49:21
Specs: Windows XP
How can I prompt for numeric, and make sure only numeric is typed in command line

eg set /p var=Enter any numeric:-

See More: how to prompt for numeric in command line

Report •

January 27, 2011 at 13:28:24
AFAIK you cannot test each digit as it is typed. However, after the digits have been <Entered> you can test the variable to ensure it contains only numeric digits. Amend the following untested script to suit your needs:

@echo off

set /p var=Enter numerics:

set chars=1234567890

FOR /F "tokens=1 delims=%chars%" %%1 IN ("%var%") do (
    ECHO %Var% contains at least one Non-Numeric character.
echo %var%

Did you Google for an answer before asking the question?

Report •
Related Solutions

Ask Question