Git Product home page Git Product logo

multiform-validator / typescript-javascript Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 1.0 3.97 MB

Javascript / Typescript library made for validation, various form fields, such as: email, telephone, password, cpf, cnpj, credit card, magic numbers for image mimetype validation and much more.

Home Page: https://multiformvalidator.netlify.app/documentation/js

License: MIT License

JavaScript 1.56% TypeScript 98.44%
javascript javascript-library library multiform-validator npm security security-tools typescript typescript-library validate-js validation validation-library validator

typescript-javascript's Introduction

Note

I accept help to make the version of the other programming languages.

Multiform-validator

npm version License: MIT npm downloads

This npm package provides JavaScript functions to validate various forms fields.

Documentation: https://multiformvalidator.netlify.app

Feel free to find bugs and report them to me. Your feedback is highly appreciated. Hugs from Gabriel Logan!

CDNs

ESM:

jsDelivr:

https://cdn.jsdelivr.net/npm/[email protected]/+esm
<script type="module">
	import multiform-validator from "https://cdn.jsdelivr.net/npm/[email protected]/+esm"
</script>

CJS:

jsDelivr:

https://cdn.jsdelivr.net/npm/[email protected]/dist/cjs/index.min.js
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cjs/index.min.js"></script>

unpkg:

https://unpkg.com/[email protected]/dist/cjs/index.js
<script src="https://unpkg.com/[email protected]/dist/cjs/index.js"></script>

Example of use with CDN

using cjs:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cjs/index.min.js"></script>
<script>
	const emailResult = isEmail("123456");
	const cpfResult = cpfIsValid("123456");

	console.log(emailResult); // returns false
	console.log(cpfResult.isValid); // returns false
</script>

or

using esm:

<script type="module">
	import multiformValidator from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
	const emailResult = multiformValidator.isEmail("123456");
	const cpfResult = multiformValidator.cpfIsValid("123456");

	console.log(emailResult); // returns false
	console.log(cpfResult.isValid); // returns false
</script>

Installation

npm install multiform-validator

or

yarn add multiform-validator

Data Validator

This package contains various modules for validating different types of data. Below are the available validation modules:

Available Validation Modules

  • cnpjValidator: CNPJ validation.
  • cpfValidator: CPF validation.
  • getOnlyEmail: Extracts only the email or emails address from a string.
  • identifyFlagCard: Identifies the flag of a credit card.
  • isAscii: Checks if the string contains only ASCII characters.
  • isBase64: Checks if the string is a valid Base64 encoding.
  • isCEP: CEP validation (Brazilian postal code).
  • isCreditCardValid: Credit card validation.
  • isDate: Date format validation.
  • isDecimal: Checks if the number is a decimal.
  • isEmail: Email address validation format.
  • isEmpty: Checks if the string is empty.
  • isMACAddress: MAC address validation.
  • isMD5: Checks if the string is a valid MD5 hash.
  • isNumber: Checks if the value is a number.
  • isPort: Port number validation.
  • isPostalCode: Postal code validation.
  • isTime: Time format validation.
  • isValidAudio: Audio file validation.
  • isValidImage: Image file validation.
  • isValidPdf: Pdf file validation.
  • isValidTxt: Txt file validation.
  • isValidVideo: Video file validation.
  • passwordStrengthTester: Password strength test.
  • validateBRPhoneNumber: Brazilian phone number validation.
  • validateEmail: Email address full validation.
  • validateName: Name validation.
  • validatePassword: Password validation.
  • validatePassportNumber: Passport number validation.
  • validatePhoneNumber: Phone number validation.
  • validateSurname: Surname validation.
  • validateTextarea: Textarea validation.
  • validateUsername: Username validation.
  • validateUSPhoneNumber: US phone number validation.

You can use it in React Native, Angular, any javascript framework or any javascript or typescript code.

Example using Reactjs:

Example using Reactjs Showing error options Showing error in browser

For better information, read the documentation

const validator = require("multiform-validator");
// or
import validator from "multiform-validator";

or;

// Attention, FUNCTION_NAME is not a valid function name! It is just an example of how to import the functions.

const { FUNCTION_NAME } = require("multiform-validator");
// or
import { FUNCTION_NAME } from "multiform-validator";
const validator = require('multiform-validator');
// or
import validator from 'multiform-validator';
// then
validator.FUNCTION_NAME
// OBS: 'if the function is called validate, the return will be an object and not boolean'
// When return object boolean
validator.FUNCTION_NAME = true or false
// When return object
validator.FUNCTION_NAME = object = { isValid: true or false, errorMsg: 'stringError' }
validator.FUNCTION_NAME.isValid = true or false
validator.FUNCTION_NAME.errorMsg = 'ErrorMsg' // You can customize errors
/**
	* There are other returns in some functions, with strings etc, stay tuned
*/

Documentation

const { validateEmail } = require("multiform-validator");
// or
import { validateEmail } from "multiform-validator";

// It has many more validations, you can read the documentation or
// do several tests to learn how to use the library in the best possible way.

// Two last parameters are optional
console.log(
	validateEmail("[email protected]", { maxLength: 30, country: "br" }).isValid,
); // returns false
console.log(
	validateEmail("[email protected]", { maxLength: 30, country: "br" }).isValid,
); // returns true
console.log(validateEmail("[email protected]", { maxLength: 30 }).isValid); // returns true

// All examples return default messages, below is an example setting your own messages

// If you want to use a default parameter, use null.

const validationResult = validateEmail("[email protected]", { maxLength: 30 });

if (validationResult.isValid) {
	console.log("0 errors");
} else {
	console.log(validationResult.errorMsg); // returns the error
}

// or

const validationResult = validateEmail("[email protected]", {
	maxLength: 30,
	errorMsg: [null, "This is an invalid email with my own errors"],
});

if (validationResult.isValid) {
	console.log("0 errors");
} else {
	console.log(validationResult.errorMsg); // Return  'This is an invalid email with my own errors'
}

Feel free to explore the various functions and experiment with different inputs to understand their behavior. If you encounter any issues or have suggestions, don't hesitate to reach out to me. Your feedback is valuable and helps improve the package. Happy coding!

If you want to help me, you can buy me a coffee (:

Buy Me A Coffee

By - Gabriel Logan

typescript-javascript's People

Contributors

gabriel-logan avatar

Stargazers

Abdullah Basheer avatar  avatar

Forkers

gabriel-logan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.