aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/validators/numbersLettersUnderscore/numbersLettersUnderscore.validator.ts
blob: 418bdfc4d7e8a60c8fccded01ac5006cabec6ba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Injectable } from '@angular/core';
import { isNullOrUndefined, isString } from 'util';

@Injectable()
export class NumbersLettersUnderscoreValidator {
  static valid(control: any) {
    let reg =  /^[a-zA-Z0-9_]*$/;

    if(isNullOrUndefined(control)) return null;
    let val = isString(control) ? control : control.value;
    if (val === null) {
      return {'invalidNumberLettersUnderscore': true};
    }
    if (reg.test(val)) {
      return null;
    } else {
      return {'invalidNumberLettersUnderscore': true};
    }
  }
}