šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

jquery-validation

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-validation

Client-side form validation made easy

1.21.0
beta
latest
Source
npm
Version published
Weekly downloads
176K
1.53%
Maintainers
3
Weekly downloads
Ā 
Created

What is jquery-validation?

The jquery-validation npm package is a popular plugin for the jQuery library that provides a simple way to validate forms on the client side. It offers a wide range of validation rules and customization options to ensure that user input meets the required criteria before submission.

What are jquery-validation's main functionalities?

Basic Form Validation

This feature allows you to set up basic form validation rules. In this example, the field 'fieldName' is required and must be at least 2 characters long. Custom error messages are also provided.

$(document).ready(function() {
  $("#myForm").validate({
    rules: {
      fieldName: {
        required: true,
        minlength: 2
      }
    },
    messages: {
      fieldName: {
        required: "This field is required",
        minlength: "Your input must be at least 2 characters long"
      }
    }
  });
});

Custom Validation Methods

This feature allows you to define custom validation methods. In this example, a custom rule 'customRule' is created to ensure that the input contains only letters.

$.validator.addMethod("customRule", function(value, element) {
  return this.optional(element) || /^[a-zA-Z]+$/.test(value);
}, "Please enter only letters");

$(document).ready(function() {
  $("#myForm").validate({
    rules: {
      fieldName: {
        customRule: true
      }
    }
  });
});

Remote Validation

This feature allows you to perform remote validation by making an AJAX request to the server. In this example, the 'username' field is validated against a server endpoint to check if the username is already taken.

$(document).ready(function() {
  $("#myForm").validate({
    rules: {
      username: {
        required: true,
        remote: "/check-username"
      }
    },
    messages: {
      username: {
        required: "Please enter a username",
        remote: "Username is already taken"
      }
    }
  });
});

Other packages similar to jquery-validation

Keywords

jquery

FAQs

Package last updated on 17 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts