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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pharma-input-validator

v1.0.1

Published

Validator for input fields

Readme

Input Validation Component

A reusable JavaScript class for validating common input fields in web forms, such as email, date, username, and Sri Lankan identity card number (NIC).

Features

  • Email validation
  • Date validation (YYYY-MM-DD format)
  • Username validation (3-20 alphanumeric characters or underscores)
  • Sri Lankan NIC validation (9 digits + 1 uppercase letter or 12 digits)
  • Dynamic feedback for valid/invalid input
  • Reusable static validation methods

Installation

Copy index.js into your project directory.

Usage

1. Import the Validator

Include the script in your HTML:

<script type="module" src="index.js"></script>

Or import in your JavaScript module:

import { Validator } from './index.js';

2. Validate Inputs

Email

import { Validator } from './index.js';

const email = "[email protected]";
if (Validator.isValidEmail(email)) {
  console.log("Valid email");
} else {
  console.log("Invalid email");
}

Date (YYYY-MM-DD)

const date = "2024-06-01";
if (Validator.isValidDate(date)) {
  console.log("Valid date");
}

Username

const username = "user_123";
if (Validator.isValidUsername(username)) {
  console.log("Valid username");
}

Sri Lankan NIC

const nic = "123456789V";
if (Validator.isValidNIC(nic)) {
  console.log("Valid NIC");
}

3. Dynamic Feedback Example

You can use the Validator with input events for real-time feedback:

<input type="text" id="emailInput" placeholder="Enter email" />
<span id="emailFeedback"></span>
<script type="module">
  import { Validator } from './index.js';
  const input = document.getElementById('emailInput');
  const feedback = document.getElementById('emailFeedback');
  input.addEventListener('input', () => {
    if (Validator.isValidEmail(input.value)) {
      feedback.textContent = "Valid email";
      feedback.style.color = "green";
    } else {
      feedback.textContent = "Invalid email";
      feedback.style.color = "red";
    }
  });
</script>

API Reference

Validator.isValidEmail(email: string): boolean

Returns true if the email is valid.

Validator.isValidDate(date: string): boolean

Returns true if the date is in YYYY-MM-DD format and valid.

Validator.isValidUsername(username: string): boolean

Returns true if the username is 3-20 characters, alphanumeric or underscores.

Validator.isValidNIC(nic: string): boolean

Returns true if the NIC matches Sri Lankan format.

License

MIT