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

@mdfrough/cnic-validator

v0.0.4

Published

An Angular library to validate and format Pakistani CNIC numbers with masking and pipe support.

Readme

CNIC Validator for Angular

A lightweight and powerful Angular library for validating, formatting, and parsing Pakistani CNIC numbers. Includes input masking, validation, formatting pipe and directive.

📦 Features

  • ✅ CNIC input validation (13-digit format: xxxxx-xxxxxxx-x)
  • ✅ CNIC input masking directive (auto-inserts hyphens)
  • ✅ CNIC validator directive for template-driven forms
  • ✅ Validation errors via Angular Reactive Forms
  • ✅ CNIC formatting pipe
  • ✅ Built for Angular 17+
  • ✅ Supports both NgModules and Standalone Components

🚀 Installation

npm i @mdfrough/cnic-validator

🔧 Setup

Option 1: Using NgModules

import { CnicValidatorModule } from '@mdfrough/cnic-validator';

@NgModule({
  imports: [CnicValidatorModule],
})
export class AppModule {}

Option 2: Using Standalone Components

You can directly import the directive and pipe in standalone components:

import { CnicMaskDirective } from '@mdfrough/cnic-validator';
import { CnicFormatPipe } from '@mdfrough/cnic-validator';
import { CnicValidatorDirective } from '@mdfrough/cnic-validator';

@Component({
  standalone: true,
  selector: 'app-cnic-form',
  imports: [CnicMaskDirective, CnicFormatPipe, CnicValidatorDirective],
  templateUrl: './cnic-form.component.html'
})
export class CnicFormComponent {}

🧪 Usage

1. Masked CNIC Input Field

<input 
  type="text" 
  formControlName="cnic" 
  cnicMask 
  placeholder="xxxxx-xxxxxxx-x" />

2. Reactive Form Setup

this.form = this.fb.group({
  cnic: ['', [Validators.required, cnicValidatorFn]]
});

3. Template-Driven Form Setup

<input 
  name="cnic" 
  ngModel 
  cnicMask 
  cnicValidator 
  #cnicModel="ngModel" />
  @if(cnicModel.errors?.['invalidCnic']) {
    <div>
      Invalid CNIC format
    </div>
  }

4. Display Validation Error (Reactive)

@if(form.get('cnic')?.errors?.['invalidCnic']) {
  <div>
    Invalid CNIC formats
  </div>
}

5. Pipe Usage

{{ '1234512345671' | cnic }} <!-- Outputs: 12345-1234567-1 -->

🔍 API Reference

Directive: cnicMask

  • Applies input masking as user types
  • Automatically formats input to xxxxx-xxxxxxx-x

Directive: cnicValidator

  • Use in template-driven forms
  • Adds validation for correct CNIC structure

Validator Function: cnicValidatorFn

  • Returns Angular ValidatorFn
  • Use in reactive forms

Pipe: cnic

  • Formats raw CNIC into masked format

🛠 Development Setup

git clone https://github.com/your-org/cnic-validator-angular.git
cd cnic-validator-angular
npm install
ng build cnic-lib --configuration production
ng serve

The demo app will be available at http://localhost:4200/.


📜 License

MIT


🤝 Contributing

PRs welcome! Please follow Angular style guidelines and write tests.


📣 Credits

This project was built with ❤️ to simplify handling Pakistani CNICs in modern Angular apps.