v1.0.0 β€” open source

Valify.js

A zero-dependency, ultra-lightweight JavaScript validation library with built-in auto-formatters. Dates, times, CNIC, passwords, and formsβ€”all in one file.

JS index.js CDN

cdn.jsdelivr.net/gh/sahirpunjwani/Valifyjs@1.1.5/index.js

<!-- via CDN script tag -->
<script src="https://cdn.jsdelivr.net/gh/sahirpunjwani/Valifyjs@1.1.5/index.js"></script>

<!-- access globally via window.Valify -->
<script>
  // Validations
  Valify.cnic("42101-1234567-1"); // returns true
  
  // Formatters
  Valify.format.cnic("4210112345671"); // returns "42101-1234567-1"
</script>

6 Modules

in one ecosystem

~4kb

unminified file size

0

third-party dependencies

MIT

free open-source license

Interactive Playground

Type directly into the fields below. The library will auto-format your string layout and validate it in real time (Green = Valid, Red = Invalid).

πŸ‡΅πŸ‡°

CNIC Validation & Format

Pattern validation for Pakistani Identity Cards. Automatically introduces hyphen boundaries dynamically as you enter values.

πŸ“ž

Phone Numbers

Flexible evaluation supporting formats. Re-structures your local code input pattern into a standardized +92 format structure instantly.

πŸ“…

Date Range & Picker

Evaluate form pickers down to the chronological timeline. Ensures your reservation start date starts before an ending date.

πŸ”

Strong Passwords

Enforce elite validation policies requiring at least 8 elements comprising uppercase letters, lowercase, numbers, and symbols.

πŸ’³

Credit Cards

Native mathematical parsing powered by the Luhn Algorithm checksum. Spaces out input digits into neat chunks of four elements.

πŸ•’

Time Configurations

Validates strict 24-hour schedules (HH:MM / HH:MM:SS) alongside standard 12-hour AM/PM string formats seamlessly.

Quick Start Samples

Clean snippets showcasing implementation options inside forms or application scopes.

// Validating standard required text strings and email inputs
if (!Valify.required(emailInput)) {
  showError("Field is mandatory");
}

if (!Valify.email(emailInput)) {
  showError("Please enter a structured, authentic email address");
}

// Length properties
Valify.minLength("hello", 3); // true
Valify.maxLength("hello", 3); // false
// Validating chronologies and ranges
const checkIn = "2026-06-01";
const checkOut = "2026-06-05";

if (!Valify.dateRange(checkIn, checkOut)) {
  console.error("Check-out cannot occur before check-in date!");
}

// Check relative bounds
Valify.futureDate("2030-01-01"); // true
Valify.pastDate("1999-12-31");   // true
// Specialized card structures and localized checks
const localCnic = "42101-1234567-1";
Valify.cnic(localCnic); // true

// Verify phone structures
Valify.phone("+923001234567"); // true

// Evaluate card formats via the Luhn Algorithm before API checkout
if (Valify.creditCard("49927398716")) {
  proceedToCheckout();
}

Full API Blueprint

An extensive dictionary of functions, matching inputs, and returned outputs.

Method Name Arguments Taken Description Check Returns
.required(val) value (any) Verifies field is not undefined, null, or empty whitespace. boolean
.email(val) value (string) Matches input text structure against verified email patterns. boolean
.url(val) value (string) Safely parses string against browser native URL constructors. boolean
.cnic(val) value (string) Checks for exact Pakistani format: 55555-5555555-5. boolean
.phone(val) value (string) Evaluates valid local parameters and global international formats. boolean
.number(val) value (num) Confirms variable is structural digits and excludes NaN loops. boolean
.range(val, min, max) val, min, max (num) Ensures input number values are sequentially bounded. boolean
.date(val) value (string/date) Validates if string translates into standard browser calendar records. boolean
.futureDate(val) value (string/date) Verifies timestamp occurs past the current local clock tick. boolean
.pastDate(val) value (string/date) Verifies input target represents historical timestamps. boolean
.dateRange(start, end) start, end (string) Confirms start picker is chronological before the ending date. boolean
.time24(val) value (string) Tests 24-hour notations up to 23:59 or 23:59:00. boolean
.time12(val) value (string) Requires structural standard AM/PM indicators (e.g. 11:30 AM). boolean
.strongPassword(val) value (string) Checks min 8 chars with 1 upper, 1 lower, 1 digit, 1 symbol. boolean
.creditCard(val) value (string/num) Evaluates strict mathematical legitimacy via Luhn algorithms. boolean
.format.cnic(val) value (string) Auto-formats string into structured 55555-5555555-5 blocks. string
.format.phone(val) value (string) Auto-formats structural pak numbers to standardized +92 code spans. string
.format.creditCard(val) value (string) Splits numeric strings automatically in groups of 4 values. string

Technical Architecture Guides

Deep-dive structural architecture notes explaining regex optimizations, formatting patterns, and pipeline processing hooks inside Valify.js.

πŸ“¦ 1. Core Paradigm

Valify.js runs entirely on declarative validation models. Instead of initializing complex class schemas or long chain-link abstractions, it returns pure, deterministic booleans directly to programmatic check steps.

  • Predictable: Safe to drop into conditional loops.
  • Lightweight: Fits cleanly into performance-critical applications.

⚑ 2. Regular Expression Performance

The built-in matchers (like CNIC and Phone variables) are pre-compiled internally. This isolates evaluation pipelines from regex engine generation overhead during repetitive keydown event listeners.

  • CNIC Layout: Maps precise capture structures across exact 5-7-1 string lengths.
  • Sanitizer Filters: Strips invalid text out before running core rule evaluations.

πŸ”„ 3. Format vs Validate Pipelines

Valify keeps a clean separation between string-formatting layers and true state verification logic to prevent user confusion.

  • Formatters: Add visual spacers (like spaces or hyphens) dynamically without altering raw underlying inputs.
  • Validators: Check total mathematical accuracy, such as running numeric streams through the Luhn Algorithm.

⏰ 4. Date & Temporal Mechanics

Temporal validation goes beyond simple string matching by processing inputs directly through browser-native Date.parse() constructors.

  • Safety Checks: Catches non-existent calendar inputs like February 31st automatically.
  • Comparisons: Converts timezone offsets accurately to keep date bounds completely safe.