Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.directive("regExInput", function () {
- "use strict";
- return {
- restrict: "A",
- require: "?regEx",
- scope: {},
- replace: false,
- link: function (scope, element, attrs, ctrl) {
- element.bind('keypress', function (event) {
- var regex = new RegExp(attrs.regEx);
- var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
- if (!regex.test(key)) {
- event.preventDefault();
- return false;
- }
- });
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement