(function () { "use strict"; var name = 'adElementPhone'; angular.module('app.directive') .directive('adElementPhone', [function () { return { require: 'ngModel', link: function (scope, element, attributes, ctrl) { var phoneExpr = /^(\+380)(\d{9})$/; ctrl.$parsers.unshift(function (viewValue) { if (phoneExpr.test(viewValue)) { ctrl.$setValidity(name, true); return viewValue; } else { ctrl.$setValidity(name, false); return undefined; } }); } }; }]); })();