Skip to content

Regle Cheat Sheet

Quick reference for common Regle patterns and usage scenarios.

Basic Setup

ts
import {  } from '@regle/core'
import { , ,  } from '@regle/rules'

const {  } = (
  { : '', : '' },        
  {                               
    : { , : (2) },
    : { ,  }
  }
)

Essential Properties

PropertyDescriptionExample
r$.$valueForm data (reactive)r$.$value.email
r$.$correctForm is dirty and valid<button :disabled="!r$.$correct">
r$.$invalidForm is invalidv-if="r$.$invalid"
r$.$errorsAll error messagesr$.$errors.email
r$.x.$errorField has errorsv-if="r$.email.$error"
r$.x.$correctField is dirty and validv-if="r$.email.$correct"
r$.x.$dirtyField was touchedv-if="r$.email.$dirty"
r$.$validate()Validate formawait r$.$validate()
r$.$reset()Reset formr$.$reset()

Common Rules

ts
import {} from '@regle/core';

const  = <>({})

const {  } = (, {
  // Basic validation
  : { , : (2) },
  : { ,  },
  : { , , : (18, 99) },
  
  // String validation
  : { , , : (3) },
  : {  },
  : { : (500) },
  
  // Custom patterns
  : { : (/^\+?[\d\s-()]+$/) },
  
  // Password confirmation
  : { , : (8) },
  : { 
    , 
    : (() => ..) 
  }
})

Field Patterns

Basic Field with Error Display

vue
<template>
  <div>
    <input v-model="r$.$value.email" type="email" />
    <span v-for="error of r$.email.$errors" class="error">
      {{ error }}
    </span>
  </div>
</template>

Field with Visual States

vue
<template>
  <input 
    v-model="r$.$value.email"
    :class="{
      'error': r$.email.$error,
      'correct': r$.email.$correct,
    }"
  />
</template>

Optional Field with Conditional Validation

ts
import {} from '@regle/core';
import {, , } from '@regle/rules';

const  = ({: ''});

const  = computed(() => (, {
  : {
    // Only required if form have no email
    : (() => !r$.$value.email)
    : (10),
    : (/^\+?[\d\s-()]+$/)
  }
}))

Custom Error Messages

ts
import {  } from '@regle/rules'

const {  } = ({: '', : ''}, {
  : { 
    : (required, 'Email is required'),
    : (email, 'Please enter a valid email address')
  },
  : {
    : (
      minLength(8), 
      ({ : [] }) => `Password must be at least ${} characters`
    )
  }
})

Form Submission

ts
function () {
  // Validate entire form
  const {, } = await .()
  
  if (!) {
    .('Form has errors')
    return
  }
  
  // Submit data
  try {
    await submitForm()
    .() // Reset form after success
  } catch () {
    // Handle submission error
  }
}

Collections (Arrays)

ts
import {} from '@regle/core';

const {  } = (
  { : [{ : '', : '' }] },
  {
    : {
      : {
        : {  },
        : { ,  }
      }
    }
  }
)

// Access array validation
..[0]..

Nested Objects

ts
import {} from '@regle/core';

const {  } = (
  { 
    : { 
      : { : '', : '' },
      : { : '', : '' }
    }
  },
  {
    : {
      : {
        : {  },
        : { : (200) }
      },
      : {
        : { ,  },
        : {  }
      }
    }
  }
)

// Access nested validation
....

Global Configuration

ts
import {  } from '@regle/core';
import { , ,  } from '@regle/rules';


// Set up global defaults
const { :  } = ({
  : () => ({
    : (, 'You need to provide a value'),
    : (, ({ , : [] }) => {
      return `Minimum length is ${}. Current length: ${?.}`;
    })
  }),
  : {
    : true,
  }
})

Schema Integration (Zod)

ts
import {  } from 'zod/v3'
import {  } from '@regle/schemas'

const  = .({
  : .().(2),
  : .().(),
  : .().(18)
})

const {  } = ({
  : '',
  : '',
  : 0
}, )

TypeScript Errors?

ts
import {  } from '@regle/core';
import {  } from '@regle/rules';

const  = ({: ''});

// ✅ Use inferRules for better type inference
const  = (() => {
  return (, {
    : {  }
  })
})

Released under the MIT License. Logo by Johannes Lacourly