• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

Need to get User Input and validate the input from file

Need to get 3 digit numeric values and validate it with file.  If doesn't match, request input again.

Enter the person ID or Q to Cancel? 123
Match Found, Triggering action

Enter the person ID? 888
Match NOT Found, Please enter again or Q to Cancel.
0
sk7815
Asked:
sk7815
  • 4
  • 2
2 Solutions
 
ScottyworldCommented:
This will automatically loop if the number is not found in the text file
 
@echo off

:TOP
set /p digits= Enter number: 

findstr /m "%digits%" "c:\support\myfile.txt"
If %errorlevel%==0 (
echo Found number
GOTO END
) else (
Echo Match not found
GOTO TOP
)
:END

Open in new window

0
 
subhashchyCommented:
you should put your action stuffs after :END in the batch code provided by Scottyworld:
0
 
sk7815Author Commented:
Thank you, can you add 'Q" or 'q' to exit out.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
sk7815Author Commented:
may be '000' will work since we setting up as numeric.

@echo off

:TOP
set /p digits= Enter Store Number:

IF %digits% == 000 GOTO END

findstr /m "%digits%" "c:\junk\foo.dat"
If %errorlevel%==0 (
echo Found number
GOTO END
) else (
Echo Match not found
GOTO TOP
)
:END
0
 
sk7815Author Commented:
When the input value matches the string, it displays the file name.  Can we avoid it?
0
 
subhashchyCommented:
add >nul after this line like this....

findstr /m "%digits%" "c:\support\myfile.txt" >nul
0
 
sk7815Author Commented:
Great Team!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now