A simple and convenient library of functions that leverage regular expressions while hiding its complexity of implementation
-
.is12HourTime().is24HourTime().isCreditCard().isDayOfMonth().isDayOfWeekString().isDecimal().isDomainName().isEmail().isHexValue().isHTMLTag().isInteger().isIPAddressV4().isLetter().isLowerCase().isMonthOfYear().isMonthOfYearString().isNegativeInteger().isNegativeNumber().isNumber().isPassword().isPositiveInteger().isPositiveNumber().isSSN().isStandardZipCode().isStrongPassword().isUpperCase().isUrl().isUsername().isUSPhoneNumber().isUSState().isUSStateAbbr().isUUID().isVowel().isWhiteSpace().isYear()
Regular expressions are awesome and absolutely super useful when it comes to looking for pattern matches in a string, but clearly it is not the easiest topic to get your head around. Don't believe me, just take a look!
Regexer just attempts to make the process of using some of the most popular regular expressions easier for you. You no longer need to look all over the place for finding a regular expression for matching an email or a phone number, or a hex value or even a day of the week. Just install regexer and use the built in common functions to verify candidate values.
Still confused...? Let's look at an example
Before we get going, make sure you have Node.js installed on your system, so we can use the NPM (Node Package Manager) to install regexer on your project.
$ npm install --save nsp-regexer
// ES5
const regexer = require('nsp-regexer');
console.log( regexer.isEmail('[email protected]') ) // true
console.log( regexer.isLowerCase('KEVIN') ) // false// ES6+
import { isVowel, isNegativeNumber } from 'nsp-regexer';
console.log( isVowel('b') ) // false
console.log( isNegativeNumber(-50.67) ) // trueReturns true if time is in a valid 12-hour format (09:59), otherwise returns false
import { is12HourTime } from 'nsp-regexer';
is12HourTime('1:00')
// true
is12HourTime(09:07')
// true
is12HourTime('15:40')
// falseReturns true if time is in a valid 24-hour format (17:45), otherwise returns false
import { is24HourTime } from 'nsp-regexer';
is24HourTime('3:55')
// true
is24HourTime(22:33')
// true
is24HourTime('40:40')
// falseReturns true if creditCardNumber is a valid credit card number, otherwise returns false
import { isCreditCard } from 'nsp-regexer';
isCreditCard('345768475867474')
// true
isCreditCard(5465838563658274)
// true
isCreditCard('?')
// falseReturns true if day is a day of the month (1-31), otherwise returns false
import { isDayOfMonth } from 'nsp-regexer';
isDayOfMonth('28')
// true
isDayOfMonth(12)
// true
isDayOfMonth(55)
// falseReturns true if day is name of a week day, otherwise returns false
import { isDayOfWeekString } from 'nsp-regexer';
isDayOfWeekString('monday')
// true
isDayOfWeekString('Tuesday')
// true
isDayOfWeekString('thURSdAy')
// true
isDayOfWeekString('FRIDAY')
// true
isDayOfWeekString('doomsday')
// falseReturns true if number is a decimal number, otherwise returns false
import { isDecimal } from 'nsp-regexer';
isDecimal('55.55')
// true
isDecimal(-0.999)
// true
isDecimal(50)
// falseReturns true if domainName is a valid domain name, otherwise returns false
import { isDomainName } from 'nsp-regexer';
isDomainName('www.pen.io')
// true
isDomainName('jack.com')
// true
isDomainName('www.google?money.com')
// falseReturns true if email is a valid email address, otherwise returns false
import { isEmail } from 'nsp-regexer';
isEmail('[email protected]')
// true
isEmail('sdfsdfsdfsd.com')
// falseReturns true if hexValue is a valid hex value, otherwise returns false
import { isHexValue } from 'nsp-regexer';
isHexValue('#FBB')
// true
isHexValue('#SHFF56')
// true
isHexValue('#FF56')
// true
isHexValue('sbfj&&#')
// falseReturns true if htmlTag is an HTML tag, otherwise returns false
import { isHTMLTag } from 'nsp-regexer';
isHTMLTag('<img src="./img/cat.png" />')
// true
isHTMLTag('#SHFF56')
// true
isHTMLTag('<h1 class="center"> Hello World! </h1>')
// true
isHTMLTag('<body>')
// falseReturns true if integer is an integer, otherwise returns false
import { isInteger } from 'nsp-regexer';
isInteger('455')
// true
isInteger(-44)
// true
isInteger('-34.66')
// falseReturns true if ipAddress a valid IP address, otherwise returns false
import { isIPAddressV4 } from 'nsp-regexer';
isIPAddressV4('172.16.254.1')
// true
isIPAddressV4('0.1.0.1')
// true
isIPAddressV4('54.45.222.345')
// falseReturns true if char an alphabetic letter, otherwise returns false
import { isLetter } from 'nsp-regexer';
isLetter('v')
// true
isLetter('P')
// true
isLetter('?')
// falseReturns true if str contains all lower case letters, otherwise returns false
import { isLowerCase } from 'nsp-regexer';
isLowerCase('coffee')
// true
isLowerCase('life is awesome!')
// true
isLowerCase('I love the new Avengers!')
// falseReturns true if number is a month of year (1-12), otherwise returns false
import { isMonthOfYear } from 'nsp-regexer';
isMonthOfYear('4')
// true
isMonthOfYear(12)
// true
isMonthOfYear(30)
// falseReturns true if month is a name of a month of year, otherwise returns false
import { isMonthOfYearString } from 'nsp-regexer';
isMonthOfYearString('march')
// true
isMonthOfYearString('April')
// true
isMonthOfYearString('augusta')
// falseReturns true if integer is a negative integer, otherwise returns false
import { isNegativeInteger } from 'nsp-regexer';
isNegativeInteger('-55')
// true
isNegativeInteger(-6456)
// true
isNegativeInteger('0.33')
// falseReturns true if number is a negative number, otherwise returns false
import { isNegativeNumber } from 'nsp-regexer';
isNegativeNumber('-0.44')
// true
isNegativeNumber(-55)
// true
isNegativeNumber('-1434.44')
// true
isNegativeNumber(10)
// falseReturns true if number is a number, otherwise returns false
import { isNumber } from 'nsp-regexer';
isNumber('-0.44')
// true
isNumber('-4.6')
// true
isNumber(45)
// true
isNumber('a coffee')
// falseReturns true if password meets simple ruleset of a password (contains letters, numbers, hyphens, and underscores; length is between 6 to 18 characters), otherwise returns false
import { isPassword } from 'nsp-regexer';
isPassword('')
// true
isPassword('i-love-cats_haha')
// true
isPassword('02140coffee')
// falseReturns true if integer is a positive integer, otherwise returns false
import { isPositiveInteger } from 'nsp-regexer';
isPositiveInteger('55')
// true
isPositiveInteger(-140)
// falseReturns true if number is a positive number, otherwise returns false
import { isPositiveNumber } from 'nsp-regexer';
isPositiveNumber('4')
// true
isPositiveNumber('0.5')
// true
isPositiveNumber(74.23)
// true
isPositiveNumber(-6)
// falseReturns true if number is a valid social security number, otherwise returns false
import { isSSN } from 'nsp-regexer';
isSSN('031767927')
// true
isSSN('031-76-7927')
// true
isSSN('031 76 7927')
// true
isSSN('545-454-4555')
// falseReturns true if zipCode is a valid zip code, otherwise returns false
import { isStandardZipCode } from 'nsp-regexer';
isStandardZipCode('02166')
// true
isStandardZipCode('12045-6089')
// true
isStandardZipCode('545-454-4555')
// falseReturns true if password is what generally considered as a strong password (must contain at least 1 lowercase alphabetical character, 1 uppercase alphabetical character, 1 numeric character, one special character [!, @, #, $, %, ^. &, or *], and at least eight characters long), otherwise returns false
import { isStrongPassword } from 'nsp-regexer';
isStrongPassword('Ajohnson184&')
// true
isStrongPassword('kevinWilliamsBaller23^')
// true
isStrongPassword('kevinIsAwesome7')
// false - missing a special characterReturns true if str contains all upper case letters, otherwise returns false
import { isUpperCase } from 'nsp-regexer';
isUpperCase('G')
// true
isUpperCase('OH WOW!')
// true
isUpperCase('tea is always BETTER!')
// falseReturns true if url a valid URL address, otherwise returns false
import { isUrl } from 'nsp-regexer';
isUrl('http://3iem.museum:1337/')
// true
isUrl('plik.co.uk')
// true
isUrl('tea@g!.org')
// falseReturns true if username meets the basic requirement of an username (contains letters, numbers, hyphens, and underscores; length is between 3 to 16 characters), otherwise returns false
import { isUsername } from 'nsp-regexer';
isUsername('jSmith455')
// true
isUsername('james-bond007')
// true
isUsername('0coffeeEnergy')
// falseReturns true if phoneNumber a valid US phone number, otherwise returns false
import { isUSPhoneNumber } from 'nsp-regexer';
isUSPhoneNumber('6174330080')
// true
isUSPhoneNumber('(617) 433-0080')
// true
isUSPhoneNumber('454-454-4544-45')
// falseReturns true if state a name of one of US state, otherwise returns false
import { isUSState } from 'nsp-regexer';
isUSState('arizona')
// true
isUSState('Rhode Island')
// true
isUSState('Boston')
// falseReturns true if stateAbbr an abbreviation of a name of one of US state, otherwise returns false
import { isUSStateAbbr } from 'nsp-regexer';
isUSStateAbbr('MA')
// true
isUSStateAbbr('ca')
// true
isUSStateAbbr('bos')
// falseReturns true if uuid is a valid universally unique identifier (UUID) v1 or v4, otherwise returns false
import { isUUID } from 'nsp-regexer';
isUUID('aafac29e-5816-4904-87ef-3eb5151e0c9a')
// true
isUUID('66b9bb40-78d1-11e8-adc0-fa7ae01bbebc')
// true
isUUID('sbfj&&#')
// falseReturns true if char a vowel letter, otherwise returns false
import { isVowel } from 'nsp-regexer';
isVowel('a')
// true
isVowel('U')
// true
isVowel('v')
// falseReturns true if char a white space, otherwise returns false
import { isWhiteSpace } from 'nsp-regexer';
isWhiteSpace(' ')
// true
isWhiteSpace(' ')
// false
isWhiteSpace('hello')
// falseReturns true if number a year, otherwise returns false
import { isYear } from 'nsp-regexer';
isYear('1985')
// true
isYear('2019')
// true
isYear('0344')
// falseObviously, more to come soon...!
Source code makes use of several open source packages, a few keys ones include...
- Babel - To transpile ES6+ syntax to ES5, to run source code in Node and browser
- Webpack - For module bundling and generating distributing assets
- ESLint - To lint source code for better readability, syntax consistency and proper formatting
- CircleCI - Continuous integration middleware to verify incremental builds are always passing
Lot of different resources came in super handy and useful in turning Regexer into reality. Here are just a few highlights:
- Regular Expression Library - the Internet's first Regular Expression Library
- 8 Regular Expressions You Should Know - an article, a tutorial of common regular expressions
- Regular Expressions Cookbook, 2nd Edition by Jan Goyvaerts and Steven Levithan

