Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6595019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:53:07+00:00 2026-05-25T17:53:07+00:00

I have to make a password meter from scratch basically (can’t use outside frameworks

  • 0

I have to make a password meter from scratch basically (can’t use outside frameworks like jquery), and I’m having 2 problems.

I can’t seem to find a way where when a user enters a certain character, it won’t jump the meter to a huge length.

And I can’t prevent that meter from getting to big, even by setting the width.

<input type="password" id="newPass" style="width:206px" onkeyup="strengthMeter()"/><br/><br/>
                <div style="width:100px;display:inline;"><div id="meter" style="background-color:red;width:10px;height:10px;"></div>
                    <span>Strength</span><span id="strength" style="float:right">Weak</span>
                </div>

function strengthMeter(){


    var password = $("newPass").value;
    var numEx = /\d/;
    var lcEx = new RegExp("[a-z]");
    var ucEx = new RegExp("[A-Z]");
    var symbols = ['/', '@', '#', '%', '&', '.', '!', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\\'];
    var meterMult = 1;

    for(var k = 0; k < password.length; k++){
        if(numEx.test(password)){
            meterMult += 0.75;
            $("meter").style.width = " " + (10*meterMult) + "px";
        }

        if(ucEx.test(password)){
            meterMult += 1;
            $("meter").style.width = " " + (10*meterMult) + "px";
        }

        if(lcEx.test(password)){
            meterMult += 0.25;
            $("meter").style.width = " " + (10*meterMult) + "px";
        }

        for(var i = 0; i < symbols.length; i++){
            if(password.indexOf(symbols[i]) >= 0){
                meterMult += 1;
                $("meter").style.width = " " + (10*meterMult) + "px";
            }
            }
        if(meterMult >= 12){
            $("strength").innerHTML = "Strong";
            }
        else if(k >= 6){
            $("strength").innerHTML = "Medium";
        }
        else
            $("strength").innerHTML = "Weak";
        }

    }

The above has the div i am using to make the meter. basically, I am taking a div and expanding it within another div to make the meter, and that’s that. Please help! Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:53:08+00:00Added an answer on May 25, 2026 at 5:53 pm

    I’ve reduced your code to a working jsFiddle. I see a couple funky things in the code that perhaps need to get sorted out first.

    First, there appears to be no reason for this loop as all it’s doing is running the same code over and over again password.length times:

    for(var k = 0; k < password.length; k++){
    

    Did you mean to be examining each character in the password, one at a time in that loop? If so, that’s not what your code is doing.

    As for the width, I would suggest that the easiest way is to set the width of the container to the max width you want and then set the width of the meter to be a percentage of the parent from 0 to 100.

    Here’s a new version of your code (working here in a jsFiddle), revised in a bunch of ways:

    1. Changed the width of the red bar to a percentage of it’s parent and capped it at 100% so it will never go beyond the parent width.
    2. Check each char in the password individually
    3. Set the width of the password bar only once
    4. Change the layout of the bar to match the width of the input field

    Here’s the code from the new version:

    function strengthMeter() {
        var password = $("newPass").value;
        var numEx = /\d/;
        var lcEx = /[a-z]/;
        var ucEx = /[A-Z]/;
        var symbols = ['/', '@', '#', '%', '&', '.', '!', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\\'];
        var meterMult = 1;
    
        for (var k = 0; k < password.length; k++) {
            var pchar = password.charAt(k);
            if(numEx.test(pchar)){
                meterMult += 0.75;
            }
    
            if(ucEx.test(pchar)){
                meterMult += 1;
            }
    
            if(lcEx.test(pchar)){
                meterMult += 0.25;
            }
        }
    
        for (var i = 0; i < symbols.length; i++) {
            if(password.indexOf(symbols[i]) >= 0) {
                meterMult += 1;
            }
        }
    
        // assume that 100% is a meterMult of 15
        var fullStrength = 15;
        $("meter").style.width = ((Math.min(fullStrength, meterMult)/fullStrength )*100) + "%";
    
        if(meterMult >= 12) {
            $("strength").innerHTML = "Strong";
        }
        else if(password.length >= 6) {
            $("strength").innerHTML = "Medium";
        }
        else {
            $("strength").innerHTML = "Weak";
        }
    }
    

    Obviously, you may want to tweak the weighting as desired.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a control which I have to make large modifications to. I'd like
I have to make a connection to an XMLRPC site from a web application,
I have a sign-in-action-form page which accept username and password from sign-in-form. Now most
I am trying to make the browser's password manager remember the input from the
I have to make column charts in Excel using VBA only (no user input).
I have to make a schema for an XML format that's already being used.
For my university assignment I have to make a networkable version of pacman. I
In our application we sometimes have to make minor GUI modifications for different customers:
I'm working on an application where users have to make a call and type
I'm busy with an asignment where i have to make a graphical interface for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.