⚠️ This project is still in early alpha. Please report bugs on GitHub.

Schemas
Regex

Regex schema

A function which creates a parsing rule to ensure that a given value is a regex.

Arguments

  1. modifiers? - A list of modifiers
  2. message? - A custom object with error messages to be displayed when validation fails or there are type errors

Examples

import { regex } from '@nordic-ui/validathor';
 
const regexRule = regex();
 
try {
  const parsedValue = regexRule.parse(/(on|off)/i);
  console.log('Parsed value:', parsedValue);
} catch (error) {
  console.error('Parsing failed:', error.message);
}

TypeScript

To get the type of a schema, you can do the following:

const regexRule = regex();
 
type RegexSchema = ReturnType<typeof regexRule.parse>; // RegExp