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

  • SEARCH
  • Home
  • 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 8847869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:17:36+00:00 2026-06-14T12:17:36+00:00

How to check passwords match before form submission in Javascript. My below code is

  • 0

How to check passwords match before form submission in Javascript. My below code is when I retype the password it should display “password doesn’t match” if they are not the same. How can I add that?

My JSP page

<body bgcolor="#33CCCC">
<form name="reg" action="Register" method="post" onsubmit="return validate()">
    <table cellpadding=4 cellspacing=2 border=1 align="center">
        <tr>
            <th bgcolor="#999999" colspan=2>
                <b>
                    First Name<sup>
                    *</sup>
                </b>
                <br>
                <input type="text" name="firstname" value="" size=15 maxlength=20>
                </td>
                <td valign=top>
                    <br>
                    <input type="text" name="surname" value="" size=15 maxlength=20>
                </td>
        </tr>
        <tr bgcolor="#999966">
            <td valign=top>
                <b>
                    E-Mail<sup>
                    *</sup>
                </b>
                <br>
                <input type="text" name="email" value="" size=25 maxlength=125>
                <br>
            </td>
            <td valign=top>
                <b>
                    Zip Code<sup>
                    *</sup>
                </b>
                <br>
                <input type="text" name="zipcode" value="" size=5 maxlength=6>
            </td>
        </tr>
        <tr bgcolor="#999966">
            <td valign=top colspan=2>
                <b>
                    User Name<sup>
                    *</sup>
                </b>
                <br>
                <input type="text" name="uid" size=10 value="e" maxlength=10>
            </td>
        </tr>
        <tr bgcolor="#999966">
            <td valign=top>
                <b>
                    Password<sup>
                    *</sup>
                </b>
                <br>
                <input type="password" name="pwd" size=10 value="" maxlength=10>
            </td>
            <td valign=top>
                <b>
                    Confirm Password<sup>
                    *</sup>
                </b>
                <br>
                <input type="password" name="cpwd " size=10 value="" maxlength=10>
            </td>
        </tr>
        <tr bgcolor="#999966">
            <td valign=top colspan=2>
                <b>
                    Town:<sup>
                    *</sup>
                </b>
                <br>
                <input type="text" name="town" size=10 value="" maxlength=10>
                <br>
            </td>
        </tr>
        <tr bgcolor="#999966">
            <td valign=top colspan=2>
                <b>
                    City:<sup>
                    *</sup>
                </b>
                <br>
                <input type="text" name="city" size=10 value="" maxlength=10>
                <br>
            </td>
        </tr>
        <tr bgcolor="#663300">
            <td align=center colspan=2>
                <hr>
                <input type="submit" value="Submit">
            </td>
        </tr>
    </table>
</form>
</body>

and my JS

<script>
    function validate() {
        var auser = document.reg.firstname.value;
        var invalid = /\W/;
        //Alphanumeric characters and Underscore permitted 
        if (auser == "") {
            alert("Enter First name!");
            return false;
        }
        var aname = document.reg.surname.value;
        invalid = /[\W_]/;
        //Alphabets and digits only allowed 
        if (apass == "") {
            alert("Enter Second name!");
            return false;
        }
        var apass = document.reg.pwd.value;
        invalid = /[\W_]/;
        //Alphabets and digits only allowed 
        if (apass == "") {
            alert("Enter password!");
            return false;
        }
        var apassnew = document.reg.cpwd.value;
        invalid = /[\W_]/;
        //Alphabets and digits only allowed 
        if (apass == "") {
            alert("Confirm password!");
            return false;
        }
    }
</script>
  • 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-06-14T12:17:38+00:00Added an answer on June 14, 2026 at 12:17 pm

    Try adding this to your last code:

    if(apass=="") { 
    alert("Confirm password!"); 
    return false; 
    } else if(apass != document.reg.pwd.value){
    alert("Confirm Password doesn't match"); 
    return false; 
    }
    

    and why are you making new variable apass everytime ?

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

Sidebar

Related Questions

Got a simple Javascript program here to accept and check a password. It should:
I am doing a client side form validation to check if passwords match. But
How can I check whether password match or not in primefaces + javascript? I
I have a change password screen and when the 2 passwords match i need
First: I'm JavaScript newbie. So.. I have basic form with password, repeat password, email
Jquery: <script type=text/javascript> $(document).ready(function(){ $(form.register).change(function() { $.post(check.php, $(form.register).serialize(), function( data ) { if( data.username
I have the following PHP code which is attempting to check for password complexity
So, I try to check if passwords match. This is the encryption I use,
I'm using a little script to check the password strength in an inscription form,
I want to check password strength of password entered by user in Asp.Net page.

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.