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 8169531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:52:16+00:00 2026-06-06T20:52:16+00:00

I am providing a validation feature on a form for passwords. I need to

  • 0

I am providing a validation feature on a form for passwords. I need to be able to implement a few validation rules and have them all checked on submit. Now to me the code is sound but I think they may be some logic error in my code that I’m too tired to notice (too the coffee machine!)

Here’s the JavaScript:

<script type="text/javascript">
<!--
    function validate(registerForm)
    registerForm.onsubmit=function()
    {
        var pw1 = document.forms["register"]["password1"].value;
        var pw2 = document.forms["register"]["password2"].value;

        //Check values are present in both fields
        if(pw1 == '' || pw2 == '')
        {
            alert("Please enter your password twice.");
            return false;
        }
        //Check there no spaces
        else if(document.forms["register"]["password1"].value.indexOf(invalid) > - 1) 
        {
            alert("Spaces are not allowed in passwords!");
            return false;
        }
        //Check passwords are the same
        else
        {
            if(pw1 != pw2) 
            {
                alert("The passwords you entered were not the same. Please try again!");
                return false;
            }
            //Accept passwords
            {
                alert("Password accepted!");
                return true;
            }
        }
    }
-->
</script>

And the HTML Form to go with it:

<form id="register">
    <label for="username">Username</label>
    <input type="text" class="input_text" name="username" id="name" placeholder="e.g. AberLibrary01" />
    <br />
    <label for="password">Password</label> 
    <input type="text" class="input_text" name="password1" id="password1" placeholder="e.g. aber01" />
    <br />
    <label for="re-enterpassword">Re-enter password</label>
    <input type="text" class="input_text" name="password2" id="password2" placeholder="e.g. aber01" />

    <input type="submit" class="button" value="Register" />
    </form>

    <script type="text/javascript">
    <!--
        new validate(document.forms['register']);
    -->
    </script>

Any ideas of lovely StackOverflow community? The exact problem is that it won’t check for spaces in passwords or whether two passwords entered are the same. It successfully checks that there is at least something in both password fields.

Thanks Dan

  • 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-06T20:52:18+00:00Added an answer on June 6, 2026 at 8:52 pm

    This line:

    else if(document.forms["register"]["password1"].value.indexOf(invalid) > - 1) 
    

    invalid is not defined and I suspect this will cause the problems you’re facing.

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

Sidebar

Related Questions

I have a website providing me with 200GB of hosting space. All the files
I'm providing free wifi service and need an ad to be added to all
I have a web form to submit a new user details. In that for
I am working on a registration form, where i am providing validation(spring) for input
I have a generic jQuery validation call in a global JS file: $('form').each(function() {
I have to look into solutions for providing a MySQL database that can handle
I have a fluent validation API that throws an exception when a supplied boolean
I have a form in contact.php with a considerable amount of inputs. this form
I was creating a form. Certian fields of the form store all of those
I have a multi-step form in which some of the fields are collecting sensitive

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.