JQuery Validate plugin How to customize the validation method (combined with Ajax to implement database duplicate checking)

Source: Internet
Author: User
Overview
        本文介绍Validate自定义表单校验方式。Validate插件虽然提供了丰富的验证规则,但在很多时候仍然很难满足我们的开发需求,在注册页面我们需要通过ajax验证用户输入的用户名是否已经被他人注册,那此时通过传统的Validate验证方式已经无法满足需求了! 我们可以通过自定义验证方法来结合ajax实现这个需求。
Customizing the basic AJAX Syntax

Because validate is a plug-in for jquery, you must first import the jquery and validate JS packages.

    <script type="text/javascript">                //下面开始自定义一个校验规则(addMethod方法传入两个参数,第一个一个是自定义校验规则的规则名称,第二个传入的是校验方法)                $.validator.addMethod(                        "规则名称",                        function(value,element,params){                                //这个是验证所调用函数(校验函数),传入三个参数                                //value:输入的内容(表单元素输入的内容)                                //element:被校验的元素对象                                //params:规则对应的参数值(例:required:true 传入的params就是true)                        }                );    </script>

JQuery Validate plugin How to customize the validation method (combined with Ajax to implement database duplicate checking)

Related Article

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.