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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nyi_nyi_phone_hlaing/validator-x

v1.1.1

Published

A utility package for validating fields with express-validator.

Readme

README.md:

validator-x

A set of essential and user-specific validation utilities for Express applications, built using express-validator. This package provides reusable validation functions for common use cases like URL, phone number, email, username, and more.


What You Need to Update

https://github.com/nyi-nyi-phone-hlaing/validator-x.git


Installation

To install the package, run the following command:

npm install @nyi_nyi_phone_hlaing/validator-x

Usage

You can use the utility functions in your Express application by importing them from the package.

const express = require("express");
const {
  checkURL,
  checkPhoneNumber,
  checkUsername,
  checkEmail,
} = require("@nyi_nyi_phone_hlaing/validator-x");
const { validationResult } = require("express-validator");

const app = express();

// Example route using the validation functions
app.post(
  "/register",
  [
    checkUsername("username"), // Validate username
    checkEmail("email"), // Validate email
    checkPhoneNumber("phone"), // Validate phone number
    checkURL("website"), // Validate URL
  ],
  (req, res) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(400).json({ errors: errors.array() });
    }
    res.send("User registered successfully!");
  }
);

app.listen(3000, () => {
  console.log("Server running on port 3000");
});

Validation Functions

checkName = ( fieldName = "name", min = 2, max = 50, allowSpaces = true, allowSpecialChars = false )

checkName("name", 4, 20, false, true);

checkEmail = ( fieldName = "email", required = true, allowedDomains = [] )

// Optional list of allowed domains (e.g., ["gmail.com", "yahoo.com"])
checkName("email", false, ["gamil.com"]);

checkPassword = ( fieldName = "password", minLength = 8, maxLength = 23, requireUppercase = true, requireLowercase = true, requireNumber = true, requireSpecialChar = true )

checkPassword("password", 6, 30, true, false, false, true);

checkURL(fieldName = 'url')

Validates if the input field is a valid URL.

checkURL("website");

checkPhoneNumber(fieldName = 'phone')

Validates if the input field is a valid phone number.

checkPhoneNumber("phone");

checkDate(fieldName = 'date')

Validates if the input field is a valid date.

checkDate("birthdate");

checkNumber(fieldName = 'number', min = 1, max = 100)

Validates if the input field is a number within a specified range.

checkNumber("age", 18, 65);

checkLength(fieldName = 'text', min = 4, max = 16)

Validates if the input field is a string with a specified length range.

checkLength("username", 4, 16);

checkAlphanumeric(fieldName = 'text')

Validates if the input field contains only alphanumeric characters (letters and numbers).

checkAlphanumeric("username");

checkAlpha(fieldName = 'text')

Validates if the input field contains only alphabetic characters (letters).

checkAlpha("firstName");

checkCustomPattern(fieldName = 'text', regex, errorMessage = 'Invalid input format')

Validates if the input field matches a custom regex pattern.

checkCustomPattern(
  "postalCode",
  /^[A-Za-z0-9]{5,10}$/,
  "Invalid postal code format"
);

checkCreditCard(fieldName = 'card')

Validates if the input field is a valid credit card number.

checkCreditCard("creditCard");

checkJSON(fieldName = 'data')

Validates if the input field is a valid JSON string.

checkJSON("data");

checkBoolean(fieldName = 'flag')

Validates if the input field is a boolean value.

checkBoolean("isActive");

checkUniqueEmail(fieldName = 'email')

Validates if the email is unique in the database.

checkUniqueEmail("email");

checkUnique( fieldName = "username", model, key = "username", message = "")

Validates if the username is unique in the specified model's database.

checkUnique("username", User, "username", "username has already taken");

checkCustomUnique(fieldName, model, field)

Validates if the field is unique in the specified model's database.

checkCustomUnique("username", UserModel, "username");

checkArray(fieldName = 'items')

Validates if the input field is an array.

checkArray("items");

checkPhoneNumberByLocale(fieldName = 'phone', locale = 'any')

Validates if the phone number is valid for the specified locale.

checkPhoneNumberByLocale("phone", "en-US");

checkLocalizedEmail(fieldName = 'email', locale = 'en-US')

Validates if the email is valid for the specified locale.

checkLocalizedEmail("email", "en-US");

checkCurrency(fieldName = 'amount', currencySymbol = '$')

Validates if the amount is a valid currency value.

checkCurrency("amount", "$");

checkLocalizedDate(fieldName = 'date', format = 'YYYY-MM-DD')

Validates if the date is in the specified format.

checkLocalizedDate("date", "MM/DD/YYYY");

checkStreetAddress(fieldName = 'address')

Validates if the street address is within a valid length.

checkStreetAddress("address");

checkPostalCode(fieldName = 'postalCode', locale = 'US')

Validates if the postal code is valid for the specified locale.

checkPostalCode("postalCode", "US");

checkCityName(fieldName = 'city')

Validates if the city name contains only alphabetic characters.

checkCityName("city");

checkUniqueFieldByLocale(fieldName = 'username', model, locale = 'en-US')

Validates if the field is unique in the specified locale's database.

checkUniqueFieldByLocale("username", UserModel, "en-US");

checkLatinText(fieldName = 'text')

Validates if the text contains only Latin characters (A-Z, a-z).

checkLatinText("username");

checkGender(fieldName = 'gender', locale = 'en-US')

Validates if the gender value is one of the valid options.

checkGender("gender", "en-US");

checkTimezone(fieldName = 'timezone', validTimezones = [...])

Validates if the timezone is part of the predefined list of valid IANA timezones.

checkTimezone("timezone", [
  "Africa/Abidjan",
  "Europe/London",
  "America/New_York",
]);

checkEnum(fieldName = "role" , enumValues = ["user", "admin"])

  checkEnum("gender", ["male", "female", "other"]),

Explanation:

  • Installation: This section provides users with the command to install the package.
  • Usage: This section shows how to use the validation functions in an Express app.
  • Validation Functions: A list of all the validation functions you provide, with examples of how to use each one.

Author

This package was created by Nyi Nyi Phone Hlaing, a passionate software developer focused on building tools that make development easier and more efficient. Nyi Nyi is a MERN Stack Developer and a tech enthusiast, working towards becoming a professional full-stack developer and contributing to open-source projects.

You can find more information about Nyi Nyi's work at GitHub or YouTube.

Feel free to adjust the details based on your actual package and use case.