UNPKG

@blinkk/selective-edit

Version:
29 lines 935 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PatternRule = void 0; const validationRules_1 = require("../validationRules"); class PatternRule extends validationRules_1.Rule { constructor(config) { super(config); this.config = config; this.defaultMessage = `Value needs to match the pattern: ${this.config.pattern}`; } validate(value) { // Allow for empty fields. // Use the required rule for making sure it exists. if (!value) { return null; } // Only need to compile the pattern once. if (!this.pattern) { this.pattern = new RegExp(this.config.pattern); } // Needs to match the pattern. if (!this.pattern.test(value)) { return this.message; } return null; } } exports.PatternRule = PatternRule; //# sourceMappingURL=pattern.js.map