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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-valid8

v1.3.6

Published

A simple form validation package made for Vue.js.

Downloads

184

Readme

Vue Valid8

A simple form validation package made for Vue.js.

Installation

npm install vue-valid8@latest --save

Getting Started

import { createApp } from 'vue';
import VueValid8 from 'vue-valid8';

createApp().use(VueValid8);

Usage

Basic setup and usage.

<template>
    <label>First name:</label>
    <input name="first-name"
        type="text"
        v-validate="'alpha'"
    >
    <span v-if="validator.invalid('first-name')">
        {{ validator.message('first-name') }}
    </span>
</template>

<script>
    export default {
        name: 'Form',
        inject: ['validator']
    }
</script>

Initial Valiadtion

If you want to validate immediately/initially when the user gets to the form, you can do so by setting the argument initial on the directive binding.

v-validate.initial="'alpha'"

Lazy Valiadtion

If you want to validate without utilizing the input event listener, you may do so by using the lazy modifier. This will allow you to only validate when you mean to, like from a submission button.

v-validate.lazy="'required|numeric'"

Validate All

You are also able to validate all fields before something like a submission and stop it, if a validation fails.

methods: {
    validateForm: function () {
        this.validator.validateAll().then((result) => {
            if (result)
                this.submit();
        });
    }
}

Scope

Scoping your fields will allow you to only validate those fields, if you choose to.

<input name="first-name"
    scope="names"
    v-validate="'alpha'"
>
<span v-if="validator.invalid('first-name')">
    {{ validator.message('first-name') }}
</span>
<input name="last-name"
    scope="names"
    v-validate="'alpha'"
>
<span v-if="validator.invalid('last-name')">
    {{ validator.message('last-name') }}
</span>
methods: {
    validateForm: function () {
        this.validator.validateAll('names').then((result) => {
            if (result)
                this.submit();
        });
    }
}

Rules

The package offers some rule already in place you can use without defining your own.

| Name | Rule | Description | |-----------------------|---------------|--------------------------------------------------------------------------| | Alpha | alpha | Only allows alphabetical characters. | | Alpha Numeric | alpha-numeric | Only allows alphabetical and numeric characters. | | Alpha Spaces | alpha-spaces | Allow alphabetical characters with spaces. | | Domain | domain | Has to be a valid domain name. | | Email | email | Has to be a valid email address. | | IP Address | ip | Has to be a valid IPv4 or IPv6 address. | | IP Address CIDR Range | ip-cidr | Any valid IPv4 or IPv6 with a CIDR range. | | Maximum | max | Set a character max on an input or textarea. | | Minimum | min | Set a character limit on an input or textarea. | | Numeric | numeric | Only allows numeric characters. | | Regular Expression | regex | User defined regular expression directly on the directive binding value. | | Required | required | The field is requires input. | | Telephone | telephone | A valid US telephone number. | | URL | url | Has to be a valid URL. |

You are able to also chain rules by using the pipe delimter.

Example: 'required|alpha'

If you want to validate any rules (including custom rules) multi-line (with something like a textarea) just add the multi- argument at the beginning of a rule.

Example: 'multi-alpha'

Extending Rules

If you have custom rules that aren't a part of the rules that come with the package, you can extend your own.

import { extend } from 'vue-valid8';

extend({
    message: 'This field must be a valid MAC address.',
    name: 'mac',
    validate: (value) => /^[0-9a-f]{1,2}([\.:-])(?:[0-9a-f]{1,2}\1){4}[0-9a-f]{1,2}$/.test(value) 
});

Minimum and Maximum

If there's an input that you want to character limit in any way, use the min and max rule. The rule below requires the input to have a minimum of 5 characters and a max of 10.

'min:5|max:10'

Custom Regex Rule

If needed you can define your own regex directly on the binding value of the directive, like the rule implies. You can also chain any other rule as well as use the multi- argument on your regex as well. The input will also accepts any regular expression flags as well.

'regex:/[a-z]/g'

Note: Currently you can only add one custom regex rule to the directive at a time.

Input Masking

Input masking will allow you to format an input. Currently this only works with integers and has to follow a specific format. This works for both text inputs and textarea as well. You do not have no use any validation while using an input mask, if you choose not to.

Usage

If you wish to use input masking, you'll start with changing the value of the v-validate into an object.

v-validate="{ mask: '(###) ###-####' }"

You are also able to use validation along with your mask.

v-validate="{ mask: '(###) ###-####', pattern: 'telephone' }"

This will result in both validating the input for telephone, but also masking it and automatically formatting the input for the user. The result of the above example would look something like this.

(123) 123-1234

Multi-line

Multi-line currently is very limited, but can be done.

v-validate="{ mask: '##\n####' }"

Each \n represents a line break, multi-line can only be used by defining each line's mask. They can follow the same mask or a separate mask.