1.0.1 • Published 1 year ago

@devspeed/validatorjs v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@devspeed/validatorjs

A JavaScript library for validating input strings based on various rules

Installation

Install using npm:

   npm install @devspeed/validatorjs

Usage

To use the library, simply import it into your project:

import Validator from '@devspeed/validatorjs';

const validator = new Validator('example@gmail.com', {
    validateEmpty: false,
    validateEmail: true,
    maxLength: 50,
});

const validationResult = validator.getValidation();
console.log(validationResult.isValid); // true

Methods

MethodDescription
isEmpty()Checks if the input string is empty.
maxLength(number)Checks if the input string exceeds the specified maximum length.
minLength(number)Checks if the input string is shorter than the specified minimum length.
isEmail()Checks if the input string is a valid email address.
isDate()Checks if the input string is a valid date in the format DD/MM/YYYY.
requireUppercase()Checks if the input string contains at least one uppercase letter.
requireLowercase()Checks if the input string contains at least one lowercase letter.
containSpecialChar(specialChar)Checks if the input string contains the specified special character.
getValidation()Returns an object containing a boolean value indicating whether the input string is valid, aswell as an array of validation errors if applicable.

Note: All methods return the Validator instance to allow chaining.

Options

The Validator constructor takes an optional options object that can contain the following properties:

OptionDescription
validateEmptyWhether to validate that the input string is not empty (default: true).
validateEmailWhether to validate that the input string is a valid email address (default: false).
validateDateWhether to validate that the input string is a valid date in the format DD/MM/YYYY (default: false).
maxLengthThe maximum allowed length for the input string.
minLengthThe minimum required length for the input string.
requireUppercaseWhether the input string must contain at least one uppercase letter (default: false).
requireLowercaseWhether the input string must contain at least one lowercase letter (default: false).

License

This library is licensed under the MIT License.