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

vue3-validate-directive

v1.0.9

Published

A flexible Vue 3 directive for form validation with support for sync/async functions, RegExp, and string patterns

Readme

Vue3 Validate Directive

A flexible Vue 3 directive for form validation with support for sync/async functions, RegExp patterns, and string patterns.

Features

  • Multiple validation types: Functions, RegExp, strings
  • Async validation support: Promise-based validation
  • Checkbox/Radio support: .checked modifier for checkbox and radio button validation
  • Real-time validation: Validates on input and programmatic changes
  • HTML5 integration: Uses native setCustomValidity() and reportValidity()
  • Memory leak prevention: Proper cleanup on component unmount
  • TypeScript support: Full type definitions included

Installation

npm install vue3-validate-directive

Usage

Setup

import { createApp } from 'vue'
import VueValidateDirective from 'vue3-validate-directive'

const app = createApp({})
app.use(VueValidateDirective)

Validation Types

1. Function Validation

<template>
  <!-- Sync function -->
  <input v-validate="{ f: (value) => value.length >= 8, msg: 'Password must be at least 8 characters' }" />
  
  <!-- Async function -->
  <input v-validate="{ f: async (value) => await checkUsername(value), msg: 'Username is already taken' }" />
</template>

2. RegExp Validation

<template>
  <!-- Direct RegExp -->
  <input v-validate="{ f: /^[a-zA-Z0-9]+$/ }" />
  
  <!-- RegExp with custom message -->
  <input v-validate="{ f: /^[a-zA-Z0-9]+$/, msg: 'Only alphanumeric characters allowed' }" />
</template>

3. String Pattern Validation

<template>
  <!-- String pattern (converted to RegExp) -->
  <input v-validate="{ f: '^[a-zA-Z0-9]+$' }" />
  
  <!-- String with custom message -->
  <input v-validate="{ f: '^[a-zA-Z0-9]+$', msg: 'Only alphanumeric characters allowed' }" />
</template>

4. Checkbox Validation

<template>
  <!-- Validate checkbox checked state -->
  <input type="checkbox" v-validate.checked="{ f: (checked) => checked, msg: 'You must accept the terms' }" />
</template>

Advanced Examples

Cross-field Validation

<template>
  <input 
    v-model="password" 
    v-validate="{ f: (value) => value.length >= 8, msg: 'Password must be at least 8 characters' }" 
  />
  <input 
    v-model="confirmPassword" 
    v-validate="{ f: (value) => value === password, msg: 'Passwords must match' }" 
  />
</template>

Async Server Validation

<template>
  <input 
    v-validate="{ 
      f: async (value) => {
        const response = await fetch(`/api/check-username?username=${value}`)
        const data = await response.json()
        return data.available
      }, 
      msg: 'Username is already taken' 
    }" 
  />
</template>

Complex Business Logic

<template>
  <input 
    v-validate="{ 
      f: (value) => {
        // Complex validation logic
        if (value.length < 8) return false
        if (!/[A-Z]/.test(value)) return false
        if (!/[a-z]/.test(value)) return false
        if (!/[0-9]/.test(value)) return false
        if (!/[!@#$%^&amp;*]/.test(value)) return false
        return true
      }, 
      msg: 'Password must contain uppercase, lowercase, number, and special character' 
    }" 
  />
</template>

API Reference

Directive Syntax

v-validate[.checked]="validationConfig"

Validation Config

| Property | Type | Description | |----------|------|-------------| | f | Function \| RegExp \| string | Validation function, RegExp, or string pattern | | msg | string | Custom error message (optional) |

Modifiers

| Modifier | Description | |----------|-------------| | .checked | Validates the element's checked property instead of value (for checkboxes and radio buttons) |

Plugin Options

app.use(VueValidateDirective, {
  defaultMessage: 'Invalid value' // Default error message
})

Browser Support

  • Modern browsers with ES6+ support
  • Vue 3.0+

License

MIT - Feel free to use, modify, and distribute as needed.