npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

form-my-simple-validation

v0.0.11

Published

[![Build Status](https://travis-ci.com/DanielAdek/form-my-simple-validation.svg?branch=master)](https://travis-ci.com/DanielAdek/form-my-simple-validation) [![Coverage Status](https://coveralls.io/repos/github/DanielAdek/form-my-simple-validation/badge.sv

Readme

form-my-simple-validation

Build Status Coverage Status Maintainability npm version dependency badge license issues

Table of Contents

Introduction

As a JavaScript web developer, you will always need to validate your forms where applicable, ensuring that each input fields are properly taken care of, to avoid unexpected errors in your application.

Sometimes, validating input fields can be really boring and time consuming. To save your time and avoid boring moment, this package can help take care of some simple validations. All you have to do is: form-my-simple-validation

This npm-package is created for web applications. It can be applied both on the client-side and server-side JavaScript application.

Installation

$ npm install form-my-simple-validation

If you are using yarn, then run the below.

$ yarn add form-my-simple-validation

Usage

Import the package
const { Form } = require('form-my-simple-validation');

// OR,

// if you have a babel configured for your project, use:
import { Form } from 'form-my-simple-validation';
Call the function
const validationResult = Form.validateFields(formType, formSchema, userForm, customeError, allowNullOrUndefinedValue);

if (validationResult.error) {
    console.log(validationResult); // this will console an object
}
Params

The first three parameters are compulsory, while the rest are optional. The table below explains params.

|Params | Data-Types | Description -------------------|-------------------|-------------- formType (required) | String | The type of form you want to perform validation on. (Note: The form type should be written as is, in the formSchema)| formSchema (required) | Object | The schema for validating your form | userForm (required) | Object | User form i.e an object containing form details, with the keys corresponding to the fields specified in your schema | customError (optional) | String or object | The message you want to return when validation requirement is not met. This field is optional because a default message is returned if customError is not specifield or when set to null.| allowNullOrUndefinedValue (optional) | Boolean | When set to false, an error message is returned when null or undefined is passed as a value to the user form object. |

Usage example.

You need to create a schema as a validation requirement for the user-form object, in the format below:

Note: you may create schema in a separate JavaScript file.

formSchema.js file

// Sample form schema for sign-up
const Schema =  {
  form: {
    formType: 'signup',
    Email: { field: 'email', isEmail: true, required: true },
    FullName: { field: 'fullName', required: true, isName: true },
    Phone: { field: 'phoneNumber', required: true, isPhoneNumber: true },
    Password: {
      field: 'password', required: true, minLength: 8, maxLength: 15
    },
  }
};

module.exports = Schema;

// OR

// if you have configured babel in your project, use:
export default Schema;

sample.js file


const { Form } = require('form-my-simple-validation');
const formSchema = require('./path-to-formSchema-js-file')

// OR,

// if you have a babel configured for your project, use:
import { Form } from 'form-my-simple-validation';
import formSchema from './path-to-formSchema-js-file';

// sample user form object
const userForm = {
  fullName: 'Daniel Adek',
  phoneNumber: '+2348100000001',
  email: 'wrong-email.com', // note: email does not meet requirement in the formSchema, email field (isEmail: true) 
  password: '12345678'
}

// Note: the keys in userForm corresponds to the fields in the schema object above e.g email correspond to Schema.form.Email.field

const validationResult = Form.validateFields('signup', formSchema, userForm);

if (validationResult.error) {
    console.log(validationResult); // result is shown below
}

// validation result sample
"error": {
  "error": true,
  "Stacktrace": "ValidationError",
  "metadata": [
    {
      "statusCode": 400,
      "field": "email",
      "target": "SIGNUP"
    }
  ],
  "message": "email is invalid. Email should look like e.g [email protected]",
  "details": {
  "error": true,
  "operationStatus": "Processs Terminated!"
  }
}

APIs

The following is a table of the options you can use in your schema for validation requirement.

| Options | Values(DataTypes) | Description ------------------------ | --------------------- | ------------------- | required | true or false (Boolean) | Set true value to ensure that the input field should not be empty and vice versa. | | isEmail | true or false (Boolean) | This will ensure that the value entered is a valid email format. e.g not-email-format will not be accepted but [email protected] will be accepted. (Note: this does not validate valid email address, only deals with format) | | isName | true or false (Boolean) | This ensures that special characters like (#,:,0-9,%, e.t.c) should not be included in a name field. Input field allows spaces, a comma, a dot between names, e.g Daniel, Adek, John Doe, but does not accept values like Daniel Adek2, or John? Doe!. | | isPhoneNumber | true or false (Boolean) | Input field will accept only a valid phone number format. e.g +2348100000001 but does not accept +234-81-00-0-00-001 (Note: this does not validate valid number, only deals with format) | | isInteger | true or false (Boolean) | Input field accepts integer value only. | | range | { from: Number, to: Number } (Object) | This ensures that the input value for this field is within the range specification in the formSchema | | isDecimal | true or false (Boolean)| Input field accepts only decimal values. | isAlpha | true or false (Boolean) | Input field only accept alphabets. It does not allow space or special characters. | | minLength | Number | Validate the field and ensure that the characters it is not lesser than specifield minimum length. | | maxLength | Number | Validate the field and ensure that the characters it is not more than specifield maximum length. | | isArray | true or false (Boolean) | This only allows array as the value. | | isObject | true or false (Boolean) | Only allows object as value |

License

The MIT License

Copyright © 2019 DanielAdek