UNPKG

bguard

Version:

**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.

25 lines (22 loc) 1.01 kB
import { RequiredValidation } from '../../core.js'; import '../../commonTypes.js'; import '../../InferType.js'; import '../../helpers/constants.js'; /** * @description Asserts that a string value matches a specified regular expression pattern. * @param {RegExp} expected The regular expression pattern that the string value should match. * @returns {RequiredValidation} A validation function that takes a received string and an exception context. * @throws {ValidationError} if the received value does not match the expected pattern. * @example * const schema = string().custom(regExp(/^[A-Za-z0-9]+$/)); // Validates against alphanumeric pattern * parseOrFail(schema, 'valid123'); // Valid * parseOrFail(schema, 'invalid!@#'); // Throws an error: 'The received value does not match the required text pattern' * * @translation Error Translation Key = 's:regExp' */ declare const regExp: { (expected: RegExp): RequiredValidation; key: string; message: string; }; export { regExp };