Javascript Library providing form validation helpers

Overview

Javascript-Form-Validation

Codacy Badge NPM Discord Server

Javascript Library providing form validation helpers

Table of contents

Installation

VanillaJS

In order to use this library, download zip file and copy necessary files from dist folder into your assets folder.

NPM

Run

npm install javascript-form-validation

Usage

Include library

VanillaJS

To use the library, start by including the files you need into head section of your project.

<script src="your_directory/EmailField.min.js" defer></script>
<script src="your_directory/PasswordField.min.js" defer></script>

NodeJS

Import and instantiate the validator you want to use (example using Password)

// Import
const Validator = require("javascript-form-validation");

// Instanciation (don't use instanciations documented in "Use components" section below)
let passValidator = new Validator.PasswordField();

Use components

Each component is made to help you validate a single type of data in your project.

Color

The Color component helps you validate the input contains a valid CSS color code (Named, rgb, rgba or hex)

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(color) ⇒ boolean

Param Type Description
color string Color to check
// Instantiation
let myColor = new ColorField(); // replace myColor by variable name of your preference

// Check Color
myColor.isValid("purple");
myColor.isValid("rgba(14, 85, 213, 0.4)");
myColor.isValid("#34D10C");

DateTime

The DateTime component helps you validate the input contains a valid DateTime (based on JS formats)

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(myDate) ⇒ boolean

Param Type Description
myDate string Date to check
// Instantiation
let myDate = new DateTimeField(); // replace myDate by variable name of your preference

// Check DateTime
myDate.isValid("2021-05-31 02:30");

Digits

The Digits component helps you validate the input contains only digits (0-9)

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(myText) ⇒ boolean

Param Type Description
myText string Text to check
// Instantiation
let myText = new DigitsField(); // replace myText by variable name of your preference

// Check string
myText.isValid("012345");

EAN13

The EAN13 component helps you validate the input contains a string that is a valid EAN13 number.

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(ean) ⇒ boolean

Param Type Description
ean string EAN13 to check
// Instantiation
let ean = new Ean13Field(); // replace ean by variable name of your preference

// Check ean
ean.isValid("7612345678900");

Email

The Email component helps you validate the input contains a string that looks like an email. It doesn't validate the email exists.

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(email) ⇒ boolean

Param Type Description
email string Email to check
// Instantiation
let email = new EmailField(); // replace email by variable name of your preference

// Check email
email.isValid("[email protected]");

Iban

The Iban (International Bank Account Number) component helps you validate the input contains a string that is a valid Iban (not that the account exists).

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(iban) ⇒ boolean

Param Type Description
iban string Iban to check
// Instantiation
let iban = new IbanField(); // replace iban by variable name of your preference

// Check iban
iban.isValid("FR1234567890123456789012345");

IP

The IP component helps you validate the input contains a string that is a valid IP address (IPV4 and/or IPV6).

In order to use this component, first instantiate it and then use the isValid method to check it.

During instantiation, provide, if you like, optional parameters as an object to define what you require as IP version.

Parameters are as follows:

Param Type Description Default
ipv4 boolean You check IPV4 version true
ipv6 boolean You check IPV6 version true

isValid(ip) ⇒ boolean

Param Type Description
ip string IP to check
// Instantiation
let ipAddress = new IPField({ipv4: false}); // replace iban by variable name of your preference. This will check only IPV6

// Check ip
ipAddress.isValid("fffe::1");

ISBN

The ISBN (International Standard Book Number) component helps you validate the input contains a string that is a valid ISBN (not that the number exists).

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(isbn) ⇒ boolean

Param Type Description
isbn string Isbn to check
// Instantiation
let isbn = new IsbnField(); // replace isbn by variable name of your preference

// Check isbn
isbn.isValid("978-2-02-130452-7");

JWT

The JWT (JSON Web Token) component helps you validate the input contains a string that is a valid JWT (not that the token exists nor that the signature is correct). **This only validated the token only contains valid characters and is correctly formed.

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(token) ⇒ boolean

Param Type Description
token string Token to check
// Instantiation
let token = new JwtField(); // replace token by variable name of your preference

// Check token
token.isValid("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c");

No Digits

The NoDigits component helps you validate the input doesn't contain digits (0-9)

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(myText) ⇒ boolean

Param Type Description
myText string Text to check
// Instantiation
let myText = new NoDigitsField(); // replace myText by variable name of your preference

// Check Text
myText.isValid("Hello");

Password

The Password component helps you validate the input contains a string that matches the strength level you look for.

In order to use this component, first instantiate it and then use the isValid method to check it.

During instantiation, provide, if you like, optional parameters as an object to define what you require in the password.

Parameters are as follows:

Param Type Description Default
uppercase boolean You require at least 1 uppercase character true
lowercase boolean You require at least 1 lowercase character true
numeric boolean You require at least 1 numeric character true
special boolean You require at least 1 special character true
minLength integer You require a minimum length for password 12

isValid(pass) ⇒ object|boolean

Param Type Description
pass string Password to check
// Instantiation
// This example requires uppercase, special, numeric and at least 15 characters
let pass = new PasswordField({lowercase: false, minLength: 15}); // replace pass by variable name of your preference

// This example requires uppercase, lowercase, special, numeric and at least 12 characters
let pass = new PasswordField(); // replace pass by variable name of your preference

// Check password
pass.isValid("here1sTheP@ssword!");

Range

The Range component helps you validate the input contains a number that matches the range you look for.

In order to use this component, first instantiate it and then use the isValid method to check it.

During instantiation, provide, if you like, optional parameters to define what you require as a range.

Parameters are as follows:

Param Type Description Default
Min integer You require a minimum value 0
Max integer You require a maximum value 0

isValid(value) ⇒ object|boolean

Param Type Description
value integer Number to check
// Instantiation
// This example requires a number between 10 and 20
let range = new RangeField(10, 20); // replace range by variable name of your preference

// This example has no limits (just checks entry is a number)
let range = new Range(); // replace range by variable name of your preference

// Check password
range.isValid(12);

Same

The Same component helps you validate the input contains only identical values.

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(value1, value2, value3, ...) ⇒ boolean

Param Type Description
valueX any Values to check
// Instantiation
let myText = new SameField(); // replace myText by variable name of your preference

// Check Values
myText.isValid(12, "12", variable, "15"); // Example will return false

Siren

The Siren component helps you validate the input contains a string that is a valid "SIREN" number (French companies identifier), not that it exists.

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(siren) ⇒ boolean

Param Type Description
siren string Siren to check
// Instantiation
let siren = new SirenField(); // replace siren by variable name of your preference

// Check siren
siren.isValid("123 456 789");

Siret

The Siret component helps you validate the input contains a string that is a valid "SIRET" number (French companies identifier), not that it exists.

In order to use this component, first instantiate it and then use the isValid method to check it.

isValid(siren) ⇒ boolean

Param Type Description
siret string Siret to check
// Instantiation
let siret = new SiretField(); // replace siret by variable name of your preference

// Check siret
siret.isValid("123 456 789 00001");

Text

The Text component helps you validate the input contains a string that meets the length you provide.

In order to use this component, first instantiate it and then use the isValid method to check it.

During instantiation, provide, if you like, optional parameters to define what you require as a range.

Parameters are as follows:

Param Type Description Default
Min integer You require a minimum length 0
Max integer You require a maximum length 0

isValid(text) ⇒ object|boolean

Param Type Description
text string Text to check
// Instantiation
// This example requires a text length between 10 and 20
let text = new TextField(10, 20); // replace text by variable name of your preference

// Check text
text.isValid("Hello World!");

Url

The Url component helps you validate the input contains a string that meets the URL standard.

In order to use this component, first instantiate it and then use the isValid method to check it.

During instantiation, provide, if you like, optional parameter to define what you require as protocols.

Parameters are as follows:

Param Type Description Default
Protocols array You require specific protocols ["https", "http"]

isValid(url) ⇒ boolean

Param Type Description
url string Url to check
// Instantiation
// This example requires "https" or "ftp" protocols
let url = new UrlField(["https", "ftp"]); // replace url by variable name of your preference

// Check url
url.isValid("https://example.com");
You might also like...

Auth-Form-Design - Beautiful Auth Form Designed using React 🥰.

Auth-Form-Design - Beautiful Auth Form Designed using React 🥰.

🙋 Auth Form Design 🥳 Features 1. Check Your Password Strength 2. Can Use Suggested Password 3. Enjoy Responsive Design Getting Started with Create R

Dec 24, 2022

Gatsby-Formik-contact-form-with-backend-panel - Full working contact form with backend GUI panel.

Gatsby minimal starter 🚀 Quick start Create a Gatsby site. Use the Gatsby CLI to create a new site, specifying the minimal starter. # create a new Ga

Jan 2, 2022

Form To CSS - jQuery-Plugin form to CSS generator

Form To CSS - jQuery-Plugin form to CSS generator

Create your own CSS generator with the form to css generator Builder plugin. Can be usefull to create your own css builder or a Wordpress plugin or any kind of apps you need a real time css generator. For example, you can create a button generator

Sep 26, 2021

Boiler is a utility library that makes every day tasks in JavaScript easier by providing over 115 methods

Boiler is a utility library that makes every day tasks in JavaScript easier by providing over 115 methods that work on arrays, collections, functions, numbers, objects, and strings. It's the JavaScript equivalent of a Swiss Army Knife.

Nov 1, 2022

Tiny JavaScript library (1kB) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Zero dependency tiny JavaScript library (1kB bytes) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Nov 8, 2022

A JavaScript library providing interactive lists

ListExtender.js https://www.julienbl.me/ListExtender/ Install Static (recommended) script defer type="text/javascript" src="https://www.julienb

Oct 31, 2022

A crash course on Zod - a schema validation library for TypeScript

Zod Crash Course This Zod crash course will give you everything you ever needed to know about Zod - an amazing library for building type-safe AND runt

Dec 28, 2022

✅Validation library for ES6+ projects

validatees Validation package for ES6+, TypeScript and JavaScript(CommonJS and Module) ready. Features 🚀 Easy to use: Easy to install in your project

Dec 27, 2022

validation-first schema library with a functional api

zap ⚡ zap is a validation-first schema library with a functional Api. Some major features are Flexible refinement and validation API Transformation, C

Dec 5, 2022
Releases(2.1.1)
Owner
Benoit Gambier
Formateur en développement de sites web
Benoit Gambier
🤝 A set of Persian Helpers for NodeJS to make your life easier

Persian Helpers Persian Helpers is a minimal NodeJS package with a set of helpers/tools specifically for the Persian/Farsi language. If you like the p

Kasra Ghoreyshi 11 Dec 22, 2022
Multi-step wizard helpers for Alpine.js

Alpine Wizard This package provides an Alpine directive (x-wizard) and a magic helper ($wizard) that allow you to quickly build multi-step wizards usi

Galahad 74 Dec 23, 2022
A robust form library for Lit that enriches input components with easy-to-use data validation features.

EliteForms A robust form library for Lit that enriches input components with easy-to-use data validation features. Installation npm install elite-form

OSLabs Beta 33 Jun 28, 2022
RenderIf is a function that receives a validation as a parameter, and if that validation is true, the content passed as children will be displayed. Try it!

RenderIf RenderIf is a function that receives a validation as a parameter, and if that validation is true, the content passed as children will be disp

Oscar Cornejo Aguila 6 Jul 12, 2022
A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

form-storage A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again. Installation via npm npm install

appleple 159 Dec 10, 2022
This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Kanshi TANAIKE 18 Oct 23, 2022
Simple and lightweight form validation for Svelte with no dependencies.

Svelidate Simple and lightweight form validation for Svelte with no dependencies Installation // npm npm install svelidate // yarn yarn add svelidate

null 28 Dec 28, 2022
The jQuery plugin for validation and post form data to server

NiceForm The jQuery plugin for validation and post form data to server (http://ducdhm.github.io/jquery.niceform/) Shortcuts Dependencies Rules Configu

Duc Doan (Bobby) 17 Jul 27, 2022
A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans.

bootstrap-validate A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans. ?? Support us with Developer Merchandise

null 138 Jan 2, 2023
Composition API & Yup Powered Form Validation

vue-yup-form Composition API & Yup Powered Form Validation. This tiny library allows Vue and Yup to be a best friend. Requirements The following versi

Masaki Koyanagi 12 Dec 26, 2022