1

I'm trying to escape the escape char (\) to allow a user to input its username of Active Directory (DOMAIN\username), but it wont include the character in the input field.

I've used \, \\, \\\ and \\\\ in the mask, and none works. Also tried with the function escapeRegex(), but have had no success.

How can this be achieved?

JS:

(function ($) {
    $.extend($.inputmask.defaults.aliases, {
        'ACTIVE-DIRECTORY': {
            mask: function(a) {
                return a.domain + '\\\\*{1,20}';
            },
            greedy: false,
            definitions: {
                '*': {
                    validator: '[A-Za-z\u0410-\u044F\u0401\u04510-9]',
                    cardinality: 1,
                    casing: 'lower'
                }
            }
        }
    });
})(jQuery);

EDIT:

This is what it shows in HTML:

input field

4

1 回答 1

-1

您如何尝试使用编码字符编写指令路径?

(function ($) {
var dicrectory = encodeURIComponent(directory_path);
    $.extend($.inputmask.defaults.aliases, {
        dicrectory: {
            mask: function(a) {
                return a.domain + '\\\\*{1,20}';
            },
            greedy: false,
            definitions: {
                '*': {
                    validator: '[A-Za-z\u0410-\u044F\u0401\u04510-9]',
                    cardinality: 1,
                    casing: 'lower'
                }
            }
        }
    });
})(jQuery);

记住在服务器端解码它 - 或者你想使用它的任何地方。

于 2016-07-21T15:17:04.250 回答