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>

1 comment:

  1. My friend Suggest me this blog and I can say this is the best blog to get the basic knowledge.Thank you so much for this Selenium Training in Chennai

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...