Regex to check if string only contain digits and is 11 characters/digits long?
currently I am using:
if (Regex.IsMatch(searchValue, @"^\d{11}.*") && searchValue.Length == 11)
{
开发者_如何学运维 // Do something
}
How can I alter the regex to also check the length and not to use the && operator?
Thanks in advance.
Changing the pattern to
@"^\d{11}$"
Should do it
Use the following expression:
^\d{11}$
I tend to use the Expresso tool for designing regex patterns, especially as they get complex. It shows a breakdown that clearly tells you what each bit of the regex is doing. Agree with other posters (Marc/Logicnp) for the answer to the OP's problem.
精彩评论