1.0.10 • Published 10 months ago

react-form-input-validator v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

React Form Input Validator

This package provides a set of validation functions for common use cases. Each function helps you validate specific types of input, such as passwords, phone numbers, emails, and more.

Installation

 npm i react-form-input-validator

Usage

ES6

// Importing the validation functions from the package
import {
  isPasswordValid,
  isAlphabetValid,
  isPhoneNumberValid,
  isEmailValid,
  isAscii,
  isAlphanumeric,
} from "react-form-input-validator";

// Validate a password
const passwordResult = isPasswordValid("SecureP@ss123", {
  minLength: 10,
  requireUppercase: true,
  requireLowercase: true,
  requireNumbers: true,
  requireSpecialChars: true,
});

// Validate an alphabet string
const alphabetResult = isAlphabetValid("AbCdEfG");

// Validate a phone number
const phoneNumberResult = isPhoneNumberValid("1234567890");

// Validate an email address
const emailResult = isEmailValid("user@example.com");

// Validate a string containing only ASCII characters
const asciiResult = isAscii("Hello123");

// Validate a string containing only alphanumeric characters
const alphanumericResult = isAlphanumeric("Alpha123");

Return result

FunctionsReturns
isPasswordValid{ isValid: boolean, errorMessage: "string" }
isAlphabetValid{ isValid: boolean, errorMessage: "string" }
isPhoneNumberValid{ isValid: boolean, errorMessage: "string" }
isEmailValid{ isValid: boolean, errorMessage: "string" }
isAscii{ isValid: boolean, errorMessage: "string" }
isAlphanumeric{ isValid: boolean, errorMessage: "string" }
isNumeric{ isValid: boolean, errorMessage: "string" }

List of validator functions available

Functions#Descriptions#Parameters#Defaults
isPasswordValidChecks if the password meets specified criteria.password: string, options: objectminLength: 8, requireUppercase: true, requireLowercase: true, requireNumbers: true, requireSpecialChars: true
isAlphabetValidChecks if the input consists only of alphabet characters.input: string, length?: number, required: booleanlength: null
isPhoneNumberValidChecks if the phone number is valid.phoneNumber: string, length: number, required: booleanlength: 10
isEmailValidChecks if the email address is valid.email: string, required: booleanrequired: false
isAsciiChecks if the input consists only of ASCII characters.input: string, required: booleanrequired: false
isAlphanumericChecks if the input consists only of alphanumeric charactersinput: string, required: booleanrequired: false
isNumericChecks if the input consists only of numeric charactersinput: string, required: boolean ,length: numberrequired: false

Documentation

Feedback and Contributions

We're eager to hear your feedback and suggestions for react-form-input-validator. If you encounter any issues or have ideas for improvements, please open an issue.

Documentation