New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

js-object-validation

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-object-validation

Simple object validator written in Pure Javascript

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
17
142.86%
Maintainers
1
Weekly downloads
 
Created
Source

Simple JS validation for forms

This is basically aimed to validate forms in reactjs.

installation

using npm

npm i js-object-validation

or

npm install js-object-validation

using yarn

yarn add js-object-validation

Benifits

Pure JS

Customizable messages

No dependencies

Easy to use.

Usage

import Validator from "js-object-validation";

try{
  const objectToValidate = {
    email: "sbamniya23",
    password: "12"
  }
  const validations = {
    email: {
      email: true,
    },
    password: {
      minlength: 8,
    }
  }
  const messages = {
    email: {
      email: "Email should be valid email",
    },
    password: {
      minlength: "Password should be at least 8 charater long",
    }
  } // this is optional

  const {isValid, errors} = Validator(objectToValidate, validations, messages);
  if(isValid){
    <!-- object has passed all validations -->
  } else {
    <!-- object has some error -->
    console.log(errors)
  }
} catch(error) {
  console.log(error)
}

Validation types Options

Required

required

Valid email

email

Valid number

numeric

Max number

maxnumber

Min number

minnumbers

Valid Alphanumeric

alphanumeric

Valid Alphabetic string

alpha

Maxlength

maxlength

Min lenght

minlength

Compare two fields

equal

Strong Password

password

Username

username

Valid URL

url

Update

Fixed Issue #1

Added Validations for Password and Username

Update 2

Added typescript defination and removed ENUM for clear management

Want to contribute/update ?

If you have any new update/idea feel free to contact.

sbamniya23@gmail.com

Contributors

@sbamniya

Keywords

form-validator

FAQs

Package last updated on 09 Jan 2020

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