import { Validator } from "../Validator" ; import { FieldValidator } from "./FieldValidator" ; import { extractValidatorPropeties } from "./utils" ; @ Validator ( ) export class RegExpValidator implements FieldValidator { validate ( field , props , value ) { const options = extractValidatorPropeties ( props ) ; options . message = options . message || `Wrong format` ; if ( value === undefined ) { throw new Error ( options . message ) ; } if ( options . value instanceof RegExp ) { if ( ! options . value . test ( value ) ) { throw new Error ( options . message ) ; } } } }