Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
4.50/5 (4 votes)
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 26-Mar-12 23:54pm
v2
Comments
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.

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/[^]
 
Share this answer
 
v4
Comments
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 :)
^[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.
 
Share this answer
 
Comments
mayur csharp G 27-Mar-12 6:14am    
Needed
Numbers exactly 1
lowercase exactly 2
Dalek Dave 27-Mar-12 6:27am    
Please explain how that works?
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.

Perhaps you are not asking your question clearly enough.
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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