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 🙏

© 2024 – Pkg Stats / Ryan Hefner

brformsvalidator

v2.0.1

Published

FormsValidator is a comprehensive JavaScript library designed to validate various types of form inputs. This library provides a robust set of validators for common form fields such as CNPJ, CPF, email, name, date, and username. It ensures that the data en

Downloads

121

Readme

FormsValidator

Overview

FormsValidator is a comprehensive JavaScript library designed to validate various types of form inputs. This library provides a robust set of validators for common form fields such as CNPJ, CPF, email, name, date, and username. It ensures that the data entered by users meets the required format and constraints, making it easier to handle form validation in web applications.

This module is primarily targeted at Brazilian users, as it includes specific validations for Brazilian documents such as CNPJ and CPF. However, it can also be used by people from other countries. Pull requests for the inclusion of validations for documents from other countries are welcome.

All documentation for the module can be found on GitHub: FormsValidator Documentation.

Features

  • CNPJ Validation: Validates Brazilian CNPJ numbers.
  • CPF Validation: Validates Brazilian CPF numbers.
  • Email Validation: Ensures the email address is in the correct format.
  • Name Validation: Validates first name and surname.
  • Date Validation: Validates dates in both Brazilian and US formats.
  • Username Validation: Ensures the username meets specified length constraints.

Installation

To install FormsValidator, you can use the following commands:

Install as a Dependency

npm install brformsvalidator

Install as a Production Dependency

npm install brformsvalidator --save

Install as a Development Dependency

npm install brformsvalidator --save-dev

Usage

You can create an instance of FormsValidator by passing the form input values to the constructor. It is possible to create an instance without using all parameters because the remaining parameters will be ignored due to having default falsy values. This allows you to use the module for specific validations such as only CPF and name, only CPF, only email, etc.

Importing the Module

To import the module in Node.js, assuming you have installed it via npm in the node_modules folder, use the following code:

const FormsValidator = require('formsvalidator');

Example

const formValidator = new FormsValidator('11.444.777/0001-61', '123.456.789-09', '[email protected]', 'John', 'Doe', '01/01/2000', '01/01/2000', 'johndoe');

console.log(formValidator.validateCnpj()); // true or false
console.log(formValidator.cnpj); // Formatted CNPJ

console.log(formValidator.validateCpf()); // true or false
console.log(formValidator.cpf); // Formatted CPF

console.log(formValidator.validateEmail()); // true or false
console.log(formValidator.email); // Email address

console.log(formValidator.validateName()); // true or false
console.log(formValidator.completeName); // Full name

console.log(formValidator.validateDate()); // true or false
console.log(formValidator.date); // Date

console.log(formValidator.validateUsDate()); // true or false
console.log(formValidator.usDate); // US Date

console.log(formValidator.validateUsername()); // true or false
console.log(formValidator.username); // Username

Using Only Specific Validators

You can also create an instance of FormsValidator with only the parameters you need:

Example: Only CPF and Name

const formValidator = new FormsValidator('', '123.456.789-09', '', 'John', 'Doe');

console.log(formValidator.validateCpf()); // true or false
console.log(formValidator.cpf); // Formatted CPF

console.log(formValidator.validateName()); // true or false
console.log(formValidator.completeName); // Full name

Example: Only Email

const formValidator = new FormsValidator('', '', '[email protected]');

console.log(formValidator.validateEmail()); // true or false
console.log(formValidator.email); // Email address

Methods and Properties

CNPJ

  • validateCnpj(): Validates the CNPJ.
  • cnpj: Returns the formatted CNPJ.

CPF

  • validateCpf(): Validates the CPF.
  • cpf: Returns the formatted CPF.

Email

  • validateEmail(): Validates the email address.
  • email: Gets or sets the email address.

Name

  • validateName(): Validates the name.
  • name: Gets or sets the first name.
  • surname: Gets or sets the surname.
  • completeName: Returns the full name (first name + surname).

Date

  • validateDate(): Validates the date in Brazilian format.
  • date: Gets or sets the date.

US Date

  • validateUsDate(): Validates the date in US format.
  • usDate: Gets or sets the US date.

Username

  • validateUsername(): Validates the username.
  • username: Gets or sets the username.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss any changes or improvements. We especially encourage contributions for the inclusion of validations for documents from other countries.

License

This project is licensed under the MIT License.