npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2024 โ€“ย Pkg Stats / Ryan Hefner

regex-validify

v3.0.0

Published

Your best friend when it comes to validation ๐Ÿ˜Ž!

Downloads

204

Readme

๐Ÿ› ๏ธ Regex Validify ๐Ÿ›ก๏ธ

๐Ÿ“š Table of Contents

Installation

To install your best friend simply run the command:

npm i regex-validify

Description

Regex Validify is a library using which you can very easily check inputs without having the hassle of remembering complex regex patterns. It could be your ultimate friend when it comes to checking users input ๐Ÿ’ช๐Ÿผ.

Features

This library includes the following validation functions:

  1. checkEmail: Validates email addresses.
  2. checkDate: Validates date formats.
  3. checkPhoneNumber: Validates phone numbers.
  4. checkURL: Validates URLs.
  5. checkOnlyLetters: Checks if a string contains only letters.
  6. checkPassword: Validates password strength.
  7. checkOnlyIntegers: Checks if a string contains only integers.
  8. checkCreditCard: Validates credit card numbers.
  9. checkUsername: Validates usernames.
  10. checkIPv4: Validates IPv4 addresses.
  11. checkHexColor: Validates hexadecimal color codes.
  12. checkMACAddress: Validates MAC addresses.
  13. CustomRegex: Allows users to define their own regex validation.

Usage

To use the specific functions you can use:

import {
  checkEmail,
  checkDate,
  checkPhoneNumber,
  checkMACAddress,
  CustomRegex,
} from "regex-validify";

And if you are working on a very big project it would be very hectic to import each function separately. Well, don't worry, in that case you can simply import the container which will contain all the methods, isn't that easy and cool ๐Ÿ˜€.

import Container from "regex-validify"

Functions

1. checkEmail

Validates if the input is a valid email address.

checkEmail(email: string): boolean

2. checkDate

Validates if the input date is in the correct format (e.g., DD/MM/YYYY).

checkDate(date: string): boolean

3. checkPhoneNumber

Validates if the input is a valid phone number.

checkPhoneNumber(phone: string): boolean

4. checkURL

Validates if the input is a valid URL.

checkURL(url: string): boolean

5. checkAlpha

Checks if the input string contains only letters.

checkOnlyLetters(input: string): boolean

6. checkPassword

Validates the strength of the password. By default the complexity parameter set to false, if you want a complex password validation then make the second arguement true.

checkPassword(password: string, complexity?: boolean): boolean

7. checkOnlyIntegers

Checks if the input string contains only integers.

checkOnlyIntegers(input: string): boolean

8. checkCreditCard

Validates credit card numbers.

checkCreditCard(cardNumber: string): boolean

9. checkUsername

Validates if the input is a valid username.

checkUsername(username: string): boolean

10. checkIPv4

Validates if the input is a valid IPv4 address.

checkIPv4(ip: string): boolean

11. checkHexColor

Validates if the input is a valid hex color code.

checkHexColor(color: string): boolean

12. checkMACAddress

Validates if the input is a valid MAC address.

checkMACAddress(mac: string): boolean

13. CustomRegex

Allows you to define your own regex for validation.

CustomRegex(pattern: (str: string) => boolean, input: string): boolean

Examples

Here are some examples demonstrating how to use the functions:

const testEmail = "[email protected]";
console.log(`Is the email '${testEmail}' valid?`, checkEmail(testEmail));

const testDate = "21/10/2024";
console.log(`Is the date '${testDate}' valid?`, checkDate(testDate));

const testPhone = "+1234567890";
console.log(`Is the phone number '${testPhone}' valid?`, checkPhoneNumber(testPhone));

const testURL = "https://example.com";
console.log(`Is the URL '${testURL}' valid?`, checkURL(testURL));

const testPassword = "P@ssw0rd123!";
console.log(`Is the password '${testPassword}' valid?`, checkPassword(testPassword, true));

const customPattern = (str: string) => /^[a-zA-Z]+$/.test(str);
console.log(`Does 'Hello' match custom pattern?`, CustomRegex(customPattern, "Hello"));

License

This project is licensed under the ISC License.