15,797,721 members
See more:
Dear All

I need regular expression for validating same in textbox

minLength: 8,
maxLength: 16,
upperCase: 0,
numbers: 1,
lower case:2 ,
specialChars:Ntt allowed
Posted
Updated 27-Mar-12 0:54am
v2
Amir Mahfoozi 27-Mar-12 6:46am
Are you sure that it can be implemented with regular expressions ?
ProEnggSoft 27-Mar-12 6:51am
It can be implemented. Please see my solution (2)
ProEnggSoft 27-Mar-12 7:22am
+5 for a thought provoking question.
ProEnggSoft 28-Mar-12 6:03am
If your question is answered, you may consider to accept the solution.

## Solution 2

The following regular expression meets the above requirement

`(?(?=^[a-z0-9]{8,16}\$)(?(?=^.*\d.*\d.*\$)(?(?=^.*[a-z].*[a-z].*\$)^[a-z0-9]{8,16}\$)))`

It first searches for alpha numeric string of 8 to 16 characters length, then
it searches if there are atleast two numbers and then searches for atleast two small alphabet. Only then the search passes.

It can be tested online here
http://regexhero.net/tester/[^]

v4
Dalek Dave 27-Mar-12 7:00am
Yes I agree.

I just couldn't see what the OP wanted at first, his question was not as clear as it could have been.
ProEnggSoft 27-Mar-12 7:06am
Thank you.
Amir Mahfoozi 27-Mar-12 7:18am
+5 I tested it here : http://regexhero.net/tester/ and it seems that it works well.
ProEnggSoft 27-Mar-12 7:20am
Thank you.
Amir Mahfoozi 27-Mar-12 7:23am
It was not my question :)

## Solution 1

^[0-9a-z](8,16)\$

Should do it.

0 to 9 and a to z lower case, minimum length 8 max 16, no special characters added.

mayur csharp G 27-Mar-12 6:14am
Needed
Numbers exactly 1
lowercase exactly 2
Dalek Dave 27-Mar-12 6:27am
You need Exactly 1 number, ok easy.
You need Exactly 2 lowercase, again, simple.
You state No Uppercase at all, no problem
You require Zero special character, child's play.

You want it between 8 and 16 characters - er... what the hell are you putting in there?
You cannot have zero upper case, 1 number and 2 lower case with no special characters.

mayur csharp G 27-Mar-12 6:33am
sorry Dalke i got it

I need exactly

2 small case characters more than 2 allowed

2 digits more than 2 allowed
Dalek Dave 27-Mar-12 6:38am
So MINIMUM of 2 lower case, MINIMUM of 2 Numbers?
mayur csharp G 27-Mar-12 6:40am
yes dear

Top Experts
Last 24hrsThis month
 Dave Kreskowiak 120 Maciej Los 90 Richard MacCutchan 70 Andre Oosthuizen 50 Richard Deeming 40
 Richard Deeming 538 Andre Oosthuizen 360 Maciej Los 350 Dave Kreskowiak 335 Richard MacCutchan 243

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900