Tags


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:\/\/)example.com/.test(value);
    }, "The URL must start with https://example.com/");
});
<input type="text" size="15" value="" id="domain" name="domain" class="domain">

Visit this link for additional information : http://jqueryvalidation.org/files/demo/

Advertisements