node-common-regex
A Node.js package that exports functions to validate various types of data using regular expressions.
Installation
npm install jscommonregex
Usage
import {
IsInt,
IsPositiveInt,
IsDecimalNum,
IsNum,
IsAlphaNumeric,
IsAlphaNumericWithSpace,
IsEmail,
IsGoodPassword,
IsUsername,
IsURL,
IsIPv4,
IsIPv6,
} from "jscommonregex";
console.log(IsInt(10));
console.log(IsInt("10"));
console.log(IsPositiveInt("10"));
console.log(IsDecimalNum("10.2"));
console.log(IsNum("10.2"));
console.log(IsNum("-10.2"));
console.log(IsAlphaNumeric("hello123"));
console.log(IsAlphaNumericWithSpace("hello 123"));
console.log(IsEmail("example@email.com"));
console.log(IsGoodPassword("Abcdefg1@"));
console.log(IsUsername("john_doe"));
console.log(IsURL("https://www.example.com"));
console.log(IsIPv4("192.168.0.1"));
console.log(IsIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"));
License
MIT
Note
Please note that these regular expressions are not foolproof and might not cover all possible cases. They are meant to be used as a basic validation tool and not as a definitive solution.