本文介绍了正则表达式的变音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求实施此 answer 但它不起作用.此 jsFiddle 中的代码如下:

I'm looking to implement the solution provided in this answer but it's not working. The code in this jsFiddle have looks like this:

function Start() {

    $('#TheBox').keyup(function () {

        var TheInput = $('#TheBox').val();
        var TheCleanInput = TheInput.replace(/([.\p{L}])/g, '');

        $('#TheBox').val(TheCleanInput);
    });
}

$(Start);

基本上,我希望允许使用éèô这样的字母以及数字.要使正则表达式过滤器正常工作,我需要更改什么?

Basically, I'm looking to allow letters such as é è ô as well as numbers. What do I need to change to make the regex filter work?

推荐答案

正如Casimir et Hippolyte在评论中所述,Javascript不支持\p{L} Unicode字符类.

As Casimir et Hippolyte stated in comments, Javascript does not support \p{L} unicode character class.

您可以创建自己的角色类:

You can create your own character class:

[a-zA-Z0-9À-ž]

演示

如果要允许这些字符但替换那些范围之外的字符,请取消字符类:

If you want to allow those characters but replace characters outside those ranges, negate the character classes:

[^a-zA-Z0-9À-ž]

演示

这篇关于正则表达式的变音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:01