FuncType - v0.8.85
    Preparing search index...

    Function PatternString

    • Create a string brand that matches a regex pattern

      Parameters

      • brand: string
      • pattern: RegExp

      Returns ValidatedBrand<string, string>

      const HexColor = PatternString("HexColor", /^#[0-9a-f]{6}$/i)
      const red = HexColor.of("#ff0000") // Some(Brand<"HexColor", string>)
      const invalid = HexColor.of("red") // None
      const PhoneNumber = PatternString("PhoneNumber", /^\+?[1-9]\d{1,14}$/)
      const phone = PhoneNumber.from("+1234567890")
      .map(p => formatPhoneNumber(p))
      .getOrElse("Invalid phone number")