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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 27, 2012, 7:04 AM
string regExp = @"^(?=.*\d.*?\d)(?=.*[a-z].*?[a-z])([a-zA-z0-9^${}[().*+?|<>&]|]|-|\\){8,16}$";
VulpesPosted Mar 28, 2012, 10:39 AM
Mayur GujrathiPosted Mar 28, 2012, 8:37 AM
VulpesPosted Mar 28, 2012, 7:09 AM
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 GujrathiPosted Mar 28, 2012, 2:26 AM
VulpesPosted Mar 27, 2012, 11:32 AM
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 GujrathiPosted Mar 27, 2012, 10:24 AM
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
VulpesPosted Mar 27, 2012, 10:15 AM
Mayur GujrathiPosted Mar 27, 2012, 9:38 AM
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
VulpesPosted Mar 27, 2012, 9:16 AM
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 GujrathiPosted Mar 27, 2012, 8:31 AM
Mayur GujrathiPosted Mar 27, 2012, 8:01 AM
Mayur GujrathiPosted Mar 27, 2012, 7:46 AM
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 GujrathiPosted Mar 27, 2012, 7:29 AM
VulpesPosted Mar 27, 2012, 7:17 AM
Mayur GujrathiPosted Mar 27, 2012, 7:14 AM
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!';
}
}
Mayur GujrathiPosted Mar 27, 2012, 6:39 AM
VulpesPosted Mar 27, 2012, 6:34 AM
http://www.fon.hum.uva.nl/praat/manual/Regular_expressions_1__Special_characters.html
Mayur GujrathiPosted Mar 27, 2012, 6:29 AM
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
VulpesPosted Mar 27, 2012, 6:14 AM
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}$";