jquery determines whether the input password is equal two times _jquery

Source: Internet
Author: User

The Jquery Easyui is a very good UI framework, but there is no most common validation in form validation for the equality of values in the two output boxes, so I did an extension.

$.extend ($.fn.validatebox.defaults.rules, {/  
  * must be equal to a field/* 
  Equalto: { 
    validator:function (Value,param) {return 
      $ (param[0]). val () = = value; 
    }, Message 
    : ' Field mismatch ' 
  } 
       
}; 

Use examples:

Password: <input id= "password" name= "password" validtype= "length[4,32" class= "Easyui-validatebox" required= "true" type= "Password" value= "/> 
<br/> 
Confirm password: <input type=" password "name=" Repassword "id=" Repassword " Required= "true" class= "Easyui-validatebox" validtype= "equalto[' #password ']" invalidmessage= "two-time input password mismatch"/> 

You can specify the Validtype property as equalto[' #password '.
Of course Use this widget, must first reference jquery Easyui JS Library.

Using Jquery.validate to verify that the two passwords in the form are consistent is a little bit of a problem, and this is the code I wrote:

$ ("#aspnetForm"). Validate ({rules: {txtname: {required:true}, txttr Uename: {required:true}, Txtpass: {required:true, minlength: 3}, Txttwopass: {required:true, Minlength:3, Equalto: "#txtPas S "}, Txtemail: {required:true, email:true}, Txtaddres
        S: {required:true}, Txtphone: {required:true}}, Messages: {txtname: {required: "* Please enter user name"}, Txttruename: {requ
          ired: "* Please enter Name"}, Txtpass: {required: "* Please enter password", minlength: "* Password cannot be less than 3 characters" }, Txttwopass: {required: "* Please enter confirmation password", minlength: "* Password cannot be less than 3 characters", equal
       To: "* Please enter the same value again"   }, Txtemail: {required: "* Please enter the mailbox", Email: "* Please enter the correct mailbox format"}, Txtadd
        Ress: {required: "* Please enter Address"}, Txtphone: {required: "* Please enter your mobile number"}
 }
      });

Why do I enter the password two times is consistent and always prompted me? You've tried different browsers and different versions of validate.

I do not know if you have encountered similar problems, I have consulted a number of articles, summed up the problem-solving ideas:

    • First go to see if the two password of the HTML page are assigned a value ID.
    • Or retrieve the two-Txtpass ID of the next page.
    • Or you can remove the Equalto first, in the re-verification, to see if there are other errors, did not come back to troubleshoot the place.

I hope this article can give you some inspiration, thank you for reading, small series will continue to redouble their efforts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.