← Back to jquery-validation/jquery-validation

How to Deploy & Use jquery-validation/jquery-validation

jQuery Validation Plugin Deployment and Usage Guide

Prerequisites

  • Runtime: jQuery v1.5 or later
  • Build Tools: Node.js and npm (for building from source)
  • Optional: RequireJS (for AMD module loading)

Installation

Option 1: Using Prebuilt Files

  1. Download the prebuilt files from the official website: https://jqueryvalidation.org/

Option 2: Building from Source

  1. Clone the repository:

    git clone https://github.com/jquery-validation/jquery-validation.git
    cd jquery-validation
    
  2. Install dependencies:

    npm install
    
  3. Build the project:

    npm run build
    

    This creates the built files in the "dist" directory.

Option 3: Using Package Managers

  • npm:

    npm install jquery-validation
    
  • yarn:

    yarn add jquery-validation
    

Configuration

Basic Setup

Include jQuery and the plugin on your page:

<form>
    <input required>
</form>
<script src="jquery.js"></script>
<script src="jquery.validate.js"></script>
<script>
    $("form").validate();
</script>

AMD Module Loading

For RequireJS integration:

define(["jquery", "jquery.validate"], function($) {
    $("form").validate();
});

Form Validation Rules

Configure validation rules and customizations as needed. Refer to the documentation for detailed options.

Build & Run

Development

  1. Start a local development server:

    npm run dev
    
  2. Open your browser and navigate to the development server URL.

Production

  1. Build for production:

    npm run build
    
  2. Deploy the contents of the "dist" directory to your production server.

Deployment

Static Hosting

The plugin can be deployed on any static hosting service:

  • GitHub Pages: Push your built files to the gh-pages branch
  • Netlify: Connect your repository and deploy automatically
  • Vercel: Deploy your static files with zero configuration

CDN Integration

Use CDN services to include the plugin:

<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js"></script>

Troubleshooting

Common Issues

  1. Plugin Not Working

    • Ensure jQuery is loaded before the validation plugin
    • Check for JavaScript errors in the browser console
    • Verify the correct version of jQuery is being used (v1.5+)
  2. Form Validation Not Triggering

    • Make sure the form has the required attribute on input fields
    • Check that the validate() method is called after the DOM is ready
  3. Email Validation Issues

    • As of version 1.12.0, the plugin uses HTML5 specification for email validation
    • For custom email validation, use jQuery.validator.addMethod()
  4. Required Method Behavior

    • As of version 1.14.0, white spaces are not trimmed automatically
    • Use the normalizer option to trim values:
      $("#myForm").validate({
          rules: {
              username: {
                  required: true,
                  normalizer: function(value) {
                      return $.trim(value);
                  }
              }
          }
      });
      
  5. Accessibility Issues

    • Use the errorElement parameter for better screen reader support:
      $("#myform").validate({
        errorElement: "span"
      });
      

Getting Help