So it seems everything I do with Regex doesn’t do what I expect it to do. This statement, I expect to toss out any letters and require 3 digits at minimum and most, but it doesn’t require 3 digits. It indeed disallows letters but any number of digits is good.
myReg = new Regex(@"(^[a-z])([0-9]{3,3})*");
I expect the ^[a-z] to toss out letters and the [0-9]{3,3} to require 3 digits.
Might as well add the whole code block, wasn’t thinking.
userData = phone.Text;
myReg = new Regex(@"(^[a-z])([0-9]{3})+");
foreach (var validName in myReg.Matches(userData))
{
if (myReg.IsMatch(userData))
{
phone.Clear();
badData.Visible = true;
phone.Focus();
}
}
That matches
I think you need:
^[0-9]{3}+$This matches a string that contains:
If you instead simply need a string that consists of more than 3 characters and entirely of digits, you can use:
^[0-9]+$