In this article I will explain with an example, how to perform Password and Confirm Password validation for Password TextBox using jQuery in ASP.Net.
The values of the Password and Confirm Password TextBoxes are compared using jQuery and if the values do not match an error message is displayed.
 
 
HTML Markup
The following HTML Markup consists of two ASP.Net TextBox and an ASP.Net Button control.
Inside the document ready event handler, the Button has been assigned a jQuery Click event.
When the Submit Button is clicked, the values of the Password and the Confirm Password TextBoxes are fetched and are compared.
Note: Here I am making use of jQuery Wildcard selectors for ASP.Net TextBox selection. For more details, please refer my article Get Client ID of ASP.Net control in JavaScript and jQuery.
 
If the values do not match, an error message is displayed using JavaScript Alert Message Box and False value is returned in order to stop the form submission.
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>Password</td>
        <td><asp:TextBox ID="txtPassword" runat="server" TextMode="Password" /></td>
    </tr>
    <tr>
        <td>Confirm Password</td>
        <td><asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" /></td>
    </tr>
    <tr>
        <td></td>
        <td><asp:Button ID="btnSubmit" Text="Submit" runat="server" /></td>
    </tr>
</table>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("[id*=btnSubmit]").click(function () {
            var password = $("[id*=txtPassword]").val();
            var confirmPassword = $("[id*=txtConfirmPassword]").val();
            if (password != confirmPassword) {
                alert("Passwords do not match.");
                return false;
            }
            return true;
        });
    });
</script>
 
 
Screenshot
Password and Confirm Password validation using jQuery in ASP.Net
 
 
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.

 
 
Demo
 
 
Downloads