Skip to content

Introduction

Regle (French word for "rule") is a Typescript-first form validation library made for Vue 3. I'm a lover and long-time user of Vuelidate API, so Regle's is greatly inspired by it.

Regle is about bringing type safety and great DX to simple or complex Form. It's all data-based and headless, the validation matches the data structure so you can separate UI and validations.

Declare your form rules inside a component or a Pinia store and use it wherever you like.

Installation

Prerequisites


sh
pnpm add @regle/core @regle/rules
sh
npm install @regle/core @regle/rules
sh
yarn add @regle/core @regle/rules
sh
bun add @regle/core @regle/rules

Quick usage

App.vue
vue
<template>
  <
input
v-model='
state
.
email
'
placeholder
='Type your email'/>
<
ul
>
<
li
v-for="
error
of
errors
.
email
"
:
key
='
error
'>
{{
error
}}
</
li
>
</
ul
>
</template> <script setup lang='ts'> import {
useRegle
} from '@regle/core';
import {
required
,
minLength
,
email
} from '@regle/rules';
const {
errors
,
state
} =
useRegle
({
email
: ''}, {
email
: {
required
,
minLength
:
minLength
(4),
email
}
}) </script>

Result:

Released under the MIT License. Logo by Johannes Lacourly