Socket
Socket
Sign inDemoInstall

js-laravel-validation

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-laravel-validation - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

2

package.json
{
"name": "js-laravel-validation",
"version": "1.0.6",
"version": "1.0.7",
"description": "Laravel style form validation for JavaScript",

@@ -5,0 +5,0 @@ "main": "index.js",

# JS-Laravel-validation
## Setup
All rules are base on documentation from https://laravel.com/docs/5.7/validation#available-validation-rules
Set custom messages:
```javascript
import { validate } from 'js-laravel-validation'
validate.setCustomMessage('required', ({ key, value }) => `${key} field is required.`)
```
The parameter to your `createMessage` function will the same field object you supplied in your `formData`. Differences are it will have a `key` prop with the field name, and the `validation` prop will be an array of rules (with parameters if any)
## Setup
E.g:
Install: `npm install js-laravel-validation`
```javascript
validateForm({
name: {
value: "c mcg",
validation: 'required|string',
label: 'Full Name', //Custom property
}
})
```
will call the custom message function with
```javascript
{
key: 'name',
validation: ['required', 'string'],
value: "c mcg",
label: 'Full Name',
}
```
## Usage
Currently no dist is provided
```javascript

@@ -56,16 +27,31 @@ import { validateForm } from 'js-laravel-validation'

const result = validateForm({
formData,
includeMessages: true,
});
const result = validateForm({ formData });
if (result.errors) {
Object.keys(result.errors).forEach(key => {
const errors = result.errors[key];
errors.forEach(error => {
console.log(`invalid field field=${key} rule=${error.rule} messages=${error.message}`
}
}
//handle errors
}
```
## API
| Function Name | Description |
| ------------- | ------------- |
| validateForm(options) | Takes a number of options to validate the specified form data |
| getMessage(rule, fieldData) | Gets an error message for the specified rule and field data |
| setMessageHandler(rule, createMessage) | Sets or replaces the current message handler for the specified rule |
| setMessageHandlers(messages) | Replaces multiple message handers |
| getMessageHandler(rule) | Returns the current message handler function for the specified rule |
Function documentation to come
## 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
- dimensions
- mimetypes
- mime
- not_regex
- regex
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc