UNPKG

simple-body-validator

Version:

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

23 lines (22 loc) 572 B
'use strict'; import RuleContract from './ruleContract'; class Regex extends RuleContract { 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'); } } export default Regex;