Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
150
rated 0 times [  155] [ 5]  / answers: 1 / hits: 22693  / 9 Years ago, wed, may 13, 2015, 12:00:00

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?


More From » jquery

 Answers
7

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À-ÖØ-öø-įĴ-őŔ-žǍ-ǰǴ-ǵǸ-țȞ-ȟȤ-ȳɃɆ-ɏḀ-ẞƀ-ƓƗ-ƚƝ-ơƤ-ƥƫ-ưƲ-ƶẠ-ỿ]

[#66617] Monday, May 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maximusbradforde

Total Points: 594
Total Questions: 106
Total Answers: 82

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;