Javascript function

Is there a Javascript function (or JQuery method) that I can use to do  the following.

Suppose var pwd is a password. I want to require that the password be a minimum of 7 chars, contain at least one number, at least one upper case letter & at least one lower case.

I know enough Javascript that I can "manually" build a function that does all this but it's a pain. Obviously the length is trivial, etc.

Thought maybe somebody did it already.

Thanks
Richard KortsBusiness Owner / Chief DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Everyone's interpretation of what they require from a password will vary.  There are jQuery plugins that do this for you, and there are also regex available to do it yourself.

This one looks really good: https://github.com/ablanco/jquery.pwstrength.bootstrap/blob/1.2.2/README.md.  Allows you to set a score that has to be met.

Remember that you will also have to do server side validation as it would be simple enough to bypass this.
Julian HansenCommented:
Further to Rob's comments here is a bit of code that will do what you want
var password = $('#password').val();
var regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,12}$/;
if (!password.match(regex)) {
  alert('Password must be 8-12 chars with 1 upper, 1 lower and 1 digit char');
}

Open in new window

Working sample here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.