Add a custom method in jQuery validation plugin

jQuery validate plugin has rich set of method to validate html form. To add custom method of validation in this plugin see following example which shows add domain validation method to html input box.

jQuery(document).ready(function($) {
    jQuery.validator.addMethod("domain", function(value, element) {
        return this.optional(element) || /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/);
    }, "The URL must start with");
<input type="text" size="15" value="" id="domain" name="domain" class="domain">

Visit this link for additional information :


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s