🔍
verifica
  • Verifica
  • Getting started
    • 📦Installation
    • 🧑‍🎓 Examples
      • 🧑‍🎓 Basic
      • 🧑‍🎓 Multiple conditions
      • 🧑‍🎓 Optional
      • 🧑‍🎓 Custom rules
      • 🧑‍🎓 With express.js
    • 🟦Typescript
  • Functions
    • asVerificable
    • isValid
    • getErrors
    • ensure
    • rawValue
  • Predicates
    • Built-in Predicates
      • isArray
      • isArrayLength
      • isArrayOf
      • isBoolean
      • isFiniteNumber
      • isInteger
      • isNumber
      • isNumberInRange
      • isObject
      • isOneOf
      • isRegexMatch
      • isString
      • isStringLength
    • Operations on Predicates
      • all
      • optional
    • Custom Predicates
Powered by GitBook
On this page
  • Arguments:
  • Possible errors:
  • Examples:

Was this helpful?

  1. Predicates
  2. Built-in Predicates

isRegexMatch

isRegexMatch(regex)

Verifies if provided Verificable represents a string that matches provided regex object.

Arguments:

  • regex - required, of type RegExp

Possible errors:

If provided Verificable is not a string:

{
    type: "isString",
    path: [/* ... */]
}

If provided Verificable is not matching provided regex:

{
    type: "isRegexMatch",
    path: [/* ... */]
}

Examples:

Each of examples uses this import statement:

const { asVerificable, isValid, isRegexMatch } = require("verifica");

Null or undefined is not considered a string:

const verificable = asVerificable(null);
isValid(verificable, isRegexMatch(/^[0-9]*$/)); // false

Number value is not considered a string as well:

const verificable = asVerificable(123);
isValid(verificable, isRegexMatch(/^[0-9]*$/)); // false

Value not matching the regex is not matching the predicate:

const verificable = asVerificable("abc");
isValid(verificable, isRegexMatch(/^[0-9]*$/)); // false

Value matching the regex matches the predicate:

const verificable = asVerificable("123");
isValid(verificable, isRegexMatch(/^[0-9]*$/)); // true
PreviousisOneOfNextisString

Last updated 5 years ago

Was this helpful?