Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
291 views
Welcome To Ask or Share your Answers For Others

1 Answer

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à-?]

Demo

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

[^a-zA-Z0-9à-?]

Demo

Or as pointed out in comments:

[A-zà-??-??-??-??-?ǎ-??-??-??-??-???-??-??-??-??-??-??-??-??-?]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...