Validator Js
A package to validate strings and input data with vanilla js.
Forked from flux-validator-js
Getting Started
Install
Install via npm:
npm install @intreguei/validator-js
Install via yarn:
yarn add @intreguei/validator-js
How to use Validator
Import
import v from "@intreguei/validator-js";
Use
function(inputName, value) {
const inputValidation = v.validate.email(inputName, value) // returns { name: 'inputName', valid: bool }
if (inputValidation.valid) {
// do something if your email is correct
} else {
// do something if your email is invalid
}
}
v.validate Options
Mercosul car plate
Ex: AAA-0000 or AAA-0A00
v.validate.carPlate(inputName, value);
Brazilian CEP
Ex: 00000-000 Ex: 00000000
v.validate.cep(inputName, value);
Brazilian RG
Ex: 000000000
v.validate.rg(inputName, value);
Brazilian CNH
Ex: 00000000000
v.validate.cnh(inputName, value);
Brazilian CNPJ
Ex: 00.000.000/0000-00
v.validate.cnpj(inputName, value);
Brazilian CPF
Ex: 000.000.000-00
v.validate.cpf(inputName, value);
Brazilian CPF & CNPJ
Ex: 000.000.000-00|0000-00
v.validate.cpfCnpj(inputName, value);
dd/mm/yyyy Date
Ex: 00/00/0000
v.validate.date(inputName, value);
Ex: aaaaa@aaa.aaa.aa
v.validate.email(inputName, value);
File Size
Ex: 1024
v.validate.fileSize(files, size);
File Type
Ex: jpg|svg|jpeg|png|bmp|gi
v.validate.fileType(files);
File Type Csv
Ex: csv
v.validate.fileTypeCsv(files);
Numbers
Ex: 0123456
v.validate.numbers(inputName, value);
Letters
Ex: abcdefgABCDEFG
v.validate.letters(inputName, value);
Special Characters
Ex: @@@@####$$$$
v.validate.specialCharacters(inputName, value);
Brazilian Phone
Ex: +55 (11) 0 0000-0000
v.validate.phone(inputName, value);
Brazilian Renavam
Ex: 00000000000
v.validate.renavam(inputName, value);
Brazilian Renavam
Ex: 00000000000
v.validate.renavam(inputName, value);
Credit Card Number
Ex: 0000000000000000
v.validate.creditCardNumber(inputName, value);
Credit Card Date
Ex: 00/00 || 00/0000
v.validate.creditCardDate(inputName, value);
RegEx
Ex: /^[0-9]+$/
v.validate.regex(inputName, value, regex);
How to use Mask
Import
import v from "@intreguei/validator-js";
Use
function(inputName, value) {
return v.mask.email(inputName, value) // returns { name: 'inputName', masked: "value masked" }
}