ZephyrFormValidator

A lightweight, dependency-free JavaScript library for form validation with custom rules, dynamic error handling, and class toggling.

Why Choose ZephyrFormValidator?

Powerful features that make form validation a breeze

Lightweight & Fast

Zero dependencies and minimal footprint for blazing-fast performance. No jQuery required.

Customizable Rules

Extensive set of built-in validation rules with support for custom error messages.

Flexible Styling

Custom CSS classes for valid and invalid states to match your design system.

Date Validation

Powerful date validation with custom format support and real date checking.

Developer Friendly

Clean API, intuitive configuration, and comprehensive documentation make implementation simple.

Cross-Browser Compatible

Works seamlessly across all modern browsers with no additional polyfills required.

Getting Started

Quick and easy implementation

1. Install ZephyrFormValidator

// Using npm


// Just ownload the script and include it
<script src="path/to/zephyr-form-validator.min.js"></script>

2. Basic Implementation

// Get the form element
const form = document.getElementById('myForm');

// Initialize the validator
const validator = new ZephyrFormValidator(form, {
  fields: {
    username: {
      required: { value: true },
      min: { value: 3 }
    },
    email: {
      required: { value: true },
      email: { value: true }
    }
  },
  errorClass: "validation-error",
  validationClasses: {
    isInvalid: {
      input: "is-invalid",
      error: "invalid-feedback"
    }
  }
});

// Validate on form submission
form.addEventListener('submit', function(e) {
  if (!validator.validate()) {
    e.preventDefault();
  }
});

Validation Rules

Comprehensive set of validation options

required

Required Validation

Ensures that a field contains a value and is not empty.

username: {
  required: { 
    value: true,
    message: "Username is required" // Optional custom message
  }
}
min/max

Minimum/Maximum Length

Validates the minimum and maximum character length for input fields.

password: {
  min: { 
    value: 8,
    message: "Password must be at least 8 characters" // Optional
  },
  max: { 
    value: 20,
    message: "Password cannot exceed 20 characters" // Optional
  }
}
email

Email Validation

Validates that an input contains a properly formatted email address.

email: {
  email: { 
    value: true,
    message: "Please enter a valid email address" // Optional
  }
}
url

URL Validation

Validates that an input contains a properly formatted URL (http://, https://, www, etc.).

website: {
  url: { 
    value: true,
    pattern: /^(https?:\/\/|www\.)[a-zA-Z0-9-]+\.[a-zA-Z]{2,6}(\/[^\s]*)?$/, // Optional
    message: "Please enter a valid URL" // Optional
  }
}
alpha

Alpha Validation

Ensures the input contains only alphabetic characters.

username: {
  alpha: { 
    value: true,
    message: "Username must contain only letters." // Optional
  }
}
alphanumeric

Alpha Numeric Validation

Verifies the input contains only letters and numbers.

username: {
  alphanumeric: { 
    value: true,
    message: "Username must contain only letters and numbers." // Optional
  }
}
pattern

Pattern/RegEx Validation

Validates input against a custom regular expression pattern.

phone: {
  pattern: { 
    value: "^\\d{3}-\\d{3}-\\d{4}$",
    message: "Please enter a valid phone number (e.g., 555-123-4567)" // Optional
  }
}
range

Numeric Range Validation

Ensures that a numeric input falls within a specific range.

age: {
  range: { 
    min: 18,
    max: 100,
    message: "Age must be between 18 and 100" // Optional
  }
}
date

Date Validation

Validates dates with custom format support and actual date validation.

birthdate: {
  date: { 
    format: "YYYY-MM-DD", // Supports YYYY, YY, MM, M, DD, D formats
    message: "Please enter a valid date in YYYY-MM-DD format" // Optional
  }
}
equalTo

Equal To Validation

Ensures that an input value matches the value of another field (useful for password confirmation).

confirmPassword: {
  equalTo: { 
    field: "password", // ID or name of the target field
    message: "Passwords must match" // Optional
  }
}

Live Demo

See ZephyrFormValidator in action

Ready to simplify your form validation?

Get started with ZephyrFormValidator today.