aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/form-elements/validation/validators/regex.validator.component.ts
blob: 5929016412707a505c270dbaddf601b36f98296a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Input, Component } from "@angular/core";
import { ValidatorComponent } from "./base.validator.component";
import { IValidator } from './validator.interface';
import template from "./base.validator.component.html";

@Component({
    selector: 'sdc-regex-validator',
    template: template
})
export class RegexValidatorComponent extends ValidatorComponent implements IValidator {

    @Input() public pattern: RegExp;

    constructor() {
        super();
    }

    public validate(value: any): boolean {
        const regexp = new RegExp(this.pattern);
        this.isValid = regexp.test(value);
        return this.isValid;
    }

}