Socket
Socket
Sign inDemoInstall

js-laravel-validation

Package Overview
Dependencies
0
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    js-laravel-validation

Laravel style form validation for JavaScript


Version published
Maintainers
1
Install size
50.0 kB
Created

Readme

Source

js-laravel-validation 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/5.7/validation#available-validation-rules

Setup

Install: npm install js-laravel-validation

Usage

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

  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

Keywords

FAQs

Last updated on 12 Jul 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc