I want to check the input of a textbox for the following patterns:
***** or [0-9] anything else should return false using regular expressions. How can I do this in C#.
How would I make the check?
Thanks,
Ben
Reg Expression
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Javeed M ShaikhRank #839 · 2.7K reputationPosted Nov 14, 2011, 10:54 AM EST
using System.Text.RegularExpressions;
string input;
string pattern = @"^([\*]){5}$|[0-9]";
input = Console.ReadLine();
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(input);
if (matches.Count > 0)
{
Console.WriteLine("all ok");
}
else
{
Console.WriteLine("error");
}
Console.ReadKey();
VulpesRank #55 · 29.2K reputationPosted Nov 14, 2011, 11:01 AM EST
If you do, then it will simply be:
string pattern = @"^\d{5}$";
bool isValid = Regex.IsMatch(textBox1.Text.Trim(), pattern);
Ben Jones3 reputationPosted Nov 14, 2011, 11:22 AM EST
This is perfect.