Package Exports
- easy-form-validation
- easy-form-validation/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (easy-form-validation) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Easy Form Validation
Easy Form Validation is a JavaScript Library which makes form validation easy.
The library functions returns a boolean value after validation. The functions can also be customized using an object parameter.
Use Case
You need to validate the inputs.
Installation
You can install this library via NPM
npm install easy-form-validation
Available Validation Methods
Function | Optional Parameter |
---|---|
validateEmail |
N/A |
validatePassword |
Available |
validateNotEmpty |
N/A |
validateNumber |
Available |
validateText |
N/A |
validateURL |
N/A |
Optional Parameter
The optional parameter is an object which is passed as the 2nd parameter which can be used to customize the validation methods.
Available attributes
validatePassword
{
minLength: value,
maxLength: value,
numbers: false || true, //default false
characters: false || true, //default true
specialCharacters: false || true, //default false
uppercase: false || true, //default false
lowercase: false || true //default false
}
validateNumber
{
min: value,
max: value
}
Importing
ES5
const { validateEmail, validatePassword, validateNotEmpty, validateNumber, validateText, validateURL } = require('easy-form-validation')
ES6
import { validateEmail, validatePassword, validateNotEmpty, validateNumber, validateText, validateURL } from 'easy-form-validation'
Example Usage
ES5
const { validateEmail, validatePassword, validateNotEmpty, validateNumber, validateText, validateURL } = require('easy-form-validation')
console.log(validatePassword('@Abcd1234', {
minLength: 8,
numbers: true,
specialCharacters: true,
uppercase: true,
lowercase: true
})) //returns true
console.log(validatePassword('AAbcd1234', {
minLength: 8,
numbers: true,
specialCharacters: true,
uppercase: true,
lowercase: true
})) //returns false because special character is not presented
ES6
import { validateEmail, validatePassword, validateNotEmpty, validateNumber, validateText, validateURL } from 'easy-form-validation'
console.log(validatePassword('@Abcd1234', {
minLength: 8,
numbers: true,
specialCharacters: true,
uppercase: true,
lowercase: true
})) //returns true
console.log(validatePassword('AAbcd1234', {
minLength: 8,
numbers: true,
specialCharacters: true,
uppercase: true,
lowercase: true
})) //returns false because special character is not presented