1.0.9 • Published 4 years ago

validation-rule-base v1.0.9

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

Validation Laravel Base - Js Standalone Validation Library

Js Standalone library for validating data.

Features

  • Validate type of variables.
  • Validate size,lenght.
  • FILES validation.
  • Custom attribute caption.
  • Multi language messages.

Quick Start

💿 Installation

on npm

npm i validation-rule-base

CDN

https://cdn.jsdelivr.net/npm/validation-rule-base/dist/Validate.js

🚀 Import

import Validate from "validation-rule-base/src/class/Validate"
Or
const Validate=require('validation-rule-base/src/class/Validate')

📝Config

you can set default messages language with set_locale

let validation=new Validate();
validation.set_locale(); //default language 'fa'
Or
validation.set_locale('en'); //set default language to 'en'

⚡ Usage

Initial data

let validation=new Validate();

let data={
  full_name:'mohammad kavosi',
  birthday_date:'1998/08/28',
  email:'kavosi1010@gmail.com'
};

let rules={
  full_name:'required|min_len:20|max_len:40',
  birthday_date:'required|date',
  email:'required|email',
};

validation.init(data,rules).validate();

⏳ Validate

check result validation

if (!validation.isValid()){  // return true or false
	// something ....
  }

get first message

validation.getFirstError();

/*
default language 'fa'
.نام و نام خانوادگی حداقل باید 20 کاراکتر باشد
or 'en'
The full_name must be at least 20.
*/

get all messages

validation.getErrors(); // return array

get message with key

validation.getErrors('full_name'); // return array

set custom caption for attribute

let captions={
  full_name:'نام و نام خانوادگی'
};
validation.setCaptions(captions);

🎁 Rules

required

The field under validation must be present in the input data and not empty. A field is considered "empty" if one of the following conditions are true:

  • The value is null.
  • The value is an empty string.
  • The value is an empty array or empty Countable object.

email

The field under validation must be formatted as an e-mail address.

IP

The field under validation must be an IP address.

URL

The field under validation must be a valid URL.

date

The field under validation must be a valid.

integer

The field under validation must be an integer.

boolean

The field under validation must be an boolean.

json

The field under validation must be a valid JSON string..

minvalue:_value

The field under validation must have a minimum value .

maxvalue:_value

The field under validation must have a maximum value .

betweenvalue:_min,max

The field under validation must have a size between the given min and max.

len:value

The field under validation must have an exact length of value.

minlen:_value

The field under validation must have an exact minimum length of value.

maxlen:_value

The field under validation must have an exact maximum length of value.

betweenlen:_min,max

The field under validation must have a length between the given min and max.

confirmed:confirmation_name

The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.

mime:(type,...)

The file under validation must have a MIME type corresponding to one of the listed extensions.

'profile' => 'mimes:jpeg,bmp,png'

minfile_size:_value(kb)

The field under validation must have a min file size matching the given value.

maxfile_size:_value(kb)

The field under validation must have a max file size matching the given value.

alpha

The field under validation must be entirely alphabetic characters.

alpha_num

The field under validation must be entirely alpha-numeric characters.

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago