UNPKG

simple-body-validator

Version:

This package is inspired by Laravel validation, and aims to make body validation easier for Javascript developers

27 lines (26 loc) 815 B
'use strict'; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ruleContract_1 = __importDefault(require("./ruleContract")); class Regex extends ruleContract_1.default { constructor(regex, shouldMatch = true) { super(); this.regex = regex; this.shouldMatch = shouldMatch; } passes(value) { if (this.shouldMatch) { return this.regex.test(value); } return !this.regex.test(value); } getMessage() { if (this.shouldMatch) { return this.trans('regex'); } return this.trans('not_regex'); } } exports.default = Regex;