javascriptasp.netasp.net-membership.net-2.0

Matching password in .Net validate by JavaScript?


I have two textbox in Asp.Net: first for password and second is for a matching password.

How can I validate whether user entered different value in both textboxes through JavaScript at client side?


Solution

  • The simplest js for this would be

    if(document.getElementById('password1').value != document.getElementById('password2').value){
        // they do not match
    }
    

    But if you are using .NET, you might want to take the advice to use a CompareValidator.