1.0.1 • Published 10 months ago

regex-ready v1.0.1

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

Regex Ready

Prebuilt Regex Patterns ready for use. This library is used to recognize patterns.

Please consider following this project's author, Anoch Jeyakanthan, and consider starring the project to show your ❤️ and support.

Install

$ npm install regex-ready

Usage

Regex to match phone numbers

import PhoneNumberRegex from 'regex-ready/regex';

const phoneNumberRegex = PhoneNumberRegex(
    [ 'ca', 'Sri Lanka', '+6' ], // Country code [Optional]
    [ '647', '416' ] // Area code [Optional]
)

phoneNumberRegex.test('+1 647 000 0000') // True
phoneNumberRegex.test('+3 647 000 0000') // False
phoneNumberRegex.test('+1 555 000 0000') // False
phoneNumberRegex.test('+1 647 000 000') // False

Regex to match emails

import EmailRegex from 'regex-ready/regex';

const emailRegex = EmailRegex(
    [ 'gmail', 'hotmail' ], // Email Provider [Optional]
    [ 'com', 'ca' ] // Top Level Domain [Optional]
)

phoneNumberRegex.test('example@gmail.com') // True
phoneNumberRegex.test('example2@hotmail.ca') // True
phoneNumberRegex.test('example@yahoo.org') // False

Regex to match links

import UrlRegex from 'regex-ready/regex';

const urlRegex = UrlRegex(
    [ 'github', 'youtube' ], // Domains [Optional]
    [ 'com', 'ca' ], // Top Level Domain [Optional]
    [ 'https' ], // Protocols [Optional]
)

urlRegex.test('https://google.com') // True
urlRegex.test('https://youtube.ca') // True
urlRegex.test('http://google.lk') // False

Regex to match credit cards

import CreditCardRegex from 'regex-ready/regex';

CreditCardRegex.test('4111111111111111') // True
CreditCardRegex.test('1234567890123456') // False
CreditCardRegex.test('6011000000000012') // True

String Validation

Validate Date

import ValidateDateRegex from 'regex-ready';

ValidateDateRegex('29th February 2020', 'DD/MM/YYYY') // True - 2020 is a leap year
ValidateDateRegex('01/29/2023', 'MM/DD/YYYY') // True
ValidateDateRegex('November 5th', 'MM/DD') // True