@this-empathy/javascript-validator
v1.6.6
Published
A package to validate strings and input data with vanilla js
Downloads
11
Readme
Javascript Validator
A package to validate strings and input data with vanilla js.
Getting Started
Install
Install via npm:
npm install @this-empathy/javascript-validator
Install via yarn:
yarn add @this-empathy/javascript-validator
How to use
Import
import Validator from ' @this-empathy/javascript-validator'
Use
function(inputName, value) {
const inputValidation = Validator.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
}
}
Validator Options
Mercosul car plate
Ex: AAA-0000 or AAA-0A00
Validator.carPlate(inputName, value)
Brazilian CEP
Ex: 00000-000 Ex: 00000000
Validator.cep(inputName, value)
Brazilian RG
Ex: 000000000
Validator.rg(inputName, value)
Brazilian CNH
Ex: 00000000000
Validator.cnh(inputName, value)
Brazilian CNPJ
Ex: 00.000.000/0000-00
Validator.cnpj(inputName, value)
Brazilian CPF
Ex: 000.000.000-00
Validator.cpf(inputName, value)
Brazilian CPF & CNPJ
Ex: 000.000.000-00|0000-00
Validator.cpfCnpj(inputName, value)
dd/mm/yyyy Date
Ex: 00/00/0000
Validator.date(inputName, value)
Validator.email(inputName, value)
File Size
Ex: 1024
Validator.fileSize(files, size)
File Type
Ex: jpg|svg|jpeg|png|bmp|gi
Validator.fileType(files)
File Type Csv
Ex: csv
Validator.fileTypeCsv(files)
Numbers
Ex: 0123456
Validator.numbers(inputName, value)
Letters
Ex: abcdefgABCDEFG
Validator.letters(inputName, value)
Special Characters
Ex: @@@@####$$$$
Validator.specialCharacters(inputName, value)
Brazilian Phone
Ex: +55 (11) 0 0000-0000
Validator.phone(inputName, value)
Brazilian Renavam
Ex: 00000000000
Validator.renavam(inputName, value)
Brazilian Renavam
Ex: 00000000000
Validator.renavam(inputName, value)
Credit Card Number
Ex: 0000000000000000
Validator.creditCardNumber(inputName, value)
Credit Card Date
Ex: 00/00 || 00/0000
Validator.creditCardDate(inputName, value)
RegEx
Ex: /^[0-9]+$/
Validator.regex(inputName, value, regex)