1
Reply

Validate User input that is read in

paula_stroud

paula_stroud

Oct 23 2004 4:21 PM
1.8k
I want to ask the User to enter a 6 digit code, and then use regular expression to validate it. If it is not correct, then ask User to try again. Here's the start of the code . . . can anyone offer a suggestion for looping and verifying the entry? Thank you. using System.Text.RegularExpressions; int code = 0; Console.WriteLine ("Enter 6 digit number."); code = Convert.ToInt32(Console.ReadLine()); string pattern = @"\d{6}"; //must be exactly 6 digits Regex rx = new Regex(pattern); //checks the pattern MatchCollection collection = rx.Matches(code); foreach(Match m in collection) Console.WriteLine(m); // displays entry

Answers (1)