# all files / Core/Validators/ FileNameValidator.js

66.67% Statements 12/18
50% Branches 3/6
100% Functions 3/3
66.67% Lines 12/18

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43

    1

    1

    1

    1

    16

    1
    10
    9

    9

    9

    9

    1
     'use strict';

    // Utilities:
    var _ = require('lodash');

    // Module:
    var Core = require('../Core');

    // Dependencies:
    require('../Components/Notifier/NotifierService');

    var FileNameValidator = function FileNameValidator (
        notifierService
    ) {
        return {
            restrict: 'A',

            require: 'ngModel',

            link: link
        };

        function link ($scope, $element, $attrs, ngModelController) {
            ngModelController.$validators.fileName = function (value) {
                Iif (_.contains(value, '_')) {
                    notifierService.error('Invalid character: "_"');
                    return false;
                }
                Iif (_.contains(value, '/')) {
                    notifierService.error('Invalid character: "/"');
                    return false;
                }
                Iif (_.contains(value, '\\')) {
                    notifierService.error('Invalid character: "\\"');
                    return false;
                }
                return true;
            };
        }
    };

    Core.directive('fileName', FileNameValidator);