1

I need to put a validation when user enter the value he should enter only numeric value but the user will enter the values in below format

Echo Build Number in the Format 5.1.2.44
set /p Build="enter Build Number Please : "

If he puts the values in 5.1.2.3 then he needs to identify that it is numeric..he can use any character ?/., between the values instead of .(dot)

Valid examples are 5.1.2.3

Invalid examples are 5.2.A.3

1 Answer 1

1

Here is an example of how to verify that each value between the delimiters is a number.

@echo off
set "xResult=valid"
for /f "tokens=1,2,3,4 delims=?/.," %%A in ("%Build%") do (
    for /f "tokens=1 delims=1234567890" %%n in ("%%A") do set "xResult=invalid"
    for /f "tokens=1 delims=1234567890" %%n in ("%%B") do set "xResult=invalid"
    for /f "tokens=1 delims=1234567890" %%n in ("%%C") do set "xResult=invalid"
    for /f "tokens=1 delims=1234567890" %%n in ("%%D") do set "xResult=invalid"
)
echo %xResult%

This works by first parsing the Build string into four separate values (A-D) by the delimiters (?/.,) and checking if each of those values are only comprised of the numbers (0-9).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.