Wednesday, May 14, 2014

validation of two Password Match

 

 Validation of two Password Match

 

I make a project and i want to match both password .

if password same then carry on ...

else abort . ...............................

 


example:


--------------

 

 

 
 
 
 
 
<script type="text/javascript">
function validate()
     {
        var pw1 = document.getElementById("password1").value;
        var pw2 = document.getElementById("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.getElementById("password1").value.indexOf(" ") > - 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;
            }
            else
            {
                alert("Password accepted!");
                return true;
            }
        }

    }
 </script>
</head>

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

    <input type="submit" class="button" onclick="validate()" value="Register" />
    </form>
</body>
</html>

No comments:

Post a Comment

GitHub repository using Git Bash command

  To add a project to a GitHub repository using Git Bash command line, you can follow these steps: Create a new repository on GitHub by logg...