You must Sign In to post a response.
  • Category: JavaScript

    Validation for min and max for password field

    For password field i have used the below javascript

    if (trim(frm.ctl00_cphBody_txtNewPassword.value.length)<6) {
    alert('Enter minimum 6 characters')
    frm.ctl00_cphBody_txtNewPassword.focus()
    return false
    }

    I am getting an error

    Message: Object doesn't support this property or method.

    Can any one tell me how to write validation for password to check Minimum Maxmimum characters
  • #645441
    Please check this code



    function validate()
    {
    var invalid = " ";
    var minLength = 6;
    var pw1 = document.myForm.password.value;

    if (pw1 == '')
    {
    alert('Please enter your password ');
    return false;
    }

    if (document.myForm.password.value.length < minLength)
    {

    alert('Your password must be at least ' + minLength + ' characters long. ');
    return false;
    }


    Regards
    Mr.Rajesh
    Software Engg.

  • #645442
    Please change your code as follows and check

    if (document.getElementById("<%= txtNewPassword.ClientID").value.length<6) {
    alert('Enter minimum 6 characters')
    document.getElementById("<%= txtNewPassword.ClientID").focus()
    return false
    }

    Thanks and Regards
    Gypson

  • #645462
    You can use Validation controls for this purpose:

    Please check the following code:


    <div>
    Password:
    <asp:TextBox ID="TxtPassword" runat="server" Font-Bold="True" Font-Names="Tahoma"
    Font-Size="10pt" TabIndex="4" TextMode="Password" Width="208px"></asp:TextBox>
    (Min. 6 Characters)
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TxtPassword"
    ErrorMessage="Password Cannot Be Left Blank." Font-Bold="True" Font-Names="Verdana"
    Font-Size="10pt" SetFocusOnError="True" Display="Dynamic"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="TxtPassword"
    ErrorMessage="Password Should Be of Minimum 6 Characters" Font-Bold="True" Font-Names="Verdana"
    Font-Size="10pt" ValidationExpression=".{6}.*" Display="Dynamic"></asp:RegularExpressionValidator>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #648514
    Hi!
    try the code given below
    function validate()
    {
    x=document.myForm
    txt=x.myInput.value
    if (txt>=1 && txt<=5)
    {
    return true
    }
    else
    {
    alert("Must be between 1 and 5")
    return false
    }
    }

    Regards
    Kamlesh

    Regards
    Kamlesh Mohanty


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.