3.1.3 • Published 2 years ago

js-laravel-validation2 v3.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

js-laravel-validation2 npm version Build Status

Useful for having consistent server side and client side validation with Laravel

All rules are base on documentation from https://laravel.com/docs/9.x/validation#available-validation-rules

IMPORTANT NOTE

This package is NOT THE SAME as js-laravel-validation.

That package attempts to validate IN THE STYLE of Laravel.

This package validates with the goal of pushing TO Laravel.

js-laravel-validation returns false on the rule 'numeric' for the value '123' because it is a string.

Therefore, this packages attempts to convert parseable parameter strings into numbers before doing validation.

You MUST however pass a numeric value to compare against.

In this package the string '123' passes the rule 'numeric|gt:0'

Setup

Install: npm install js-laravel-validation2

Usage

  import { validateForm } from "js-laravel-validation2";

  const formData = {
    username: {
      value: "test1",
      validation: "required|string"
    },
    password: {
      value: null,
      validation: "required|string"
    }
  };

  const result = validateForm({ formData });

  if (result.errors) {
    console.log(result.errors); // will be { password: ['required', 'string'] }
  }

Docs

Function NameDescription
validateForm(options)Takes a number of options to validate the form data
setMessageHandler(rule, createMessage)Sets or replaces the current message handler for the specified rule
setMessageHandlers(messages)Replaces multiple message handers

Missing Rules

  • active_url
    • This cannot be supported because JS does not support hostname lookups (dns_get_record in PHP)
    • This could be implemented if there was a reliable way to host a small API to do the lookup
  • date_format
    • This can be added with something like return new Date(value).format(params[0]) === value;
    • Unfortunately that isn't so easy in vanilla js atm
  • exists & unqiue

    • These are both rules relating to the database
  • not_regex (to come)

  • regex (to come)

    • Regex requires extra parsing to remove forward slashes around regex
3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.2

2 years ago