2.0.3 • Published 3 days ago

multiform-validator v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

!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://gabriel-logan.github.io/multiform-validator

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

CDNs

jsDelivr:

https://cdn.jsdelivr.net/npm/multiform-validator@2.0.3/dist/bundle.min.js
<scritp src="https://cdn.jsdelivr.net/npm/multiform-validator@2.0.3/dist/bundle.min.js"></script>

unpkg:

https://unpkg.com/multiform-validator@2.0.3/dist/bundle.js
<scritp src="https://unpkg.com/multiform-validator@2.0.3/dist/bundle.js"></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

https://gabriel-logan.github.io/multiform-validator

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@email.com', { maxLength: 30, country: 'br' }).isValid); // returns false
console.log(validateEmail('email@email.com.br', { maxLength: 30, country: 'br' }).isValid); // returns true
console.log(validateEmail('email@email.com', { 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@email.com', { maxLength: 30 });

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

// or

const validationResult = validateEmail("1email@email.com", {
	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 (:

By - Gabriel Logan

2.0.3

3 days ago

2.0.2

3 days ago

2.0.1

6 days ago

2.0.0

6 days ago

1.1.6

6 days ago

1.1.5

6 days ago

1.1.4

8 days ago

1.1.1

13 days ago

1.1.0

13 days ago

1.1.3

13 days ago

1.1.2

13 days ago

1.0.39

1 month ago

1.0.38

1 month ago

1.0.40

1 month ago

1.0.37

1 month ago

1.0.36

2 months ago

1.0.35

2 months ago

1.0.34

2 months ago

1.0.33

2 months ago

1.0.32

2 months ago

1.0.31

2 months ago

1.0.30

2 months ago

1.0.29

2 months ago

1.0.28

2 months ago

1.0.27

2 months ago

1.0.26

7 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

10 months ago

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago