Reputation: 13
I have the below regular expression.
^((?=.{10,32}$)(?=.*[A-Z])(?=.*[a-z]))
The regular expression has the following functionality:
I want to add one more validation. I do not want any continuous repeating character.
Can you please help me?
Upvotes: 1
Views: 1659
Reputation: 70732
You can use a Negative Lookahead to do this.
^(?=.{10,32}$)(?=.*[A-Z])(?=.*[a-z])(?!.*(.)\1).+$
Upvotes: 2
Reputation: 18127
This would match any pair of identical characters:
"(.)\1"
Here little program.
static void Main(string[] args)
{
string a = "12223";
string b = "P12345";
bool z = Regex.IsMatch(a,@"(.)\1");
bool x = Regex.IsMatch(b,@"(.)\1");
}
Upvotes: 1