Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pre-post-validation

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pre-post-validation

simple javascript libaray for user input validation before POST request

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

PRE-POST-VALIDATION

This is a very simple to use javascript library for professionally validating the user input before POST request for Login and Register.

fields include name, email, password, confirm_password

The validation checks for the following

Name must be between 2 and 30 characters, Name required, Email required and is not invalid, Password required and must be at least 6 characters, Confirm Password field is required, Passwords must match.

practical usage

Run npm install pre-post-validation

and then

const validateRegisterInput = require('pre-post-validation');
// or you can import like this
import { validateRegisterInput } from 'pre-post-validation';


const validateLoginInput = require('pre-post-validation');
// or you can import like this
import { validateRegisterInput } from 'pre-post-validation';

The functions are called with (data) property which includes the user data. and return errors and isValid.

const router = express.Router();

router.post('/register', (req, res) => {

const { errors, isValid } = validateRegisterInput(req.body);

     if (!isValid) {

        return res.status(400).json(errors);
    }
    else {
        // add your logic after the validation passed.
    }
}

router.post('/Login', (req, res) => {

const { errors, isValid } = validateLoginInput(data);

    if (!isValid) {

        return res.status(400).json(errors);
    }
    else {
        // add your logic after the validation passed.
    }
}

Every time you call this function you have to do some destructuring by taking out const { errors, isValid } and check isValid property for validation.

FAQs

Package last updated on 22 Dec 2018

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

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