Answer to Question #62923 in C# for Peter

Question #62923
I want the user to enter a word in my application, but I want it to follow these rules:

• Word starts with a vowel
• Has a length of 5 – 8 characters
• Must have at least 1 repeating letter

How can I check for these in my program? (not case sensitive)
1
Expert's answer
2016-10-28T07:49:53-0400
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
class Program
{
static bool CheckInput(string s)
{
Regex r = new Regex(@"^[aeiouy]\w{4,7}$", RegexOptions.IgnoreCase);
Match match = r.Match(s);
return (match.Success && Regex.IsMatch(match.Value, @"(\w)(\w)*\1+"));
}
static void Main(string[] args)
{
Console.WriteLine("Write a word: ");
string s = Console.ReadLine();
if (CheckInput(s)) Console.WriteLine("Everything OK!");
else Console.WriteLine("Something is wrong!");
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS