Dear All
I need regular expression for validating same in textbox
minLength: 8,
maxLength: 16,
upperCase: 0,
numbers: 1,
lowease:2 ,
specialChars:Not allowed
Symbols:Not Allowed
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 3:04 AM EDT
string regExp = @"^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$";
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 2:14 AM EDT
When you also give a quantity for upper case, lower case and numbers, I assume that those quantities are minima as otherwise there's no way they will add up to a minimum of 8.
Subject to those assumptions, try this:
string regExp = @"^(?=.*\d)(?=.*[a-z].*?[a-z])[a-zA-z0-9]{8,16}$";
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 2:29 AM EDT
My req is change, sorry for the same
I need exactly
2 small case characters more than 2 allowed
2 digits exactly more than 2 allowed
Allow special characters
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 2:34 AM EDT
http://www.fon.hum.uva.nl/praat/manual/Regular_expressions_1__Special_characters.html
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 2:39 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 3:14 AM EDT
my java script function
function passwordChanged() {
var strength = document.getElementById('strength');
var last = new RegExp("^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$)");
var pwd = document.getElementById("pwdPassword");
if (pwd.value.length==0) {
strength.innerHTML = 'Type Password';
}
else if (last.test(pwd.value)) {
strength.innerHTML = 'Medium!';
}
else {
strength.innerHTML = 'Weak!';
}
}
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 3:17 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 3:29 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 3:46 AM EDT
As soon as I am giving i/p like any 2 small case characters first in textbox it is validating
function passwordChanged()
{
var strength = document.getElementById('strength');
var last = new RegExp("^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$)");
var pwd = document.getElementById("pwdPassword");
if (pwd.value.length==0)
{
strength.innerHTML = 'Type Password';
}
else if (last.test(pwd.value))
{
strength.innerHTML = 'Strong!';
}
else
{
strength.innerHTML = 'Weak!';
}
}
it should not validate until and unless there are 2 small case letters and 2 numbers in textbox
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 4:01 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 4:31 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 5:16 AM EDT
Try replacing this line:
var last = new RegExp("^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$)");
with this:
var last = /^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$/
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 5:38 AM EDT
But it is still having one problem
It is validating on 10 characters
If i am entering mm33mm33 then it is not validating here i have to put 2 more alphabets
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 6:15 AM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 6:24 AM EDT
it is giving message not ok
function passwordChanged()
{
var text = "mm33mm33";
var expr = /^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$/
if(expr.test(text))
{
alert("OK");
return false;
}
else
{
alert("Not OK")
}
}
Type Password
Type Password
VulpesRank #55 · 29.2K reputationPosted Mar 27, 2012, 7:32 AM EDT
It's just the same whether I run the JavaScript from the command line or within my browser (Google Chrome) so I'm at a loss to explain why it's not working for you.
As it's unlikely now that anyone else will reply to this thread, all I can suggest is that you start a new thread and see if someone else can come up with a different regular expression that does work correctly for you.
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 27, 2012, 10:26 PM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 28, 2012, 3:09 AM EDT
You could try rearranging the regular expression to see if IE will then give the correct results.
Previously, to avoid any confusion, I left the special characters ], - and \ out of the list of characters within the [...] and OR'ed them with the list instead.
I'd try bringing them within the [...] in 'escaped' form:
var expr = /^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])[a-zA-z0-9^${}[().*+?|<>&\\\]\-]{8,16}$/
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 28, 2012, 4:37 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 28, 2012, 6:39 AM EDT